Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(227)

Side by Side Diff: tools/telemetry/third_party/coverage/tests/test_filereporter.py

Issue 1366913004: Add coverage Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 # Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
2 # For details: https://bitbucket.org/ned/coveragepy/src/default/NOTICE.txt
3
4 """Tests for FileReporters"""
5
6 import os
7 import sys
8
9 from coverage.plugin import FileReporter
10 from coverage.python import PythonFileReporter
11
12 from tests.coveragetest import CoverageTest
13
14 # pylint: disable=import-error
15 # Unable to import 'aa' (No module named aa)
16
17
18 def native(filename):
19 """Make `filename` into a native form."""
20 return filename.replace("/", os.sep)
21
22
23 class FileReporterTest(CoverageTest):
24 """Tests for FileReporter classes."""
25
26 run_in_temp_dir = False
27
28 def setUp(self):
29 super(FileReporterTest, self).setUp()
30 # Parent class saves and restores sys.path, we can just modify it.
31 testmods = self.nice_file(os.path.dirname(__file__), 'modules')
32 sys.path.append(testmods)
33
34 def test_filenames(self):
35 acu = PythonFileReporter("aa/afile.py")
36 bcu = PythonFileReporter("aa/bb/bfile.py")
37 ccu = PythonFileReporter("aa/bb/cc/cfile.py")
38 self.assertEqual(acu.relative_filename(), "aa/afile.py")
39 self.assertEqual(bcu.relative_filename(), "aa/bb/bfile.py")
40 self.assertEqual(ccu.relative_filename(), "aa/bb/cc/cfile.py")
41 self.assertEqual(acu.source(), "# afile.py\n")
42 self.assertEqual(bcu.source(), "# bfile.py\n")
43 self.assertEqual(ccu.source(), "# cfile.py\n")
44
45 def test_odd_filenames(self):
46 acu = PythonFileReporter("aa/afile.odd.py")
47 bcu = PythonFileReporter("aa/bb/bfile.odd.py")
48 b2cu = PythonFileReporter("aa/bb.odd/bfile.py")
49 self.assertEqual(acu.relative_filename(), "aa/afile.odd.py")
50 self.assertEqual(bcu.relative_filename(), "aa/bb/bfile.odd.py")
51 self.assertEqual(b2cu.relative_filename(), "aa/bb.odd/bfile.py")
52 self.assertEqual(acu.source(), "# afile.odd.py\n")
53 self.assertEqual(bcu.source(), "# bfile.odd.py\n")
54 self.assertEqual(b2cu.source(), "# bfile.py\n")
55
56 def test_modules(self):
57 import aa
58 import aa.bb
59 import aa.bb.cc
60
61 acu = PythonFileReporter(aa)
62 bcu = PythonFileReporter(aa.bb)
63 ccu = PythonFileReporter(aa.bb.cc)
64 self.assertEqual(acu.relative_filename(), native("aa.py"))
65 self.assertEqual(bcu.relative_filename(), native("aa/bb.py"))
66 self.assertEqual(ccu.relative_filename(), native("aa/bb/cc.py"))
67 self.assertEqual(acu.source(), "# aa\n")
68 self.assertEqual(bcu.source(), "# bb\n")
69 self.assertEqual(ccu.source(), "") # yes, empty
70
71 def test_module_files(self):
72 import aa.afile
73 import aa.bb.bfile
74 import aa.bb.cc.cfile
75
76 acu = PythonFileReporter(aa.afile)
77 bcu = PythonFileReporter(aa.bb.bfile)
78 ccu = PythonFileReporter(aa.bb.cc.cfile)
79 self.assertEqual(acu.relative_filename(), native("aa/afile.py"))
80 self.assertEqual(bcu.relative_filename(), native("aa/bb/bfile.py"))
81 self.assertEqual(ccu.relative_filename(), native("aa/bb/cc/cfile.py"))
82 self.assertEqual(acu.source(), "# afile.py\n")
83 self.assertEqual(bcu.source(), "# bfile.py\n")
84 self.assertEqual(ccu.source(), "# cfile.py\n")
85
86 def test_comparison(self):
87 acu = FileReporter("aa/afile.py")
88 acu2 = FileReporter("aa/afile.py")
89 zcu = FileReporter("aa/zfile.py")
90 bcu = FileReporter("aa/bb/bfile.py")
91 assert acu == acu2 and acu <= acu2 and acu >= acu2
92 assert acu < zcu and acu <= zcu and acu != zcu
93 assert zcu > acu and zcu >= acu and zcu != acu
94 assert acu < bcu and acu <= bcu and acu != bcu
95 assert bcu > acu and bcu >= acu and bcu != acu
96
97 def test_egg(self):
98 # Test that we can get files out of eggs, and read their source files.
99 # The egg1 module is installed by an action in igor.py.
100 import egg1
101 import egg1.egg1
102
103 # Verify that we really imported from an egg. If we did, then the
104 # __file__ won't be an actual file, because one of the "directories"
105 # in the path is actually the .egg zip file.
106 self.assert_doesnt_exist(egg1.__file__)
107
108 ecu = PythonFileReporter(egg1)
109 eecu = PythonFileReporter(egg1.egg1)
110 self.assertEqual(ecu.source(), u"")
111 self.assertIn(u"# My egg file!", eecu.source().splitlines())
OLDNEW
« no previous file with comments | « tools/telemetry/third_party/coverage/tests/test_farm.py ('k') | tools/telemetry/third_party/coverage/tests/test_files.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698