22import os
33from io import StringIO
44from pathlib import Path
5- from unittest import TestCase
5+ from unittest import TestCase , mock
66from unittest .mock import patch
77
88from mlx .warnings import WarningsPlugin , warnings_wrapper
@@ -19,19 +19,12 @@ def ordered(obj):
1919 else :
2020 return obj
2121
22-
22+ @ mock . patch . dict ( os . environ , { "MIN_COV_WARNINGS" : "1" , "MAX_COV_WARNINGS" : "2" })
2323class TestCoverityWarnings (TestCase ):
2424 def setUp (self ):
25- os .environ ["MIN_COV_WARNINGS" ] = "1"
26- os .environ ["MAX_COV_WARNINGS" ] = "2"
2725 self .warnings = WarningsPlugin (verbose = True )
2826 self .warnings .activate_checker_name ('coverity' )
2927
30- def tearDown (self ):
31- for var in ('MIN_POLY_WARNINGS' , 'MAX_POLY_WARNINGS' ):
32- if var in os .environ :
33- del os .environ [var ]
34-
3528 def test_no_warning_normal_text (self ):
3629 dut = 'This should not be treated as warning'
3730 self .warnings .check (dut )
@@ -79,9 +72,9 @@ def test_code_quality_without_config(self):
7972 str (TEST_IN_DIR / 'defects.txt' ),
8073 ])
8174 self .assertEqual (8 , retval )
82- with open (out_file ) as file :
75+ with open (out_file ) as file :
8376 cq_out = json .load (file )
84- with open (ref_file ) as file :
77+ with open (ref_file ) as file :
8578 cq_ref = json .load (file )
8679 self .assertEqual (ordered (cq_out ), ordered (cq_ref ))
8780
@@ -95,8 +88,8 @@ def test_code_quality_with_config(self):
9588 str (TEST_IN_DIR / 'defects.txt' ),
9689 ])
9790 self .assertEqual (3 , retval )
98- with open (out_file ) as file :
91+ with open (out_file ) as file :
9992 cq_out = json .load (file )
100- with open (ref_file ) as file :
93+ with open (ref_file ) as file :
10194 cq_ref = json .load (file )
10295 self .assertEqual (ordered (cq_out ), ordered (cq_ref ))
0 commit comments