summaryrefslogtreecommitdiff
path: root/tests/test_context.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2019-10-02 10:27:06 -0400
committerNed Batchelder <ned@nedbatchelder.com>2019-10-02 16:08:46 -0400
commit079b6d8f145f50918461a4568d9a961e1eb38024 (patch)
treee239b9cc29ee3832c4f401ce42501bab927a8bb3 /tests/test_context.py
parent4c6a1f3746b9d9772cae7b415fc456422b4a8bd6 (diff)
downloadpython-coveragepy-git-079b6d8f145f50918461a4568d9a961e1eb38024.tar.gz
Setting query context has to be done with a separate method call
Diffstat (limited to 'tests/test_context.py')
-rw-r--r--tests/test_context.py64
1 files changed, 40 insertions, 24 deletions
diff --git a/tests/test_context.py b/tests/test_context.py
index eb8ee9c5..72739ad0 100644
--- a/tests/test_context.py
+++ b/tests/test_context.py
@@ -72,10 +72,14 @@ class StaticContextTest(CoverageTest):
fred = full_names['red.py']
fblue = full_names['blue.py']
- self.assertEqual(combined.lines(fred, contexts=['red']), self.LINES)
- self.assertEqual(combined.lines(fred, contexts=['blue']), [])
- self.assertEqual(combined.lines(fblue, contexts=['red']), [])
- self.assertEqual(combined.lines(fblue, contexts=['blue']), self.LINES)
+ def assert_combined_lines(filename, context, lines):
+ combined.set_query_context(context)
+ self.assertEqual(combined.lines(filename), lines)
+
+ assert_combined_lines(fred, 'red', self.LINES)
+ assert_combined_lines(fred, 'blue', [])
+ assert_combined_lines(fblue, 'red', [])
+ assert_combined_lines(fblue, 'blue', self.LINES)
def test_combining_arc_contexts(self):
red_data, blue_data = self.run_red_blue(branch=True)
@@ -92,15 +96,23 @@ class StaticContextTest(CoverageTest):
fred = full_names['red.py']
fblue = full_names['blue.py']
- self.assertEqual(combined.lines(fred, contexts=['red']), self.LINES)
- self.assertEqual(combined.lines(fred, contexts=['blue']), [])
- self.assertEqual(combined.lines(fblue, contexts=['red']), [])
- self.assertEqual(combined.lines(fblue, contexts=['blue']), self.LINES)
+ def assert_combined_lines(filename, context, lines):
+ combined.set_query_context(context)
+ self.assertEqual(combined.lines(filename), lines)
+
+ assert_combined_lines(fred, 'red', self.LINES)
+ assert_combined_lines(fred, 'blue', [])
+ assert_combined_lines(fblue, 'red', [])
+ assert_combined_lines(fblue, 'blue', self.LINES)
+
+ def assert_combined_arcs(filename, context, lines):
+ combined.set_query_context(context)
+ self.assertEqual(combined.arcs(filename), lines)
- self.assertEqual(combined.arcs(fred, contexts=['red']), self.ARCS)
- self.assertEqual(combined.arcs(fred, contexts=['blue']), [])
- self.assertEqual(combined.arcs(fblue, contexts=['red']), [])
- self.assertEqual(combined.arcs(fblue, contexts=['blue']), self.ARCS)
+ assert_combined_arcs(fred, 'red', self.ARCS)
+ assert_combined_arcs(fred, 'blue', [])
+ assert_combined_arcs(fblue, 'red', [])
+ assert_combined_arcs(fblue, 'blue', self.ARCS)
class DynamicContextTest(CoverageTest):
@@ -145,12 +157,14 @@ class DynamicContextTest(CoverageTest):
self.assertCountEqual(
data.measured_contexts(),
["", "two_tests.test_one", "two_tests.test_two"])
- self.assertCountEqual(data.lines(fname, [""]), self.OUTER_LINES)
- self.assertCountEqual(
- data.lines(fname, ["two_tests.test_one"]),
- self.TEST_ONE_LINES)
- self.assertCountEqual(
- data.lines(fname, ["two_tests.test_two"]), self.TEST_TWO_LINES)
+
+ def assert_context_lines(context, lines):
+ data.set_query_context(context)
+ self.assertCountEqual(lines, data.lines(fname))
+
+ assert_context_lines("", self.OUTER_LINES)
+ assert_context_lines("two_tests.test_one", self.TEST_ONE_LINES)
+ assert_context_lines("two_tests.test_two", self.TEST_TWO_LINES)
def test_static_and_dynamic(self):
self.make_file("two_tests.py", self.SOURCE)
@@ -164,12 +178,14 @@ class DynamicContextTest(CoverageTest):
self.assertCountEqual(
data.measured_contexts(),
["stat", "stat|two_tests.test_one", "stat|two_tests.test_two"])
- self.assertCountEqual(
- data.lines(fname, ["stat"]), self.OUTER_LINES)
- self.assertCountEqual(
- data.lines(fname, ["stat|two_tests.test_one"]), self.TEST_ONE_LINES)
- self.assertCountEqual(
- data.lines(fname, ["stat|two_tests.test_two"]), self.TEST_TWO_LINES)
+
+ def assert_context_lines(context, lines):
+ data.set_query_context(context)
+ self.assertCountEqual(lines, data.lines(fname))
+
+ assert_context_lines("stat", self.OUTER_LINES)
+ assert_context_lines("stat|two_tests.test_one", self.TEST_ONE_LINES)
+ assert_context_lines("stat|two_tests.test_two", self.TEST_TWO_LINES)
def get_qualname():