diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/farm/html/run_partial.py | 7 | ||||
-rw-r--r-- | tests/osinfo.py | 2 | ||||
-rw-r--r-- | tests/test_arcs.py | 117 | ||||
-rw-r--r-- | tests/test_config.py | 23 | ||||
-rw-r--r-- | tests/test_coverage.py | 332 | ||||
-rw-r--r-- | tests/test_html.py | 31 | ||||
-rw-r--r-- | tests/test_oddball.py | 73 | ||||
-rw-r--r-- | tests/test_phystokens.py | 9 | ||||
-rw-r--r-- | tests/test_process.py | 29 |
9 files changed, 299 insertions, 324 deletions
diff --git a/tests/farm/html/run_partial.py b/tests/farm/html/run_partial.py index 41e6ba9..eab1441 100644 --- a/tests/farm/html/run_partial.py +++ b/tests/farm/html/run_partial.py @@ -24,9 +24,8 @@ contains("html_partial/partial.html", contains("html_partial/index.html", "<a href='partial.html'>partial</a>", ) -if sys.version_info >= (2, 4): - contains("html_partial/index.html", - "<span class='pc_cov'>100%</span>" - ) +contains("html_partial/index.html", + "<span class='pc_cov'>100%</span>" + ) clean("html_partial") diff --git a/tests/osinfo.py b/tests/osinfo.py index 25c3a7c..acbec23 100644 --- a/tests/osinfo.py +++ b/tests/osinfo.py @@ -2,7 +2,7 @@ import sys -if sys.version_info >= (2, 5) and sys.platform == 'win32': +if sys.platform == 'win32': # Windows implementation def process_ram(): """How much RAM is this process using? (Windows)""" diff --git a/tests/test_arcs.py b/tests/test_arcs.py index 6268e28..80923f8 100644 --- a/tests/test_arcs.py +++ b/tests/test_arcs.py @@ -88,12 +88,6 @@ class SimpleArcTest(CoverageTest): arcz=".1 14 45 5. .2 2. 23 3.", arcz_missing="23 3.") def test_multiline(self): - # The firstlineno of the a assignment below differs among Python - # versions. - if sys.version_info >= (2, 5): - arcz = ".1 15 5-2" - else: - arcz = ".1 15 5-1" self.check_coverage("""\ a = ( 2 + @@ -102,7 +96,7 @@ class SimpleArcTest(CoverageTest): b = \\ 6 """, - arcz=arcz, arcz_missing="") + arcz=".1 15 5-2", arcz_missing="") def test_if_return(self): self.check_coverage("""\ @@ -151,33 +145,32 @@ class SimpleArcTest(CoverageTest): ) -if sys.version_info >= (2, 6): - class WithTest(CoverageTest): - """Arc-measuring tests involving context managers.""" +class WithTest(CoverageTest): + """Arc-measuring tests involving context managers.""" - def test_with(self): - self.check_coverage("""\ - def example(): - with open("test", "w") as f: # exit - f.write("") - return 1 + def test_with(self): + self.check_coverage("""\ + def example(): + with open("test", "w") as f: # exit + f.write("") + return 1 - example() - """, - arcz=".1 .2 23 34 4. 16 6." - ) + example() + """, + arcz=".1 .2 23 34 4. 16 6." + ) - def test_bug_146(self): - # https://bitbucket.org/ned/coveragepy/issue/146 - self.check_coverage("""\ - for i in range(2): - with open("test", "w") as f: - print(3) - print(4) - print(5) - """, - arcz=".1 12 23 34 41 15 5." - ) + def test_bug_146(self): + # https://bitbucket.org/ned/coveragepy/issue/146 + self.check_coverage("""\ + for i in range(2): + with open("test", "w") as f: + print(3) + print(4) + print(5) + """, + arcz=".1 12 23 34 41 15 5." + ) class LoopArcTest(CoverageTest): @@ -509,9 +502,9 @@ class ExceptionArcTest(CoverageTest): arcz=".1 12 23 35 56 61 17 7.", arcz_missing="", arcz_unpredicted="") - # Run this test only on 2.6 and 2.7 for now. I hope to fix it on Py3 + # Run this test only on Py2 for now. I hope to fix it on Py3 # eventually... - if (2, 6) <= sys.version_info < (3,): + if sys.version_info < (3, 0): # "except Exception as e" is crucial here. def test_bug_212(self): self.check_coverage("""\ @@ -533,36 +526,34 @@ class ExceptionArcTest(CoverageTest): arcz=".1 .2 1A 23 34 56 67 68 8. AB BC C. DE E.", arcz_missing="C.", arcz_unpredicted="45 7. CD") - if sys.version_info >= (2, 5): - # Try-except-finally was new in 2.5 - def test_except_finally(self): - self.check_coverage("""\ - a, b, c = 1, 1, 1 - try: - a = 3 - except: - b = 5 - finally: - c = 7 - assert a == 3 and b == 1 and c == 7 - """, - arcz=".1 12 23 45 37 57 78 8.", arcz_missing="45 57") - self.check_coverage("""\ - a, b, c = 1, 1, 1 - def oops(x): - if x % 2: raise Exception("odd") - try: - a = 5 - oops(1) - a = 7 - except: - b = 9 - finally: - c = 11 - assert a == 5 and b == 9 and c == 11 - """, - arcz=".1 12 .3 3-2 24 45 56 67 7B 89 9B BC C.", - arcz_missing="67 7B", arcz_unpredicted="68") + def test_except_finally(self): + self.check_coverage("""\ + a, b, c = 1, 1, 1 + try: + a = 3 + except: + b = 5 + finally: + c = 7 + assert a == 3 and b == 1 and c == 7 + """, + arcz=".1 12 23 45 37 57 78 8.", arcz_missing="45 57") + self.check_coverage("""\ + a, b, c = 1, 1, 1 + def oops(x): + if x % 2: raise Exception("odd") + try: + a = 5 + oops(1) + a = 7 + except: + b = 9 + finally: + c = 11 + assert a == 5 and b == 9 and c == 11 + """, + arcz=".1 12 .3 3-2 24 45 56 67 7B 89 9B BC C.", + arcz_missing="67 7B", arcz_unpredicted="68") class MiscArcTest(CoverageTest): diff --git a/tests/test_config.py b/tests/test_config.py index 6d37025..c44fa80 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -211,15 +211,14 @@ class ConfigFileTest(CoverageTest): 'other': ['other', '/home/ned/other', 'c:\\Ned\\etc'] }) - if sys.version_info[:2] != (3,1): - def test_one(self): - # This sample file tries to use lots of variation of syntax... - self.make_file(".coveragerc", """\ - [html] - title = tabblo & «ταБЬℓσ» # numbers - """) - cov = coverage.coverage() - - self.assertEqual(cov.config.html_title, - "tabblo & «ταБЬℓσ» # numbers" - ) + def test_one(self): + # This sample file tries to use lots of variation of syntax... + self.make_file(".coveragerc", """\ + [html] + title = tabblo & «ταБЬℓσ» # numbers + """) + cov = coverage.coverage() + + self.assertEqual(cov.config.html_title, + "tabblo & «ταБЬℓσ» # numbers" + ) diff --git a/tests/test_coverage.py b/tests/test_coverage.py index 6de4d0e..078c66c 100644 --- a/tests/test_coverage.py +++ b/tests/test_coverage.py @@ -839,15 +839,13 @@ class CompoundStatementTest(CoverageTest): """, [1,2,4,5,7,9,10], "4, 7") - if sys.version_info >= (2, 4): - # In 2.4 and up, constant if's were compiled away. - def test_constant_if(self): - self.check_coverage("""\ - if 1: - a = 2 - assert a == 2 - """, - [2,3], "") + def test_constant_if(self): + self.check_coverage("""\ + if 1: + a = 2 + assert a == 2 + """, + [2,3], "") def test_while(self): self.check_coverage("""\ @@ -1510,187 +1508,185 @@ class ExcludeTest(CoverageTest): [8,9], "", excludes=['#pragma: NO COVER']) -if sys.version_info >= (2, 4): - class Py24Test(CoverageTest): - """Tests of new syntax in Python 2.4.""" +class Py24Test(CoverageTest): + """Tests of new syntax in Python 2.4.""" - def test_function_decorators(self): - self.check_coverage("""\ - def require_int(func): - def wrapper(arg): - assert isinstance(arg, int) - return func(arg) + def test_function_decorators(self): + self.check_coverage("""\ + def require_int(func): + def wrapper(arg): + assert isinstance(arg, int) + return func(arg) + return wrapper + + @require_int + def p1(arg): + return arg*2 + + assert p1(10) == 20 + """, + [1,2,3,4,6,8,10,12], "") + + def test_function_decorators_with_args(self): + self.check_coverage("""\ + def boost_by(extra): + def decorator(func): + def wrapper(arg): + return extra*func(arg) return wrapper + return decorator - @require_int - def p1(arg): - return arg*2 + @boost_by(10) + def boosted(arg): + return arg*2 - assert p1(10) == 20 - """, - [1,2,3,4,6,8,10,12], "") + assert boosted(10) == 200 + """, + [1,2,3,4,5,6,8,10,12], "") - def test_function_decorators_with_args(self): - self.check_coverage("""\ - def boost_by(extra): - def decorator(func): - def wrapper(arg): - return extra*func(arg) - return wrapper - return decorator - - @boost_by(10) - def boosted(arg): - return arg*2 - - assert boosted(10) == 200 - """, - [1,2,3,4,5,6,8,10,12], "") + def test_double_function_decorators(self): + self.check_coverage("""\ + def require_int(func): + def wrapper(arg): + assert isinstance(arg, int) + return func(arg) + return wrapper - def test_double_function_decorators(self): - self.check_coverage("""\ - def require_int(func): + def boost_by(extra): + def decorator(func): def wrapper(arg): - assert isinstance(arg, int) - return func(arg) + return extra*func(arg) return wrapper + return decorator - def boost_by(extra): - def decorator(func): - def wrapper(arg): - return extra*func(arg) - return wrapper - return decorator + @require_int + @boost_by(10) + def boosted1(arg): + return arg*2 - @require_int - @boost_by(10) - def boosted1(arg): - return arg*2 + assert boosted1(10) == 200 - assert boosted1(10) == 200 + @boost_by(10) + @require_int + def boosted2(arg): + return arg*2 - @boost_by(10) - @require_int - def boosted2(arg): - return arg*2 + assert boosted2(10) == 200 + """, + ([1,2,3,4,5,7,8,9,10,11,12,14,15,17,19,21,22,24,26], + [1,2,3,4,5,7,8,9,10,11,12,14, 17,19,21, 24,26]), "") - assert boosted2(10) == 200 - """, - ([1,2,3,4,5,7,8,9,10,11,12,14,15,17,19,21,22,24,26], - [1,2,3,4,5,7,8,9,10,11,12,14, 17,19,21, 24,26]), "") +class Py25Test(CoverageTest): + """Tests of new syntax in Python 2.5.""" -if sys.version_info >= (2, 5): - class Py25Test(CoverageTest): - """Tests of new syntax in Python 2.5.""" + def test_with_statement(self): + self.check_coverage("""\ + from __future__ import with_statement - def test_with_statement(self): - self.check_coverage("""\ - from __future__ import with_statement + class Managed: + def __enter__(self): + desc = "enter" - class Managed: - def __enter__(self): - desc = "enter" + def __exit__(self, type, value, tb): + desc = "exit" - def __exit__(self, type, value, tb): - desc = "exit" + m = Managed() + with m: + desc = "block1a" + desc = "block1b" - m = Managed() + try: with m: - desc = "block1a" - desc = "block1b" - - try: - with m: - desc = "block2" - raise Exception("Boo!") - except: - desc = "caught" - """, - [1,3,4,5,7,8,10,11,12,13,15,16,17,18,19,20], "") + desc = "block2" + raise Exception("Boo!") + except: + desc = "caught" + """, + [1,3,4,5,7,8,10,11,12,13,15,16,17,18,19,20], "") - def test_try_except_finally(self): - self.check_coverage("""\ - a = 0; b = 0 - try: - a = 1 - except: - a = 99 - finally: - b = 2 - assert a == 1 and b == 2 - """, - [1,2,3,4,5,7,8], "4-5") - self.check_coverage("""\ - a = 0; b = 0 - try: - a = 1 - raise Exception("foo") - except: - a = 99 - finally: - b = 2 - assert a == 99 and b == 2 - """, - [1,2,3,4,5,6,8,9], "") - self.check_coverage("""\ - a = 0; b = 0 - try: - a = 1 - raise Exception("foo") - except ImportError: - a = 99 - except: - a = 123 - finally: - b = 2 - assert a == 123 and b == 2 - """, - [1,2,3,4,5,6,7,8,10,11], "6") - self.check_coverage("""\ - a = 0; b = 0 - try: - a = 1 - raise IOError("foo") - except ImportError: - a = 99 - except IOError: - a = 17 - except: - a = 123 - finally: - b = 2 - assert a == 17 and b == 2 - """, - [1,2,3,4,5,6,7,8,9,10,12,13], "6, 9-10") - self.check_coverage("""\ - a = 0; b = 0 - try: - a = 1 - except: - a = 99 - else: - a = 123 - finally: - b = 2 - assert a == 123 and b == 2 - """, - [1,2,3,4,5,7,9,10], "4-5") - self.check_coverage("""\ - a = 0; b = 0 - try: - a = 1 - raise Exception("foo") - except: - a = 99 - else: - a = 123 - finally: - b = 2 - assert a == 99 and b == 2 - """, - [1,2,3,4,5,6,8,10,11], "8") + def test_try_except_finally(self): + self.check_coverage("""\ + a = 0; b = 0 + try: + a = 1 + except: + a = 99 + finally: + b = 2 + assert a == 1 and b == 2 + """, + [1,2,3,4,5,7,8], "4-5") + self.check_coverage("""\ + a = 0; b = 0 + try: + a = 1 + raise Exception("foo") + except: + a = 99 + finally: + b = 2 + assert a == 99 and b == 2 + """, + [1,2,3,4,5,6,8,9], "") + self.check_coverage("""\ + a = 0; b = 0 + try: + a = 1 + raise Exception("foo") + except ImportError: + a = 99 + except: + a = 123 + finally: + b = 2 + assert a == 123 and b == 2 + """, + [1,2,3,4,5,6,7,8,10,11], "6") + self.check_coverage("""\ + a = 0; b = 0 + try: + a = 1 + raise IOError("foo") + except ImportError: + a = 99 + except IOError: + a = 17 + except: + a = 123 + finally: + b = 2 + assert a == 17 and b == 2 + """, + [1,2,3,4,5,6,7,8,9,10,12,13], "6, 9-10") + self.check_coverage("""\ + a = 0; b = 0 + try: + a = 1 + except: + a = 99 + else: + a = 123 + finally: + b = 2 + assert a == 123 and b == 2 + """, + [1,2,3,4,5,7,9,10], "4-5") + self.check_coverage("""\ + a = 0; b = 0 + try: + a = 1 + raise Exception("foo") + except: + a = 99 + else: + a = 123 + finally: + b = 2 + assert a == 99 and b == 2 + """, + [1,2,3,4,5,6,8,10,11], "8") class ModuleTest(CoverageTest): diff --git a/tests/test_html.py b/tests/test_html.py index 06132fb..f22fdc2 100644 --- a/tests/test_html.py +++ b/tests/test_html.py @@ -177,22 +177,21 @@ class HtmlTitleTest(HtmlTestHelpers, CoverageTest): self.assertIn("<title>Metrics & stuff!</title>", index) self.assertIn("<h1>Metrics & stuff!:", index) - if sys.version_info[:2] != (3,1): - def test_non_ascii_title_set_in_config_file(self): - self.create_initial_files() - self.make_file(".coveragerc", - "[html]\ntitle = «ταБЬℓσ» numbers" - ) - self.run_coverage() - index = open("htmlcov/index.html").read() - self.assertIn( - "<title>«ταБЬℓσ»" - " numbers", index - ) - self.assertIn( - "<h1>«ταБЬℓσ»" - " numbers", index - ) + def test_non_ascii_title_set_in_config_file(self): + self.create_initial_files() + self.make_file(".coveragerc", + "[html]\ntitle = «ταБЬℓσ» numbers" + ) + self.run_coverage() + index = open("htmlcov/index.html").read() + self.assertIn( + "<title>«ταБЬℓσ»" + " numbers", index + ) + self.assertIn( + "<h1>«ταБЬℓσ»" + " numbers", index + ) def test_title_set_in_args(self): self.create_initial_files() diff --git a/tests/test_oddball.py b/tests/test_oddball.py index 4b18a4e..eba507b 100644 --- a/tests/test_oddball.py +++ b/tests/test_oddball.py @@ -329,43 +329,42 @@ class ExceptionTest(CoverageTest): self.assertEqual(clean_lines, lines_expected) -if sys.version_info >= (2, 5): - class DoctestTest(CoverageTest): - """Tests invoked with doctest should measure properly.""" - - def setUp(self): - super(DoctestTest, self).setUp() - - # Oh, the irony! This test case exists because Python 2.4's - # doctest module doesn't play well with coverage. But nose fixes - # the problem by monkeypatching doctest. I want to undo the - # monkeypatch to be sure I'm getting the doctest module that users - # of coverage will get. Deleting the imported module here is - # enough: when the test imports doctest again, it will get a fresh - # copy without the monkeypatch. - del sys.modules['doctest'] - - def test_doctest(self): - self.check_coverage('''\ - def return_arg_or_void(arg): - """If <arg> is None, return "Void"; otherwise return <arg> - - >>> return_arg_or_void(None) - 'Void' - >>> return_arg_or_void("arg") - 'arg' - >>> return_arg_or_void("None") - 'None' - """ - if arg is None: - return "Void" - else: - return arg - - import doctest, sys - doctest.testmod(sys.modules[__name__]) # we're not __main__ :( - ''', - [1,11,12,14,16,17], "") +class DoctestTest(CoverageTest): + """Tests invoked with doctest should measure properly.""" + + def setUp(self): + super(DoctestTest, self).setUp() + + # Oh, the irony! This test case exists because Python 2.4's + # doctest module doesn't play well with coverage. But nose fixes + # the problem by monkeypatching doctest. I want to undo the + # monkeypatch to be sure I'm getting the doctest module that users + # of coverage will get. Deleting the imported module here is + # enough: when the test imports doctest again, it will get a fresh + # copy without the monkeypatch. + del sys.modules['doctest'] + + def test_doctest(self): + self.check_coverage('''\ + def return_arg_or_void(arg): + """If <arg> is None, return "Void"; otherwise return <arg> + + >>> return_arg_or_void(None) + 'Void' + >>> return_arg_or_void("arg") + 'arg' + >>> return_arg_or_void("None") + 'None' + """ + if arg is None: + return "Void" + else: + return arg + + import doctest, sys + doctest.testmod(sys.modules[__name__]) # we're not __main__ :( + ''', + [1,11,12,14,16,17], "") if hasattr(sys, 'gettrace'): diff --git a/tests/test_phystokens.py b/tests/test_phystokens.py index c1e51f1..76e59f3 100644 --- a/tests/test_phystokens.py +++ b/tests/test_phystokens.py @@ -86,11 +86,6 @@ if sys.version_info < (3, 0): run_in_temp_dir = False - if sys.version_info >= (2,4): - default_encoding = 'ascii' - else: - default_encoding = 'iso-8859-1' - def test_detect_source_encoding(self): # Various forms from http://www.python.org/dev/peps/pep-0263/ source = "# coding=cp850\n\n" @@ -110,11 +105,11 @@ if sys.version_info < (3, 0): def test_dont_detect_source_encoding_on_third_line(self): # A coding declaration doesn't count on the third line. source = "\n\n# coding=cp850\n\n" - self.assertEqual(source_encoding(source), self.default_encoding) + self.assertEqual(source_encoding(source), 'ascii') def test_detect_source_encoding_of_empty_file(self): # An important edge case. - self.assertEqual(source_encoding(""), self.default_encoding) + self.assertEqual(source_encoding(""), 'ascii') def test_bom(self): # A BOM means utf-8. diff --git a/tests/test_process.py b/tests/test_process.py index c49d90a..d1107e3 100644 --- a/tests/test_process.py +++ b/tests/test_process.py @@ -324,23 +324,20 @@ class ProcessTest(CoverageTest): out_py = self.run_command("python run_me.py") self.assertMultiLineEqual(out_cov, out_py) - if sys.version_info >= (2, 6): - # Doesn't work in 2.5, and I don't care! For some reason, python -m - # in 2.5 has __builtins__ as a dictionary instead of a module? - def test_coverage_run_dashm_is_like_python_dashm(self): - # These -m commands assume the coverage tree is on the path. - out_cov = self.run_command("coverage run -m tests.try_execfile") - out_py = self.run_command("python -m tests.try_execfile") - self.assertMultiLineEqual(out_cov, out_py) + def test_coverage_run_dashm_is_like_python_dashm(self): + # These -m commands assume the coverage tree is on the path. + out_cov = self.run_command("coverage run -m tests.try_execfile") + out_py = self.run_command("python -m tests.try_execfile") + self.assertMultiLineEqual(out_cov, out_py) - def test_coverage_run_dashm_is_like_python_dashm_off_path(self): - # https://bitbucket.org/ned/coveragepy/issue/242 - tryfile = os.path.join(here, "try_execfile.py") - self.make_file("sub/__init__.py", "") - self.make_file("sub/run_me.py", open(tryfile).read()) - out_cov = self.run_command("coverage run -m sub.run_me") - out_py = self.run_command("python -m sub.run_me") - self.assertMultiLineEqual(out_cov, out_py) + def test_coverage_run_dashm_is_like_python_dashm_off_path(self): + # https://bitbucket.org/ned/coveragepy/issue/242 + tryfile = os.path.join(here, "try_execfile.py") + self.make_file("sub/__init__.py", "") + self.make_file("sub/run_me.py", open(tryfile).read()) + out_cov = self.run_command("coverage run -m sub.run_me") + out_py = self.run_command("python -m sub.run_me") + self.assertMultiLineEqual(out_cov, out_py) if sys.version_info >= (2, 7): # Coverage isn't bug-for-bug compatible in the behavior of -m for |