summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2018-11-15 06:07:31 -0500
committerNed Batchelder <ned@nedbatchelder.com>2018-11-15 06:52:18 -0500
commit88f1a0992d7afc2218cefb9384dc0096ab017a47 (patch)
treefc69265901cc1f4af9a78ec687d8582d6862673c
parent852951d2740b5e87109fd9538787bc424bf95237 (diff)
downloadpython-coveragepy-git-88f1a0992d7afc2218cefb9384dc0096ab017a47.tar.gz
Convert annotate() farm tests to normal tests
-rw-r--r--tests/test_annotate.py121
1 files changed, 121 insertions, 0 deletions
diff --git a/tests/test_annotate.py b/tests/test_annotate.py
new file mode 100644
index 00000000..634c1c14
--- /dev/null
+++ b/tests/test_annotate.py
@@ -0,0 +1,121 @@
+# coding: utf-8
+# Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
+# For details: https://github.com/nedbat/coveragepy/blob/master/NOTICE.txt
+
+"""Tests for annotation from coverage.py."""
+
+import coverage
+
+from tests.coveragetest import CoverageTest
+from tests.goldtest import compare, gold_path
+
+
+class AnnotationGoldTest1(CoverageTest):
+
+ def make_multi(self):
+ self.make_file("multi.py", """\
+ # Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
+ # For details: https://github.com/nedbat/coveragepy/blob/master/NOTICE.txt
+
+ import a.a
+ import b.b
+
+ a.a.a(1)
+ b.b.b(2)
+ """)
+ self.make_file("a/__init__.py")
+ self.make_file("a/a.py", """\
+ # Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
+ # For details: https://github.com/nedbat/coveragepy/blob/master/NOTICE.txt
+
+ def a(x):
+ if x == 1:
+ print("x is 1")
+ else:
+ print("x is not 1")
+ """)
+ self.make_file("b/__init__.py")
+ self.make_file("b/b.py", """\
+ # Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
+ # For details: https://github.com/nedbat/coveragepy/blob/master/NOTICE.txt
+
+ def b(x):
+ msg = "x is %s" % x
+ print(msg)
+ """)
+
+ def test_multi(self):
+ self.make_multi()
+ cov = coverage.Coverage()
+ self.start_import_stop(cov, "multi")
+ cov.annotate()
+
+ compare(gold_path("annotate/gold_multi"), ".", "*,cover")
+
+ def test_annotate_dir(self):
+ self.make_multi()
+ cov = coverage.Coverage(source=["."])
+ self.start_import_stop(cov, "multi")
+ cov.annotate(directory="out_anno_dir")
+
+ compare(gold_path("annotate/gold_anno_dir"), "out_anno_dir", "*,cover")
+
+ def test_encoding(self):
+ self.make_file("utf8.py", """\
+ # -*- coding: utf-8 -*-
+ # Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
+ # For details: https://github.com/nedbat/coveragepy/blob/master/NOTICE.txt
+
+ # This comment has an accent: é
+
+ print("spam eggs")
+ """)
+ cov = coverage.Coverage()
+ self.start_import_stop(cov, "utf8")
+ cov.annotate()
+ compare(gold_path("annotate/gold_encodings"), ".", "*,cover")
+
+ def test_white(self):
+ self.make_file("white.py", """\
+ # Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
+ # For details: https://github.com/nedbat/coveragepy/blob/master/NOTICE.txt
+
+ # A test case sent to me by Steve White
+
+ def f(self):
+ if self==1:
+ pass
+ elif self.m('fred'):
+ pass
+ elif (g==1) and (b==2):
+ pass
+ elif self.m('fred')==True:
+ pass
+ elif ((g==1) and (b==2))==True:
+ pass
+ else:
+ pass
+
+ def g(x):
+ if x == 1:
+ a = 1
+ else:
+ a = 2
+
+ g(1)
+
+ def h(x):
+ if 0: #pragma: no cover
+ pass
+ if x == 1:
+ a = 1
+ else:
+ a = 2
+
+ h(2)
+ """)
+
+ cov = coverage.Coverage()
+ self.start_import_stop(cov, "white")
+ cov.annotate()
+ compare(gold_path("annotate/gold"), ".", "*,cover")