@@ -617,6 +617,38 @@ def test_cant_purge_in_empty_data(self) -> None:
617
617
with pytest .raises (DataError , match = msg ):
618
618
covdata .purge_files (["abc.py" ])
619
619
620
+ def test_purge_contexts_lines (self ) -> None :
621
+ covdata = DebugCoverageData ()
622
+ covdata .set_context ('context1' )
623
+ covdata .add_lines (LINES_1 )
624
+ covdata .set_context ('context2' )
625
+ covdata .add_lines (LINES_2 )
626
+ assert_line_counts (covdata , SUMMARY_1_2 )
627
+ covdata .purge_contexts (["context2" ])
628
+ assert_line_counts (covdata , {'a.py' : 2 , 'b.py' : 1 , 'c.py' : 0 })
629
+ covdata .purge_contexts (["context1" ])
630
+ assert_line_counts (covdata , {"a.py" : 0 , "b.py" : 0 , "c.py" : 0 })
631
+ # It's OK to "purge" a context that wasn't measured.
632
+ covdata .purge_contexts (["context3" ])
633
+ assert_line_counts (covdata , {"a.py" : 0 , "b.py" : 0 , "c.py" : 0 })
634
+
635
+ def test_purge_contexts_arcs (self ) -> None :
636
+ covdata = CoverageData ()
637
+ covdata .set_context ('context1' )
638
+ covdata .add_arcs (ARCS_3 )
639
+ covdata .set_context ('context2' )
640
+ covdata .add_arcs (ARCS_4 )
641
+ assert_line_counts (covdata , SUMMARY_3_4 )
642
+ covdata .purge_contexts (["context1" ])
643
+ assert_line_counts (covdata ,{'x.py' : 2 , 'y.py' : 0 , 'z.py' : 1 })
644
+ covdata .purge_contexts (["context2" ])
645
+ assert_line_counts (covdata , {"x.py" : 0 , "y.py" : 0 , "z.py" : 0 })
646
+
647
+ def test_cant_purge_contexts_in_empty_data (self ) -> None :
648
+ covdata = DebugCoverageData ()
649
+ msg = "Can't purge contexts in an empty CoverageData"
650
+ with pytest .raises (DataError , match = msg ):
651
+ covdata .purge_contexts (["context1" ])
620
652
621
653
class CoverageDataInTempDirTest (CoverageTest ):
622
654
"""Tests of CoverageData that need a temporary directory to make files."""
0 commit comments