58
58
MEASURED_FILES_3_4 = ['x.py' , 'y.py' , 'z.py' ]
59
59
60
60
61
- class DataTestHelpers (CoverageTest ):
62
- """Test helpers for data tests."""
63
-
64
- def assert_line_counts (self , covdata , counts , fullpath = False ):
65
- """Check that the line_counts of `covdata` is `counts`."""
66
- assert line_counts (covdata , fullpath ) == counts
67
-
68
- def assert_measured_files (self , covdata , measured ):
69
- """Check that `covdata`'s measured files are `measured`."""
70
- assert_count_equal (covdata .measured_files (), measured )
71
-
72
- def assert_lines1_data (self , covdata ):
73
- """Check that `covdata` has the data from LINES1."""
74
- self .assert_line_counts (covdata , SUMMARY_1 )
75
- self .assert_measured_files (covdata , MEASURED_FILES_1 )
76
- assert_count_equal (covdata .lines ("a.py" ), A_PY_LINES_1 )
77
- assert not covdata .has_arcs ()
78
-
79
- def assert_arcs3_data (self , covdata ):
80
- """Check that `covdata` has the data from ARCS3."""
81
- self .assert_line_counts (covdata , SUMMARY_3 )
82
- self .assert_measured_files (covdata , MEASURED_FILES_3 )
83
- assert_count_equal (covdata .lines ("x.py" ), X_PY_LINES_3 )
84
- assert_count_equal (covdata .arcs ("x.py" ), X_PY_ARCS_3 )
85
- assert_count_equal (covdata .lines ("y.py" ), Y_PY_LINES_3 )
86
- assert_count_equal (covdata .arcs ("y.py" ), Y_PY_ARCS_3 )
87
- assert covdata .has_arcs ()
61
+ def assert_line_counts (covdata , counts , fullpath = False ):
62
+ """Check that the line_counts of `covdata` is `counts`."""
63
+ assert line_counts (covdata , fullpath ) == counts
64
+
65
+ def assert_measured_files (covdata , measured ):
66
+ """Check that `covdata`'s measured files are `measured`."""
67
+ assert_count_equal (covdata .measured_files (), measured )
68
+
69
+ def assert_lines1_data (covdata ):
70
+ """Check that `covdata` has the data from LINES1."""
71
+ assert_line_counts (covdata , SUMMARY_1 )
72
+ assert_measured_files (covdata , MEASURED_FILES_1 )
73
+ assert_count_equal (covdata .lines ("a.py" ), A_PY_LINES_1 )
74
+ assert not covdata .has_arcs ()
75
+
76
+ def assert_arcs3_data (covdata ):
77
+ """Check that `covdata` has the data from ARCS3."""
78
+ assert_line_counts (covdata , SUMMARY_3 )
79
+ assert_measured_files (covdata , MEASURED_FILES_3 )
80
+ assert_count_equal (covdata .lines ("x.py" ), X_PY_LINES_3 )
81
+ assert_count_equal (covdata .arcs ("x.py" ), X_PY_ARCS_3 )
82
+ assert_count_equal (covdata .lines ("y.py" ), Y_PY_LINES_3 )
83
+ assert_count_equal (covdata .arcs ("y.py" ), Y_PY_ARCS_3 )
84
+ assert covdata .has_arcs ()
88
85
89
86
90
87
def dicts_from_sets (file_data ):
@@ -97,7 +94,7 @@ def dicts_from_sets(file_data):
97
94
return {k : dict .fromkeys (v ) for k , v in file_data .items ()}
98
95
99
96
100
- class CoverageDataTest (DataTestHelpers , CoverageTest ):
97
+ class CoverageDataTest (CoverageTest ):
101
98
"""Test cases for CoverageData."""
102
99
103
100
def test_empty_data_is_false (self ):
@@ -128,27 +125,27 @@ def test_empty_arc_data_is_false(self):
128
125
def test_adding_lines (self , lines ):
129
126
covdata = CoverageData ()
130
127
covdata .add_lines (lines )
131
- self . assert_lines1_data (covdata )
128
+ assert_lines1_data (covdata )
132
129
133
130
@pytest .mark .parametrize ("arcs" , [ARCS_3 , dicts_from_sets (ARCS_3 )])
134
131
def test_adding_arcs (self , arcs ):
135
132
covdata = CoverageData ()
136
133
covdata .add_arcs (arcs )
137
- self . assert_arcs3_data (covdata )
134
+ assert_arcs3_data (covdata )
138
135
139
136
def test_ok_to_add_lines_twice (self ):
140
137
covdata = CoverageData ()
141
138
covdata .add_lines (LINES_1 )
142
139
covdata .add_lines (LINES_2 )
143
- self . assert_line_counts (covdata , SUMMARY_1_2 )
144
- self . assert_measured_files (covdata , MEASURED_FILES_1_2 )
140
+ assert_line_counts (covdata , SUMMARY_1_2 )
141
+ assert_measured_files (covdata , MEASURED_FILES_1_2 )
145
142
146
143
def test_ok_to_add_arcs_twice (self ):
147
144
covdata = CoverageData ()
148
145
covdata .add_arcs (ARCS_3 )
149
146
covdata .add_arcs (ARCS_4 )
150
- self . assert_line_counts (covdata , SUMMARY_3_4 )
151
- self . assert_measured_files (covdata , MEASURED_FILES_3_4 )
147
+ assert_line_counts (covdata , SUMMARY_3_4 )
148
+ assert_measured_files (covdata , MEASURED_FILES_3_4 )
152
149
153
150
def test_cant_add_arcs_with_lines (self ):
154
151
covdata = CoverageData ()
@@ -168,13 +165,13 @@ def test_touch_file_with_lines(self):
168
165
covdata = CoverageData ()
169
166
covdata .add_lines (LINES_1 )
170
167
covdata .touch_file ('zzz.py' )
171
- self . assert_measured_files (covdata , MEASURED_FILES_1 + ['zzz.py' ])
168
+ assert_measured_files (covdata , MEASURED_FILES_1 + ['zzz.py' ])
172
169
173
170
def test_touch_file_with_arcs (self ):
174
171
covdata = CoverageData ()
175
172
covdata .add_arcs (ARCS_3 )
176
173
covdata .touch_file ('zzz.py' )
177
- self . assert_measured_files (covdata , MEASURED_FILES_3 + ['zzz.py' ])
174
+ assert_measured_files (covdata , MEASURED_FILES_3 + ['zzz.py' ])
178
175
179
176
def test_set_query_contexts (self ):
180
177
covdata = CoverageData ()
@@ -319,8 +316,8 @@ def test_update_lines(self):
319
316
covdata3 .update (covdata1 )
320
317
covdata3 .update (covdata2 )
321
318
322
- self . assert_line_counts (covdata3 , SUMMARY_1_2 )
323
- self . assert_measured_files (covdata3 , MEASURED_FILES_1_2 )
319
+ assert_line_counts (covdata3 , SUMMARY_1_2 )
320
+ assert_measured_files (covdata3 , MEASURED_FILES_1_2 )
324
321
325
322
def test_update_arcs (self ):
326
323
covdata1 = CoverageData (suffix = '1' )
@@ -333,8 +330,8 @@ def test_update_arcs(self):
333
330
covdata3 .update (covdata1 )
334
331
covdata3 .update (covdata2 )
335
332
336
- self . assert_line_counts (covdata3 , SUMMARY_3_4 )
337
- self . assert_measured_files (covdata3 , MEASURED_FILES_3_4 )
333
+ assert_line_counts (covdata3 , SUMMARY_3_4 )
334
+ assert_measured_files (covdata3 , MEASURED_FILES_3_4 )
338
335
339
336
def test_update_cant_mix_lines_and_arcs (self ):
340
337
covdata1 = CoverageData (suffix = '1' )
@@ -421,22 +418,22 @@ def test_update_lines_empty(self):
421
418
422
419
covdata2 = CoverageData (suffix = '2' )
423
420
covdata1 .update (covdata2 )
424
- self . assert_line_counts (covdata1 , SUMMARY_1 )
421
+ assert_line_counts (covdata1 , SUMMARY_1 )
425
422
426
423
def test_update_arcs_empty (self ):
427
424
covdata1 = CoverageData (suffix = '1' )
428
425
covdata1 .add_arcs (ARCS_3 )
429
426
430
427
covdata2 = CoverageData (suffix = '2' )
431
428
covdata1 .update (covdata2 )
432
- self . assert_line_counts (covdata1 , SUMMARY_3 )
429
+ assert_line_counts (covdata1 , SUMMARY_3 )
433
430
434
431
def test_asking_isnt_measuring (self ):
435
432
# Asking about an unmeasured file shouldn't make it seem measured.
436
433
covdata = CoverageData ()
437
- self . assert_measured_files (covdata , [])
434
+ assert_measured_files (covdata , [])
438
435
assert covdata .arcs ("missing.py" ) is None
439
- self . assert_measured_files (covdata , [])
436
+ assert_measured_files (covdata , [])
440
437
441
438
def test_add_to_hash_with_lines (self ):
442
439
covdata = CoverageData ()
@@ -507,7 +504,7 @@ def test_read_and_write_are_opposites(self):
507
504
508
505
covdata2 = CoverageData ()
509
506
covdata2 .read ()
510
- self . assert_arcs3_data (covdata2 )
507
+ assert_arcs3_data (covdata2 )
511
508
512
509
def test_thread_stress (self ):
513
510
covdata = CoverageData ()
@@ -526,11 +523,11 @@ def thread_main():
526
523
for t in threads :
527
524
t .join ()
528
525
529
- self . assert_lines1_data (covdata )
526
+ assert_lines1_data (covdata )
530
527
assert exceptions == []
531
528
532
529
533
- class CoverageDataInTempDirTest (DataTestHelpers , CoverageTest ):
530
+ class CoverageDataInTempDirTest (CoverageTest ):
534
531
"""Tests of CoverageData that need a temporary directory to make files."""
535
532
536
533
def test_read_write_lines (self ):
@@ -540,7 +537,7 @@ def test_read_write_lines(self):
540
537
541
538
covdata2 = CoverageData ("lines.dat" )
542
539
covdata2 .read ()
543
- self . assert_lines1_data (covdata2 )
540
+ assert_lines1_data (covdata2 )
544
541
545
542
def test_read_write_arcs (self ):
546
543
covdata1 = CoverageData ("arcs.dat" )
@@ -549,7 +546,7 @@ def test_read_write_arcs(self):
549
546
550
547
covdata2 = CoverageData ("arcs.dat" )
551
548
covdata2 .read ()
552
- self . assert_arcs3_data (covdata2 )
549
+ assert_arcs3_data (covdata2 )
553
550
554
551
def test_read_errors (self ):
555
552
msg = r"Couldn't .* '.*[/\\]{0}': \S+"
@@ -585,14 +582,14 @@ def test_read_sql_errors(self):
585
582
assert not covdata
586
583
587
584
588
- class CoverageDataFilesTest (DataTestHelpers , CoverageTest ):
585
+ class CoverageDataFilesTest (CoverageTest ):
589
586
"""Tests of CoverageData file handling."""
590
587
591
588
def test_reading_missing (self ):
592
589
self .assert_doesnt_exist (".coverage" )
593
590
covdata = CoverageData ()
594
591
covdata .read ()
595
- self . assert_line_counts (covdata , {})
592
+ assert_line_counts (covdata , {})
596
593
597
594
def test_writing_and_reading (self ):
598
595
covdata1 = CoverageData ()
@@ -601,7 +598,7 @@ def test_writing_and_reading(self):
601
598
602
599
covdata2 = CoverageData ()
603
600
covdata2 .read ()
604
- self . assert_line_counts (covdata2 , SUMMARY_1 )
601
+ assert_line_counts (covdata2 , SUMMARY_1 )
605
602
606
603
def test_debug_output_with_debug_option (self ):
607
604
# With debug option dataio, we get debug output about reading and
@@ -613,7 +610,7 @@ def test_debug_output_with_debug_option(self):
613
610
614
611
covdata2 = CoverageData (debug = debug )
615
612
covdata2 .read ()
616
- self . assert_line_counts (covdata2 , SUMMARY_1 )
613
+ assert_line_counts (covdata2 , SUMMARY_1 )
617
614
618
615
assert re .search (
619
616
r"^Erasing data file '.*\.coverage'\n" +
@@ -632,7 +629,7 @@ def test_debug_output_without_debug_option(self):
632
629
633
630
covdata2 = CoverageData (debug = debug )
634
631
covdata2 .read ()
635
- self . assert_line_counts (covdata2 , SUMMARY_1 )
632
+ assert_line_counts (covdata2 , SUMMARY_1 )
636
633
637
634
assert debug .get_output () == ""
638
635
@@ -683,8 +680,8 @@ def test_combining(self):
683
680
684
681
covdata3 = CoverageData ()
685
682
combine_parallel_data (covdata3 )
686
- self . assert_line_counts (covdata3 , SUMMARY_1_2 )
687
- self . assert_measured_files (covdata3 , MEASURED_FILES_1_2 )
683
+ assert_line_counts (covdata3 , SUMMARY_1_2 )
684
+ assert_measured_files (covdata3 , MEASURED_FILES_1_2 )
688
685
self .assert_file_count (".coverage.*" , 0 )
689
686
690
687
def test_erasing (self ):
@@ -693,11 +690,11 @@ def test_erasing(self):
693
690
covdata1 .write ()
694
691
695
692
covdata1 .erase ()
696
- self . assert_line_counts (covdata1 , {})
693
+ assert_line_counts (covdata1 , {})
697
694
698
695
covdata2 = CoverageData ()
699
696
covdata2 .read ()
700
- self . assert_line_counts (covdata2 , {})
697
+ assert_line_counts (covdata2 , {})
701
698
702
699
def test_erasing_parallel (self ):
703
700
self .make_file ("datafile.1" )
@@ -742,8 +739,8 @@ def test_combining_with_aliases(self):
742
739
sub_bpy = canonical_filename ('./sub/b.py' )
743
740
template_html = canonical_filename ('./template.html' )
744
741
745
- self . assert_line_counts (covdata3 , {apy : 4 , sub_bpy : 2 , template_html : 1 }, fullpath = True )
746
- self . assert_measured_files (covdata3 , [apy , sub_bpy , template_html ])
742
+ assert_line_counts (covdata3 , {apy : 4 , sub_bpy : 2 , template_html : 1 }, fullpath = True )
743
+ assert_measured_files (covdata3 , [apy , sub_bpy , template_html ])
747
744
assert covdata3 .file_tracer (template_html ) == 'html.plugin'
748
745
749
746
def test_combining_from_different_directories (self ):
@@ -765,8 +762,8 @@ def test_combining_from_different_directories(self):
765
762
covdata3 = CoverageData ()
766
763
combine_parallel_data (covdata3 , data_paths = ['cov1' , 'cov2' ])
767
764
768
- self . assert_line_counts (covdata3 , SUMMARY_1_2 )
769
- self . assert_measured_files (covdata3 , MEASURED_FILES_1_2 )
765
+ assert_line_counts (covdata3 , SUMMARY_1_2 )
766
+ assert_measured_files (covdata3 , MEASURED_FILES_1_2 )
770
767
self .assert_doesnt_exist ("cov1/.coverage.1" )
771
768
self .assert_doesnt_exist ("cov2/.coverage.2" )
772
769
self .assert_exists (".coverage.xxx" )
@@ -794,8 +791,8 @@ def test_combining_from_files(self):
794
791
covdata3 = CoverageData ()
795
792
combine_parallel_data (covdata3 , data_paths = ['cov1' , 'cov2/.coverage.2' ])
796
793
797
- self . assert_line_counts (covdata3 , SUMMARY_1_2 )
798
- self . assert_measured_files (covdata3 , MEASURED_FILES_1_2 )
794
+ assert_line_counts (covdata3 , SUMMARY_1_2 )
795
+ assert_measured_files (covdata3 , MEASURED_FILES_1_2 )
799
796
self .assert_doesnt_exist ("cov1/.coverage.1" )
800
797
self .assert_doesnt_exist ("cov2/.coverage.2" )
801
798
self .assert_exists (".coverage.xxx" )
@@ -820,7 +817,7 @@ def test_interleaved_erasing_bug716(self):
820
817
covdata2 .add_lines (LINES_1 )
821
818
822
819
823
- class DumpsLoadsTest (DataTestHelpers , CoverageTest ):
820
+ class DumpsLoadsTest (CoverageTest ):
824
821
"""Tests of CoverageData.dumps and loads."""
825
822
826
823
run_in_temp_dir = False
@@ -833,8 +830,8 @@ def test_serialization(self):
833
830
834
831
covdata2 = CoverageData (no_disk = True )
835
832
covdata2 .loads (serial )
836
- self . assert_line_counts (covdata2 , SUMMARY_1_2 )
837
- self . assert_measured_files (covdata2 , MEASURED_FILES_1_2 )
833
+ assert_line_counts (covdata2 , SUMMARY_1_2 )
834
+ assert_measured_files (covdata2 , MEASURED_FILES_1_2 )
838
835
839
836
def test_misfed_serialization (self ):
840
837
covdata = CoverageData (no_disk = True )
0 commit comments