alessandro trinca tornidor commited on
Commit
8e595ef
·
1 Parent(s): 5a21e22

feat: add utility function get_cosmic_ray_report_filtered() to filter cosmic-ray reports from KILLED mutant tests

Browse files
aip_trainer/utils/split_cosmic_ray_report.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from pathlib import Path
2
+
3
+
4
+ def get_cosmic_ray_report_filtered(input_filename, suffix="filtered", separator="============", filter_string="test outcome: TestOutcome.KILLED"):
5
+ filename, ext = Path(input_filename).stem, Path(input_filename).suffix
6
+ working_dir = input_filename.parent
7
+ # Read the input file
8
+ with open(input_filename, 'r') as file:
9
+ content = file.read()
10
+
11
+ # Split the content into sections
12
+ sections = content.split(separator)
13
+
14
+ # Filter out sections containing "test outcome: TestOutcome.KILLED"
15
+ filtered_sections = [section for section in sections if filter_string not in section]
16
+
17
+ # Join the filtered sections back into a single string
18
+ filtered_content = separator.join(filtered_sections)
19
+
20
+ # Write the filtered content to a new file
21
+ with open(working_dir / f'{filename}_{suffix}{ext}', 'w') as file:
22
+ file.write(filtered_content)
23
+
24
+
25
+
26
+ if __name__ == "__main__":
27
+ from aip_trainer import PROJECT_ROOT_FOLDER
28
+ _input_filename = "cosmic-ray-lambdagetsample4.txt"
29
+ get_cosmic_ray_report_filtered(PROJECT_ROOT_FOLDER / "tmp" / _input_filename)
tests/events/cosmic-ray-lambdagetsample.txt ADDED
The diff for this file is too large to render. See raw diff
 
tests/utils/test_split_cosmic_ray_report.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import unittest
2
+ from pathlib import Path
3
+ from aip_trainer.utils.split_cosmic_ray_report import get_cosmic_ray_report_filtered
4
+ from aip_trainer.utils import utilities
5
+ from tests import EVENTS_FOLDER
6
+
7
+
8
+ class TestSplitCosmicRayReport(unittest.TestCase):
9
+ def test_get_cosmic_ray_report_filtered(self):
10
+ input_filename = EVENTS_FOLDER / "cosmic-ray-lambdagetsample.txt"
11
+ output_filename = EVENTS_FOLDER / f"{input_filename.stem}_filtered{input_filename.suffix}"
12
+ self.assertFalse(output_filename.exists())
13
+ get_cosmic_ray_report_filtered(input_filename, separator="============", filter_string="test outcome: TestOutcome.KILLED")
14
+
15
+ # Check if the filtered file is created
16
+ self.assertTrue(output_filename.exists() and output_filename.is_file())
17
+
18
+ # Verify the filtered content
19
+ hash_output = utilities.hash_calculate(output_filename, True)
20
+ self.assertEqual(hash_output, b'HqzO5Hq50Z1CIz/8rGE8Hpt4wSRM5Xm86pv+9FOYbUg=')
21
+
22
+ output_filename.unlink(missing_ok=False)
23
+
24
+
25
+ if __name__ == "__main__":
26
+ unittest.main()