diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test_annotate.py | 121 | 
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") | 
