6
6
import os .path
7
7
8
8
import coverage
9
- from coverage .data import CoverageData , combine_parallel_data
9
+ from coverage .data import CoverageData
10
10
11
11
from tests .coveragetest import CoverageTest
12
12
@@ -32,58 +32,73 @@ def test_global_context(self):
32
32
data = cov .get_data ()
33
33
self .assertCountEqual (data .measured_contexts (), ["gooey" ])
34
34
35
+ SOURCE = """\
36
+ a = 1
37
+ if a > 2:
38
+ a = 3
39
+ assert a == 1
40
+ """
41
+
42
+ LINES = [1 , 2 , 4 ]
43
+ ARCS = [(- 1 , 1 ), (1 , 2 ), (2 , 4 ), (4 , - 1 )]
44
+
35
45
def run_red_blue (self , ** options ):
36
- self .make_file ("red.py" , """\
37
- a = 1
38
- if a > 2:
39
- a = 3
40
- assert a == 1
41
- """ )
46
+ """Run red.py and blue.py, and return their CoverageData objects."""
47
+ self .make_file ("red.py" , self .SOURCE )
42
48
red_cov = coverage .Coverage (context = "red" , data_suffix = "r" , source = ["." ], ** options )
43
49
self .start_import_stop (red_cov , "red" )
44
50
red_cov .save ()
51
+ red_data = red_cov .get_data ()
45
52
46
- self .make_file ("blue.py" , """\
47
- b = 1
48
- if b > 2:
49
- b = 3
50
- assert b == 1
51
- """ )
53
+ self .make_file ("blue.py" , self .SOURCE )
52
54
blue_cov = coverage .Coverage (context = "blue" , data_suffix = "b" , source = ["." ], ** options )
53
55
self .start_import_stop (blue_cov , "blue" )
54
56
blue_cov .save ()
57
+ blue_data = blue_cov .get_data ()
58
+
59
+ return red_data , blue_data
55
60
56
61
def test_combining_line_contexts (self ):
57
- self .run_red_blue ()
58
- combined = CoverageData ()
59
- combine_parallel_data (combined )
62
+ red_data , blue_data = self .run_red_blue ()
63
+ for datas in [[red_data , blue_data ], [blue_data , red_data ]]:
64
+ combined = CoverageData (suffix = "combined" )
65
+ for data in datas :
66
+ combined .update (data )
60
67
61
- self .assertEqual (combined .measured_contexts (), {'red' , 'blue' })
68
+ self .assertEqual (combined .measured_contexts (), {'red' , 'blue' })
62
69
63
- full_names = {os .path .basename (f ): f for f in combined .measured_files ()}
64
- self .assertCountEqual (full_names , ['red.py' , 'blue.py' ])
70
+ full_names = {os .path .basename (f ): f for f in combined .measured_files ()}
71
+ self .assertCountEqual (full_names , ['red.py' , 'blue.py' ])
65
72
66
- self .assertEqual (combined .lines (full_names ['red.py' ], context = 'red' ), [1 , 2 , 4 ])
67
- self .assertEqual (combined .lines (full_names ['red.py' ], context = 'blue' ), [])
68
- self .assertEqual (combined .lines (full_names ['blue.py' ], context = 'red' ), [])
69
- self .assertEqual (combined .lines (full_names ['blue.py' ], context = 'blue' ), [1 , 2 , 4 ])
73
+ fred = full_names ['red.py' ]
74
+ fblue = full_names ['blue.py' ]
75
+
76
+ self .assertEqual (combined .lines (fred , context = 'red' ), self .LINES )
77
+ self .assertEqual (combined .lines (fred , context = 'blue' ), [])
78
+ self .assertEqual (combined .lines (fblue , context = 'red' ), [])
79
+ self .assertEqual (combined .lines (fblue , context = 'blue' ), self .LINES )
70
80
71
81
def test_combining_arc_contexts (self ):
72
- self .run_red_blue (branch = True )
73
- combined = CoverageData ()
74
- combine_parallel_data (combined )
82
+ red_data , blue_data = self .run_red_blue (branch = True )
83
+ for datas in [[red_data , blue_data ], [blue_data , red_data ]]:
84
+ combined = CoverageData (suffix = "combined" )
85
+ for data in datas :
86
+ combined .update (data )
87
+
88
+ self .assertEqual (combined .measured_contexts (), {'red' , 'blue' })
75
89
76
- self .assertEqual (combined .measured_contexts (), {'red' , 'blue' })
90
+ full_names = {os .path .basename (f ): f for f in combined .measured_files ()}
91
+ self .assertCountEqual (full_names , ['red.py' , 'blue.py' ])
77
92
78
- full_names = { os . path . basename ( f ): f for f in combined . measured_files ()}
79
- self . assertCountEqual ( full_names , [ 'red.py' , ' blue.py' ])
93
+ fred = full_names [ 'red.py' ]
94
+ fblue = full_names [ ' blue.py' ]
80
95
81
- self .assertEqual (combined .lines (full_names [ 'red.py' ] , context = 'red' ), [ 1 , 2 , 4 ] )
82
- self .assertEqual (combined .lines (full_names [ 'red.py' ] , context = 'blue' ), [])
83
- self .assertEqual (combined .lines (full_names [ 'blue.py' ] , context = 'red' ), [])
84
- self .assertEqual (combined .lines (full_names [ 'blue.py' ] , context = 'blue' ), [ 1 , 2 , 4 ] )
96
+ self .assertEqual (combined .lines (fred , context = 'red' ), self . LINES )
97
+ self .assertEqual (combined .lines (fred , context = 'blue' ), [])
98
+ self .assertEqual (combined .lines (fblue , context = 'red' ), [])
99
+ self .assertEqual (combined .lines (fblue , context = 'blue' ), self . LINES )
85
100
86
- self .assertEqual (combined .arcs (full_names [ 'red.py' ] , context = 'red' ), [( - 1 , 1 ), ( 1 , 2 ), ( 2 , 4 ), ( 4 , - 1 )] )
87
- self .assertEqual (combined .arcs (full_names [ 'red.py' ] , context = 'blue' ), [])
88
- self .assertEqual (combined .arcs (full_names [ 'blue.py' ] , context = 'red' ), [])
89
- self .assertEqual (combined .arcs (full_names [ 'blue.py' ] , context = 'blue' ), [( - 1 , 1 ), ( 1 , 2 ), ( 2 , 4 ), ( 4 , - 1 )] )
101
+ self .assertEqual (combined .arcs (fred , context = 'red' ), self . ARCS )
102
+ self .assertEqual (combined .arcs (fred , context = 'blue' ), [])
103
+ self .assertEqual (combined .arcs (fblue , context = 'red' ), [])
104
+ self .assertEqual (combined .arcs (fblue , context = 'blue' ), self . ARCS )
0 commit comments