diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2009-05-08 23:31:51 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2009-05-08 23:31:51 -0400 |
commit | fce62d380f82f6a650a8297341bff3044400b4f9 (patch) | |
tree | da3984e580bf6f57797c6aa2c192c33f1bf0db61 | |
parent | 6bac20d0a7a8815a7d1cf789642ba2342ae212ac (diff) | |
download | python-coveragepy-git-fce62d380f82f6a650a8297341bff3044400b4f9.tar.gz |
makeFile is more useful if it doesn't append .py
-rw-r--r-- | test/coveragetest.py | 14 | ||||
-rw-r--r-- | test/test_api.py | 16 | ||||
-rw-r--r-- | test/test_coverage.py | 8 | ||||
-rw-r--r-- | test/test_execfile.py | 14 |
4 files changed, 34 insertions, 18 deletions
diff --git a/test/coveragetest.py b/test/coveragetest.py index 65e69cf8..5e2c18dc 100644 --- a/test/coveragetest.py +++ b/test/coveragetest.py @@ -63,14 +63,16 @@ class CoverageTest(unittest.TestCase): """Return the data written to stdout during the test.""" return self.captured_stdout.getvalue() - def makeFile(self, modname, text): - """ Create a temp file with modname as the module name, and text as the - contents. + def makeFile(self, filename, text): + """Create a temp file. + + `filename` is the file name, and `text` is the content. + """ text = textwrap.dedent(text) - # Create the python file. - f = open(modname + '.py', 'w') + # Create the file. + f = open(filename, 'w') f.write(text) f.close() @@ -105,7 +107,7 @@ class CoverageTest(unittest.TestCase): # Coverage wants to deal with things as modules with file names. modname = self.getModuleName() - self.makeFile(modname, text) + self.makeFile(modname+".py", text) # Start up Coverage. cov = coverage.coverage() diff --git a/test/test_api.py b/test/test_api.py index 35278e92..803ebfe3 100644 --- a/test/test_api.py +++ b/test/test_api.py @@ -12,7 +12,7 @@ class ApiTest(CoverageTest): def testSimple(self): coverage.erase() - self.makeFile("mycode", """\ + self.makeFile("mycode.py", """\ a = 1 b = 2 if b == 3: @@ -33,7 +33,7 @@ class ApiTest(CoverageTest): def doReportWork(self, modname): coverage.erase() - self.makeFile(modname, """\ + self.makeFile(modname+".py", """\ a = 1 b = 2 if b == 3: @@ -79,7 +79,7 @@ class ApiTest(CoverageTest): def testUnexecutedFile(self): cov = coverage.coverage() - self.makeFile("mycode", """\ + self.makeFile("mycode.py", """\ a = 1 b = 2 if b == 3: @@ -87,7 +87,7 @@ class ApiTest(CoverageTest): d = 5 """) - self.makeFile("not_run", """\ + self.makeFile("not_run.py", """\ fooey = 17 """) @@ -102,12 +102,12 @@ class ApiTest(CoverageTest): def testFileNames(self): - self.makeFile("mymain", """\ + self.makeFile("mymain.py", """\ import mymod a = 1 """) - self.makeFile("mymod", """\ + self.makeFile("mymod.py", """\ fooey = 17 """) @@ -145,13 +145,13 @@ class ApiTest(CoverageTest): self.assertEqual(os.path.basename(filename), "mymod.py") def testIgnoreStdLib(self): - self.makeFile("mymain", """\ + self.makeFile("mymain.py", """\ import mymod, colorsys a = 1 hls = colorsys.rgb_to_hls(1.0, 0.5, 0.0) """) - self.makeFile("mymod", """\ + self.makeFile("mymod.py", """\ fooey = 17 """) diff --git a/test/test_coverage.py b/test/test_coverage.py index 4ca51408..8a10dce4 100644 --- a/test/test_coverage.py +++ b/test/test_coverage.py @@ -1560,7 +1560,7 @@ class ModuleTest(CoverageTest): class ProcessTest(CoverageTest): def testSaveOnExit(self): - self.makeFile("mycode", """\ + self.makeFile("mycode.py", """\ a = 1 b = 2 if b == 3: @@ -1574,7 +1574,7 @@ class ProcessTest(CoverageTest): def testEnvironment(self): # Checks that we can import modules from the test directory at all! - self.makeFile("mycode", """\ + self.makeFile("mycode.py", """\ import covmod1 import covmodzip1 a = 1 @@ -1587,7 +1587,7 @@ class ProcessTest(CoverageTest): self.assertEqual(out, 'done\n') def testReport(self): - self.makeFile("mycode", """\ + self.makeFile("mycode.py", """\ import covmod1 import covmodzip1 a = 1 @@ -1636,7 +1636,7 @@ class ProcessTest(CoverageTest): self.assert_("mycode " in report3) def testCombineParallelData(self): - self.makeFile("b_or_c", """\ + self.makeFile("b_or_c.py", """\ import sys a = 1 if sys.argv[1] == 'b': diff --git a/test/test_execfile.py b/test/test_execfile.py index d46732d2..60ef1952 100644 --- a/test/test_execfile.py +++ b/test/test_execfile.py @@ -34,3 +34,17 @@ class RunTest(CoverageTest): # Argv should have the proper values. self.assertEqual(mod_globs['argv'], [tryfile, "arg1", "arg2"]) + + def test_no_c_file(self): + self.makeFile("mycode.py", """\ + a = 1 + b = 2 + if b == 3: + c = 4 + d = 5 + """) + + self.assert_(not os.path.exists(".coverage")) + self.run_command("coverage -x mycode.py") + self.assert_(os.path.exists(".coverage")) +
\ No newline at end of file |