diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2013-02-02 11:15:11 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2013-02-02 11:15:11 -0500 |
commit | c19232a9d2be2bde30e446311f32e9dcdd5d4774 (patch) | |
tree | c2a9afb49cb74d9e041058c0275e1896dc0ecd0c /test/test_arcs.py | |
parent | c359cea1408c410a4c770debeddf3aed0abd43fe (diff) | |
download | python-coveragepy-git-c19232a9d2be2bde30e446311f32e9dcdd5d4774.tar.gz |
Move the test directory to tests to avoid conflicts with the stdlib test package.
--HG--
rename : test/__init__.py => tests/__init__.py
rename : test/backtest.py => tests/backtest.py
rename : test/backunittest.py => tests/backunittest.py
rename : test/coveragetest.py => tests/coveragetest.py
rename : test/covmodzip1.py => tests/covmodzip1.py
rename : test/eggsrc/egg1/__init__.py => tests/eggsrc/egg1/__init__.py
rename : test/eggsrc/egg1/egg1.py => tests/eggsrc/egg1/egg1.py
rename : test/eggsrc/setup.py => tests/eggsrc/setup.py
rename : test/farm/annotate/annotate_dir.py => tests/farm/annotate/annotate_dir.py
rename : test/farm/annotate/gold/white.py,cover => tests/farm/annotate/gold/white.py,cover
rename : test/farm/annotate/gold_anno_dir/a___init__.py,cover => tests/farm/annotate/gold_anno_dir/a___init__.py,cover
rename : test/farm/annotate/gold_anno_dir/a_a.py,cover => tests/farm/annotate/gold_anno_dir/a_a.py,cover
rename : test/farm/annotate/gold_anno_dir/b___init__.py,cover => tests/farm/annotate/gold_anno_dir/b___init__.py,cover
rename : test/farm/annotate/gold_anno_dir/b_b.py,cover => tests/farm/annotate/gold_anno_dir/b_b.py,cover
rename : test/farm/annotate/gold_anno_dir/multi.py,cover => tests/farm/annotate/gold_anno_dir/multi.py,cover
rename : test/farm/annotate/gold_multi/a/__init__.py,cover => tests/farm/annotate/gold_multi/a/__init__.py,cover
rename : test/farm/annotate/gold_multi/a/a.py,cover => tests/farm/annotate/gold_multi/a/a.py,cover
rename : test/farm/annotate/gold_multi/b/__init__.py,cover => tests/farm/annotate/gold_multi/b/__init__.py,cover
rename : test/farm/annotate/gold_multi/b/b.py,cover => tests/farm/annotate/gold_multi/b/b.py,cover
rename : test/farm/annotate/gold_multi/multi.py,cover => tests/farm/annotate/gold_multi/multi.py,cover
rename : test/farm/annotate/gold_v24/white.py,cover => tests/farm/annotate/gold_v24/white.py,cover
rename : test/farm/annotate/run.py => tests/farm/annotate/run.py
rename : test/farm/annotate/run_multi.py => tests/farm/annotate/run_multi.py
rename : test/farm/annotate/src/a/__init__.py => tests/farm/annotate/src/a/__init__.py
rename : test/farm/annotate/src/a/a.py => tests/farm/annotate/src/a/a.py
rename : test/farm/annotate/src/b/__init__.py => tests/farm/annotate/src/b/__init__.py
rename : test/farm/annotate/src/b/b.py => tests/farm/annotate/src/b/b.py
rename : test/farm/annotate/src/multi.py => tests/farm/annotate/src/multi.py
rename : test/farm/annotate/src/white.py => tests/farm/annotate/src/white.py
rename : test/farm/html/gold_a/a.html => tests/farm/html/gold_a/a.html
rename : test/farm/html/gold_a/index.html => tests/farm/html/gold_a/index.html
rename : test/farm/html/gold_b_branch/b.html => tests/farm/html/gold_b_branch/b.html
rename : test/farm/html/gold_b_branch/index.html => tests/farm/html/gold_b_branch/index.html
rename : test/farm/html/gold_bom/bom.html => tests/farm/html/gold_bom/bom.html
rename : test/farm/html/gold_bom/index.html => tests/farm/html/gold_bom/index.html
rename : test/farm/html/gold_isolatin1/index.html => tests/farm/html/gold_isolatin1/index.html
rename : test/farm/html/gold_isolatin1/isolatin1.html => tests/farm/html/gold_isolatin1/isolatin1.html
rename : test/farm/html/gold_omit_1/index.html => tests/farm/html/gold_omit_1/index.html
rename : test/farm/html/gold_omit_1/m1.html => tests/farm/html/gold_omit_1/m1.html
rename : test/farm/html/gold_omit_1/m2.html => tests/farm/html/gold_omit_1/m2.html
rename : test/farm/html/gold_omit_1/m3.html => tests/farm/html/gold_omit_1/m3.html
rename : test/farm/html/gold_omit_1/main.html => tests/farm/html/gold_omit_1/main.html
rename : test/farm/html/gold_omit_2/index.html => tests/farm/html/gold_omit_2/index.html
rename : test/farm/html/gold_omit_2/m2.html => tests/farm/html/gold_omit_2/m2.html
rename : test/farm/html/gold_omit_2/m3.html => tests/farm/html/gold_omit_2/m3.html
rename : test/farm/html/gold_omit_2/main.html => tests/farm/html/gold_omit_2/main.html
rename : test/farm/html/gold_omit_3/index.html => tests/farm/html/gold_omit_3/index.html
rename : test/farm/html/gold_omit_3/m3.html => tests/farm/html/gold_omit_3/m3.html
rename : test/farm/html/gold_omit_3/main.html => tests/farm/html/gold_omit_3/main.html
rename : test/farm/html/gold_omit_4/index.html => tests/farm/html/gold_omit_4/index.html
rename : test/farm/html/gold_omit_4/m1.html => tests/farm/html/gold_omit_4/m1.html
rename : test/farm/html/gold_omit_4/m3.html => tests/farm/html/gold_omit_4/m3.html
rename : test/farm/html/gold_omit_4/main.html => tests/farm/html/gold_omit_4/main.html
rename : test/farm/html/gold_omit_5/index.html => tests/farm/html/gold_omit_5/index.html
rename : test/farm/html/gold_omit_5/m1.html => tests/farm/html/gold_omit_5/m1.html
rename : test/farm/html/gold_omit_5/main.html => tests/farm/html/gold_omit_5/main.html
rename : test/farm/html/gold_other/blah_blah_other.html => tests/farm/html/gold_other/blah_blah_other.html
rename : test/farm/html/gold_other/here.html => tests/farm/html/gold_other/here.html
rename : test/farm/html/gold_other/index.html => tests/farm/html/gold_other/index.html
rename : test/farm/html/gold_partial/index.html => tests/farm/html/gold_partial/index.html
rename : test/farm/html/gold_partial/partial.html => tests/farm/html/gold_partial/partial.html
rename : test/farm/html/gold_styled/a.html => tests/farm/html/gold_styled/a.html
rename : test/farm/html/gold_styled/extra.css => tests/farm/html/gold_styled/extra.css
rename : test/farm/html/gold_styled/index.html => tests/farm/html/gold_styled/index.html
rename : test/farm/html/gold_styled/style.css => tests/farm/html/gold_styled/style.css
rename : test/farm/html/gold_unicode/index.html => tests/farm/html/gold_unicode/index.html
rename : test/farm/html/gold_unicode/unicode.html => tests/farm/html/gold_unicode/unicode.html
rename : test/farm/html/gold_x_xml/coverage.xml => tests/farm/html/gold_x_xml/coverage.xml
rename : test/farm/html/gold_y_xml_branch/coverage.xml => tests/farm/html/gold_y_xml_branch/coverage.xml
rename : test/farm/html/othersrc/other.py => tests/farm/html/othersrc/other.py
rename : test/farm/html/run_a.py => tests/farm/html/run_a.py
rename : test/farm/html/run_a_xml_1.py => tests/farm/html/run_a_xml_1.py
rename : test/farm/html/run_a_xml_2.py => tests/farm/html/run_a_xml_2.py
rename : test/farm/html/run_b_branch.py => tests/farm/html/run_b_branch.py
rename : test/farm/html/run_bom.py => tests/farm/html/run_bom.py
rename : test/farm/html/run_isolatin1.py => tests/farm/html/run_isolatin1.py
rename : test/farm/html/run_omit_1.py => tests/farm/html/run_omit_1.py
rename : test/farm/html/run_omit_2.py => tests/farm/html/run_omit_2.py
rename : test/farm/html/run_omit_3.py => tests/farm/html/run_omit_3.py
rename : test/farm/html/run_omit_4.py => tests/farm/html/run_omit_4.py
rename : test/farm/html/run_omit_5.py => tests/farm/html/run_omit_5.py
rename : test/farm/html/run_other.py => tests/farm/html/run_other.py
rename : test/farm/html/run_partial.py => tests/farm/html/run_partial.py
rename : test/farm/html/run_styled.py => tests/farm/html/run_styled.py
rename : test/farm/html/run_tabbed.py => tests/farm/html/run_tabbed.py
rename : test/farm/html/run_unicode.py => tests/farm/html/run_unicode.py
rename : test/farm/html/run_y_xml_branch.py => tests/farm/html/run_y_xml_branch.py
rename : test/farm/html/src/a.py => tests/farm/html/src/a.py
rename : test/farm/html/src/b.py => tests/farm/html/src/b.py
rename : test/farm/html/src/bom.py => tests/farm/html/src/bom.py
rename : test/farm/html/src/coverage.xml => tests/farm/html/src/coverage.xml
rename : test/farm/html/src/extra.css => tests/farm/html/src/extra.css
rename : test/farm/html/src/here.py => tests/farm/html/src/here.py
rename : test/farm/html/src/isolatin1.py => tests/farm/html/src/isolatin1.py
rename : test/farm/html/src/m1.py => tests/farm/html/src/m1.py
rename : test/farm/html/src/m2.py => tests/farm/html/src/m2.py
rename : test/farm/html/src/m3.py => tests/farm/html/src/m3.py
rename : test/farm/html/src/main.py => tests/farm/html/src/main.py
rename : test/farm/html/src/omit4.ini => tests/farm/html/src/omit4.ini
rename : test/farm/html/src/omit5.ini => tests/farm/html/src/omit5.ini
rename : test/farm/html/src/partial.py => tests/farm/html/src/partial.py
rename : test/farm/html/src/run_a_xml_2.ini => tests/farm/html/src/run_a_xml_2.ini
rename : test/farm/html/src/tabbed.py => tests/farm/html/src/tabbed.py
rename : test/farm/html/src/unicode.py => tests/farm/html/src/unicode.py
rename : test/farm/html/src/y.py => tests/farm/html/src/y.py
rename : test/farm/run/run_chdir.py => tests/farm/run/run_chdir.py
rename : test/farm/run/run_timid.py => tests/farm/run/run_timid.py
rename : test/farm/run/run_xxx.py => tests/farm/run/run_xxx.py
rename : test/farm/run/src/chdir.py => tests/farm/run/src/chdir.py
rename : test/farm/run/src/showtrace.py => tests/farm/run/src/showtrace.py
rename : test/farm/run/src/subdir/placeholder => tests/farm/run/src/subdir/placeholder
rename : test/farm/run/src/xxx => tests/farm/run/src/xxx
rename : test/js/index.html => tests/js/index.html
rename : test/js/tests.js => tests/js/tests.js
rename : test/modules/aa/__init__.py => tests/modules/aa/__init__.py
rename : test/modules/aa/afile.odd.py => tests/modules/aa/afile.odd.py
rename : test/modules/aa/afile.py => tests/modules/aa/afile.py
rename : test/modules/aa/bb.odd/bfile.py => tests/modules/aa/bb.odd/bfile.py
rename : test/modules/aa/bb/__init__.py => tests/modules/aa/bb/__init__.py
rename : test/modules/aa/bb/bfile.odd.py => tests/modules/aa/bb/bfile.odd.py
rename : test/modules/aa/bb/bfile.py => tests/modules/aa/bb/bfile.py
rename : test/modules/aa/bb/cc/__init__.py => tests/modules/aa/bb/cc/__init__.py
rename : test/modules/aa/bb/cc/cfile.py => tests/modules/aa/bb/cc/cfile.py
rename : test/modules/aa/zfile.py => tests/modules/aa/zfile.py
rename : test/modules/covmod1.py => tests/modules/covmod1.py
rename : test/modules/pkg1/__init__.py => tests/modules/pkg1/__init__.py
rename : test/modules/pkg1/__main__.py => tests/modules/pkg1/__main__.py
rename : test/modules/pkg1/p1a.py => tests/modules/pkg1/p1a.py
rename : test/modules/pkg1/p1b.py => tests/modules/pkg1/p1b.py
rename : test/modules/pkg1/p1c.py => tests/modules/pkg1/p1c.py
rename : test/modules/pkg1/runmod2.py => tests/modules/pkg1/runmod2.py
rename : test/modules/pkg1/sub/__init__.py => tests/modules/pkg1/sub/__init__.py
rename : test/modules/pkg1/sub/__main__.py => tests/modules/pkg1/sub/__main__.py
rename : test/modules/pkg1/sub/ps1a.py => tests/modules/pkg1/sub/ps1a.py
rename : test/modules/pkg1/sub/runmod3.py => tests/modules/pkg1/sub/runmod3.py
rename : test/modules/pkg2/__init__.py => tests/modules/pkg2/__init__.py
rename : test/modules/pkg2/p2a.py => tests/modules/pkg2/p2a.py
rename : test/modules/pkg2/p2b.py => tests/modules/pkg2/p2b.py
rename : test/modules/runmod1.py => tests/modules/runmod1.py
rename : test/modules/usepkgs.py => tests/modules/usepkgs.py
rename : test/moremodules/othermods/__init__.py => tests/moremodules/othermods/__init__.py
rename : test/moremodules/othermods/othera.py => tests/moremodules/othermods/othera.py
rename : test/moremodules/othermods/otherb.py => tests/moremodules/othermods/otherb.py
rename : test/moremodules/othermods/sub/__init__.py => tests/moremodules/othermods/sub/__init__.py
rename : test/moremodules/othermods/sub/osa.py => tests/moremodules/othermods/sub/osa.py
rename : test/moremodules/othermods/sub/osb.py => tests/moremodules/othermods/sub/osb.py
rename : test/osinfo.py => tests/osinfo.py
rename : test/qunit/jquery.tmpl.min.js => tests/qunit/jquery.tmpl.min.js
rename : test/qunit/qunit.css => tests/qunit/qunit.css
rename : test/qunit/qunit.js => tests/qunit/qunit.js
rename : test/stress_phystoken.tok => tests/stress_phystoken.tok
rename : test/stress_phystoken_dos.tok => tests/stress_phystoken_dos.tok
rename : test/test_api.py => tests/test_api.py
rename : test/test_arcs.py => tests/test_arcs.py
rename : test/test_cmdline.py => tests/test_cmdline.py
rename : test/test_codeunit.py => tests/test_codeunit.py
rename : test/test_config.py => tests/test_config.py
rename : test/test_coverage.py => tests/test_coverage.py
rename : test/test_data.py => tests/test_data.py
rename : test/test_execfile.py => tests/test_execfile.py
rename : test/test_farm.py => tests/test_farm.py
rename : test/test_files.py => tests/test_files.py
rename : test/test_html.py => tests/test_html.py
rename : test/test_misc.py => tests/test_misc.py
rename : test/test_oddball.py => tests/test_oddball.py
rename : test/test_parser.py => tests/test_parser.py
rename : test/test_phystokens.py => tests/test_phystokens.py
rename : test/test_process.py => tests/test_process.py
rename : test/test_results.py => tests/test_results.py
rename : test/test_summary.py => tests/test_summary.py
rename : test/test_templite.py => tests/test_templite.py
rename : test/test_testing.py => tests/test_testing.py
rename : test/test_xml.py => tests/test_xml.py
rename : test/try_execfile.py => tests/try_execfile.py
Diffstat (limited to 'test/test_arcs.py')
-rw-r--r-- | test/test_arcs.py | 578 |
1 files changed, 0 insertions, 578 deletions
diff --git a/test/test_arcs.py b/test/test_arcs.py deleted file mode 100644 index 69c054cc..00000000 --- a/test/test_arcs.py +++ /dev/null @@ -1,578 +0,0 @@ -"""Tests for Coverage.py's arc measurement.""" - -import sys -from test.coveragetest import CoverageTest - - -class SimpleArcTest(CoverageTest): - """Tests for Coverage.py's arc measurement.""" - - def test_simple_sequence(self): - self.check_coverage("""\ - a = 1 - b = 2 - """, - arcz=".1 12 2.") - self.check_coverage("""\ - a = 1 - - b = 3 - """, - arcz=".1 13 3.") - self.check_coverage("""\ - - a = 2 - b = 3 - - c = 5 - """, - arcz=".2 23 35 5-2") - - def test_function_def(self): - self.check_coverage("""\ - def foo(): - a = 2 - - foo() - """, - arcz=".1 .2 14 2. 4.") - - def test_if(self): - self.check_coverage("""\ - a = 1 - if len([]) == 0: - a = 3 - assert a == 3 - """, - arcz=".1 12 23 24 34 4.", arcz_missing="24") - self.check_coverage("""\ - a = 1 - if len([]) == 1: - a = 3 - assert a == 1 - """, - arcz=".1 12 23 24 34 4.", arcz_missing="23 34") - - def test_if_else(self): - self.check_coverage("""\ - if len([]) == 0: - a = 2 - else: - a = 4 - assert a == 2 - """, - arcz=".1 12 25 14 45 5.", arcz_missing="14 45") - self.check_coverage("""\ - if len([]) == 1: - a = 2 - else: - a = 4 - assert a == 4 - """, - arcz=".1 12 25 14 45 5.", arcz_missing="12 25") - - def test_compact_if(self): - self.check_coverage("""\ - a = 1 - if len([]) == 0: a = 2 - assert a == 2 - """, - arcz=".1 12 23 3.", arcz_missing="") - self.check_coverage("""\ - def fn(x): - if x % 2: return True - return False - a = fn(1) - assert a == True - """, - 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 + - 3 - ) - b = \\ - 6 - """, - arcz=arcz, arcz_missing="") - - def test_if_return(self): - self.check_coverage("""\ - def if_ret(a): - if a: - return 3 - b = 4 - return 5 - x = if_ret(0) + if_ret(1) - assert x == 8 - """, - arcz=".1 16 67 7. .2 23 24 3. 45 5.", arcz_missing="" - ) - - def test_dont_confuse_exit_and_else(self): - self.check_coverage("""\ - def foo(): - if foo: - a = 3 - else: - a = 5 - return a - assert foo() == 3 # 7 - """, - arcz=".1 17 7. .2 23 36 25 56 6.", arcz_missing="25 56" - ) - self.check_coverage("""\ - def foo(): - if foo: - a = 3 - else: - a = 5 - foo() # 6 - """, - arcz=".1 16 6. .2 23 3. 25 5.", arcz_missing="25 5." - ) - - if 0: # expected failure - def test_lambdas_are_confusing_bug_90(self): - self.check_coverage("""\ - a = 1 - fn = lambda x: x - b = 3 - """, - arcz=".1 12 .2 2-2 23 3." - ) - - -if sys.version_info >= (2, 6): - 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 - - example() - """, - arcz=".1 .2 23 34 4. 16 6." - ) - - -class LoopArcTest(CoverageTest): - """Arc-measuring tests involving loops.""" - - def test_loop(self): - self.check_coverage("""\ - for i in range(10): - a = i - assert a == 9 - """, - arcz=".1 12 21 13 3.", arcz_missing="") - self.check_coverage("""\ - a = -1 - for i in range(0): - a = i - assert a == -1 - """, - arcz=".1 12 23 32 24 4.", arcz_missing="23 32") - - def test_nested_loop(self): - self.check_coverage("""\ - for i in range(3): - for j in range(3): - a = i + j - assert a == 4 - """, - arcz=".1 12 23 32 21 14 4.", arcz_missing="") - - def test_break(self): - self.check_coverage("""\ - for i in range(10): - a = i - break # 3 - a = 99 - assert a == 0 # 5 - """, - arcz=".1 12 23 35 15 41 5.", arcz_missing="15 41") - - def test_continue(self): - self.check_coverage("""\ - for i in range(10): - a = i - continue # 3 - a = 99 - assert a == 9 # 5 - """, - arcz=".1 12 23 31 15 41 5.", arcz_missing="41") - - def test_nested_breaks(self): - self.check_coverage("""\ - for i in range(3): - for j in range(3): - a = i + j - break # 4 - if i == 2: - break - assert a == 2 and i == 2 # 7 - """, - arcz=".1 12 23 34 45 25 56 51 67 17 7.", arcz_missing="17 25") - - def test_while_true(self): - # With "while 1", the loop knows it's constant. - self.check_coverage("""\ - a, i = 1, 0 - while 1: - if i >= 3: - a = 4 - break - i += 1 - assert a == 4 and i == 3 - """, - arcz=".1 12 23 34 45 36 63 57 7.", - ) - # With "while True", 2.x thinks it's computation, 3.x thinks it's - # constant. - if sys.version_info >= (3, 0): - arcz = ".1 12 23 34 45 36 63 57 7." - else: - arcz = ".1 12 23 27 34 45 36 62 57 7." - self.check_coverage("""\ - a, i = 1, 0 - while True: - if i >= 3: - a = 4 - break - i += 1 - assert a == 4 and i == 3 - """, - arcz=arcz, - ) - - def test_for_if_else_for(self): - self.check_coverage("""\ - def branches_2(l): - if l: - for e in l: - a = 4 - else: - a = 6 - - def branches_3(l): - for x in l: - if x: - for e in l: - a = 12 - else: - a = 14 - - branches_2([0,1]) - branches_3([0,1]) - """, - arcz= - ".1 18 8G GH H. " - ".2 23 34 43 26 3. 6. " - ".9 9A 9-8 AB BC CB B9 AE E9", - arcz_missing="26 6." - ) - - def test_for_else(self): - self.check_coverage("""\ - def forelse(seq): - for n in seq: - if n > 5: - break - else: - print('None of the values were greater than 5') - print('Done') - forelse([1,2]) - forelse([1,6]) - """, - arcz=".1 .2 23 32 34 47 26 67 7. 18 89 9." - ) - - def test_confusing_for_loop_bug_175(self): - if sys.version_info >= (3, 0): - # Py3 counts the list comp as a separate code object. - arcz = ".1 .2 2-2 12 23 34 45 53 3." - else: - arcz = ".1 12 23 34 45 53 3." - self.check_coverage("""\ - o = [(1,2), (3,4)] - o = [a for a in o] - for tup in o: - x = tup[0] - y = tup[1] - """, - arcz=arcz, arcz_missing="", arcz_unpredicted="") - if sys.version_info >= (3, 0): - arcz = ".1 12 .2 2-2 23 34 42 2." - else: - arcz = ".1 12 23 34 42 2." - self.check_coverage("""\ - o = [(1,2), (3,4)] - for tup in [a for a in o]: - x = tup[0] - y = tup[1] - """, - arcz=arcz, arcz_missing="", arcz_unpredicted="") - - -class ExceptionArcTest(CoverageTest): - """Arc-measuring tests involving exception handling.""" - - def test_try_except(self): - self.check_coverage("""\ - a, b = 1, 1 - try: - a = 3 - except: - b = 5 - assert a == 3 and b == 1 - """, - arcz=".1 12 23 36 45 56 6.", arcz_missing="45 56") - self.check_coverage("""\ - a, b = 1, 1 - try: - a = 3 - raise Exception("Yikes!") - a = 5 - except: - b = 7 - assert a == 3 and b == 7 - """, - arcz=".1 12 23 34 58 67 78 8.", - arcz_missing="58", arcz_unpredicted="46") - - def test_hidden_raise(self): - self.check_coverage("""\ - a, b = 1, 1 - def oops(x): - if x % 2: raise Exception("odd") - try: - a = 5 - oops(1) - a = 7 - except: - b = 9 - assert a == 5 and b == 9 - """, - arcz=".1 12 .3 3-2 24 45 56 67 7A 89 9A A.", - arcz_missing="67 7A", arcz_unpredicted="68") - - def test_except_with_type(self): - self.check_coverage("""\ - a, b = 1, 1 - def oops(x): - if x % 2: raise ValueError("odd") - def try_it(x): - try: - a = 6 - oops(x) - a = 8 - except ValueError: - b = 10 - return a - assert try_it(0) == 8 # C - assert try_it(1) == 6 # D - """, - arcz=".1 12 .3 3-2 24 4C CD D. .5 56 67 78 8B 9A AB B-4", - arcz_missing="", - arcz_unpredicted="79") - - def test_try_finally(self): - self.check_coverage("""\ - a, c = 1, 1 - try: - a = 3 - finally: - c = 5 - assert a == 3 and c == 5 - """, - arcz=".1 12 23 35 56 6.", arcz_missing="") - self.check_coverage("""\ - a, c, d = 1, 1, 1 - try: - try: - a = 4 - finally: - c = 6 - except: - d = 8 - assert a == 4 and c == 6 and d == 1 # 9 - """, - arcz=".1 12 23 34 46 67 78 89 69 9.", - arcz_missing="67 78 89", arcz_unpredicted="") - self.check_coverage("""\ - a, c, d = 1, 1, 1 - try: - try: - a = 4 - raise Exception("Yikes!") - a = 6 - finally: - c = 8 - except: - d = 10 # A - assert a == 4 and c == 8 and d == 10 # B - """, - arcz=".1 12 23 34 45 68 89 8B 9A AB B.", - arcz_missing="68 8B", arcz_unpredicted="58") - - def test_finally_in_loop(self): - self.check_coverage("""\ - a, c, d, i = 1, 1, 1, 99 - try: - for i in range(5): - try: - a = 5 - if i > 0: - raise Exception("Yikes!") - a = 8 - finally: - c = 10 - except: - d = 12 # C - assert a == 5 and c == 10 and d == 12 # D - """, - arcz=".1 12 23 34 3D 45 56 67 68 8A A3 AB AD BC CD D.", - arcz_missing="3D AD", arcz_unpredicted="7A") - self.check_coverage("""\ - a, c, d, i = 1, 1, 1, 99 - try: - for i in range(5): - try: - a = 5 - if i > 10: - raise Exception("Yikes!") - a = 8 - finally: - c = 10 - except: - d = 12 # C - assert a == 8 and c == 10 and d == 1 # D - """, - arcz=".1 12 23 34 3D 45 56 67 68 8A A3 AB AD BC CD D.", - arcz_missing="67 AB AD BC CD", arcz_unpredicted="") - - - def test_break_in_finally(self): - self.check_coverage("""\ - a, c, d, i = 1, 1, 1, 99 - try: - for i in range(5): - try: - a = 5 - if i > 0: - break - a = 8 - finally: - c = 10 - except: - d = 12 # C - assert a == 5 and c == 10 and d == 1 # D - """, - arcz=".1 12 23 34 3D 45 56 67 68 7A 8A A3 AB AD BC CD D.", - arcz_missing="3D AB BC CD", arcz_unpredicted="") - - if 1: # expected failure - def test_finally_in_loop_bug_92(self): - self.check_coverage("""\ - for i in range(5): - try: - j = 3 - finally: - f = 5 - g = 6 - h = 7 - """, - arcz=".1 12 23 35 56 61 17 7.", - arcz_missing="", arcz_unpredicted="") - - 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") - - -class MiscArcTest(CoverageTest): - """Miscellaneous arc-measuring tests.""" - - def test_dict_literal(self): - self.check_coverage("""\ - d = { - 'a': 2, - 'b': 3, - 'c': { - 'd': 5, - 'e': 6, - } - } - assert d - """, - arcz=".1 19 9.") - - -class ExcludeTest(CoverageTest): - """Tests of exclusions to indicate known partial branches.""" - - def test_default(self): - # A number of forms of pragma comment are accepted. - self.check_coverage("""\ - a = 1 - if a: #pragma: no branch - b = 3 - c = 4 - if c: # pragma NOBRANCH - d = 6 - e = 7 - """, - [1,2,3,4,5,6,7], - arcz=".1 12 23 24 34 45 56 57 67 7.", arcz_missing="") - - def test_custom_pragmas(self): - self.check_coverage("""\ - a = 1 - while a: # [only some] - c = 3 - break - assert c == 5-2 - """, - [1,2,3,4,5], - partials=["only some"], - arcz=".1 12 23 34 45 25 5.", arcz_missing="") |