diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2009-05-04 19:52:48 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2009-05-04 19:52:48 -0400 |
commit | 80132a0b9faad6de95828bb85e23271506aa3a4f (patch) | |
tree | 4c5a009dd2b7b9cfcbb6b801aac52d39b4a26d48 /test/test_coverage.py | |
parent | 998879621fe7195580ddcf5262170b80843d8cc8 (diff) | |
download | python-coveragepy-git-80132a0b9faad6de95828bb85e23271506aa3a4f.tar.gz |
Split api tests into their own file.
Diffstat (limited to 'test/test_coverage.py')
-rw-r--r-- | test/test_coverage.py | 171 |
1 files changed, 0 insertions, 171 deletions
diff --git a/test/test_coverage.py b/test/test_coverage.py index 8c32e90f..4ca51408 100644 --- a/test/test_coverage.py +++ b/test/test_coverage.py @@ -4,7 +4,6 @@ import os, sys, unittest from cStringIO import StringIO -from textwrap import dedent import coverage coverage.use_cache(0) @@ -1559,176 +1558,6 @@ class ModuleTest(CoverageTest): coverage.coverage() -class ApiTest(CoverageTest): - - def testSimple(self): - coverage.erase() - - self.makeFile("mycode", """\ - a = 1 - b = 2 - if b == 3: - c = 4 - d = 5 - """) - - # Import the python file, executing it. - coverage.start() - self.importModule("mycode") - coverage.stop() - - filename, statements, missing, readablemissing = coverage.analysis("mycode.py") - self.assertEqual(statements, [1,2,3,4,5]) - self.assertEqual(missing, [4]) - self.assertEqual(readablemissing, "4") - - def doReportWork(self, modname): - coverage.erase() - - self.makeFile(modname, """\ - a = 1 - b = 2 - if b == 3: - c = 4 - d = 5 - e = 6 - f = 7 - """) - - # Import the python file, executing it. - coverage.start() - self.importModule(modname) - coverage.stop() - coverage.analysis(modname + ".py") - - def testReport(self): - self.doReportWork("mycode2") - coverage.report(["mycode2.py"]) - self.assertEqual(self.stdout(), dedent("""\ - Name Stmts Exec Cover Missing - --------------------------------------- - mycode2 7 4 57% 4-6 - """)) - - def testReportFile(self): - self.doReportWork("mycode3") - fout = StringIO() - coverage.report(["mycode3.py"], file=fout) - self.assertEqual(self.stdout(), "") - self.assertEqual(fout.getvalue(), dedent("""\ - Name Stmts Exec Cover Missing - --------------------------------------- - mycode3 7 4 57% 4-6 - """)) - - def testUnexecutedFile(self): - cov = coverage.coverage() - - self.makeFile("mycode", """\ - a = 1 - b = 2 - if b == 3: - c = 4 - d = 5 - """) - - self.makeFile("not_run", """\ - fooey = 17 - """) - - # Import the python file, executing it. - cov.start() - self.importModule("mycode") - cov.stop() - - filename, statements, missing, readablemissing = cov.analysis("not_run.py") - self.assertEqual(statements, [1]) - self.assertEqual(missing, [1]) - - def testFileNames(self): - - self.makeFile("mymain", """\ - import mymod - a = 1 - """) - - self.makeFile("mymod", """\ - fooey = 17 - """) - - # Import the python file, executing it. - cov = coverage.coverage() - cov.start() - self.importModule("mymain") - cov.stop() - - filename, _, _, _ = cov.analysis("mymain.py") - self.assertEqual(os.path.basename(filename), "mymain.py") - filename, _, _, _ = cov.analysis("mymod.py") - self.assertEqual(os.path.basename(filename), "mymod.py") - - filename, _, _, _ = cov.analysis(sys.modules["mymain"]) - self.assertEqual(os.path.basename(filename), "mymain.py") - filename, _, _, _ = cov.analysis(sys.modules["mymod"]) - self.assertEqual(os.path.basename(filename), "mymod.py") - - # Import the python file, executing it again, once it's been compiled - # already. - cov = coverage.coverage() - cov.start() - self.importModule("mymain") - cov.stop() - - filename, _, _, _ = cov.analysis("mymain.py") - self.assertEqual(os.path.basename(filename), "mymain.py") - filename, _, _, _ = cov.analysis("mymod.py") - self.assertEqual(os.path.basename(filename), "mymod.py") - - filename, _, _, _ = cov.analysis(sys.modules["mymain"]) - self.assertEqual(os.path.basename(filename), "mymain.py") - filename, _, _, _ = cov.analysis(sys.modules["mymod"]) - self.assertEqual(os.path.basename(filename), "mymod.py") - - def testIgnoreStdLib(self): - self.makeFile("mymain", """\ - import mymod, colorsys - a = 1 - hls = colorsys.rgb_to_hls(1.0, 0.5, 0.0) - """) - - self.makeFile("mymod", """\ - fooey = 17 - """) - - # Measure without the stdlib. - cov1 = coverage.coverage() - self.assertEqual(cov1.cover_stdlib, False) - cov1.start() - self.importModule("mymain") - cov1.stop() - - # some statements were marked executed in mymain.py - _, statements, missing, _ = cov1.analysis("mymain.py") - self.assertNotEqual(statements, missing) - # but none were in colorsys.py - _, statements, missing, _ = cov1.analysis("colorsys.py") - self.assertEqual(statements, missing) - - # Measure with the stdlib. - cov2 = coverage.coverage() - cov2.cover_stdlib = True - cov2.start() - self.importModule("mymain") - cov2.stop() - - # some statements were marked executed in mymain.py - _, statements, missing, _ = cov2.analysis("mymain.py") - self.assertNotEqual(statements, missing) - # and some were marked executed in colorsys.py - _, statements, missing, _ = cov2.analysis("colorsys.py") - self.assertNotEqual(statements, missing) - - class ProcessTest(CoverageTest): def testSaveOnExit(self): self.makeFile("mycode", """\ |