33from pathlib import Path
44from zipfile import ZipFile
55
6- from spark_log_parser . eventlog import EventLogBuilder
6+ from spark_log_parser import eventlog , extractor
77
88
99class BadEventLog (unittest .TestCase ):
10- def test_multiple_context_ids (self ):
11- event_log = Path ("tests" , "logs" , "bad" , "non-unique-context-id.zip" ).resolve ()
10+ def check_value_error (self , event_log_path , msg ):
1211
1312 with tempfile .TemporaryDirectory () as temp_dir :
14- with self .assertRaises (
15- ValueError , msg = "Not all rollover files have the same Spark context ID"
16- ):
17- EventLogBuilder (event_log .as_uri (), temp_dir ).build ()
13+ with self .assertRaises (ValueError ) as cm :
14+
15+ event_log_paths = extractor .Extractor (event_log_path .as_uri (), temp_dir ).extract ()
16+ eventlog .EventLogBuilder (event_log_paths , temp_dir ).build ()
17+
18+ assert str (cm .exception ) == msg # , "Exception message matches"
19+
20+ def test_multiple_context_ids (self ):
21+ event_log = Path ("tests" , "logs" , "bad" , "non-unique-context-id.zip" ).resolve ()
22+ self .check_value_error (
23+ event_log , "Not all rollover log files have the same Spark context ID"
24+ )
1825
1926 def test_missing_dbc_event (self ):
2027 event_log = Path ("tests" , "logs" , "bad" , "missing-dbc-event.zip" ).resolve ()
21-
22- with tempfile .TemporaryDirectory () as temp_dir :
23- with self .assertRaises (ValueError , msg = "Expected DBC event not found" ):
24- EventLogBuilder (event_log .as_uri (), temp_dir ).build ()
28+ self .check_value_error (event_log , "No rollover properties found in log file" )
2529
2630 def test_duplicate_log_part (self ):
2731 event_log = Path ("tests" , "logs" , "bad" , "duplicate-part.tgz" ).resolve ()
28-
29- with tempfile .TemporaryDirectory () as temp_dir :
30- with self .assertRaises (ValueError , msg = "Duplicate rollover file detected" ):
31- EventLogBuilder (event_log .as_uri (), temp_dir ).build ()
32+ self .check_value_error (event_log , "Duplicate rollover log file detected" )
3233
3334 def test_missing_log_part (self ):
3435 event_log = Path ("tests" , "logs" , "bad" , "missing-part.zip" ).resolve ()
35-
36- with tempfile .TemporaryDirectory () as temp_dir :
37- with self .assertRaises (ValueError , msg = "Rollover file appears to be missing" ):
38- EventLogBuilder (event_log .as_uri (), temp_dir ).build ()
36+ self .check_value_error (event_log , "Rollover log file appears to be missing" )
3937
4038 def test_missing_first_part (self ):
4139 event_log = Path ("tests" , "logs" , "bad" , "missing-first-part.zip" ).resolve ()
42-
43- with tempfile .TemporaryDirectory () as temp_dir :
44- with self .assertRaises (ValueError , msg = "Rollover file appears to be missing" ):
45- EventLogBuilder (event_log .as_uri (), temp_dir ).build ()
40+ self .check_value_error (event_log , "Rollover log file appears to be missing" )
4641
4742 def test_only_non_first_part (self ):
4843 with tempfile .TemporaryDirectory () as temp_dir :
@@ -51,10 +46,8 @@ def test_only_non_first_part(self):
5146 [zinfo for zinfo in zfile .infolist () if not zinfo .is_dir ()][0 ], temp_dir
5247 )
5348
54- with self .assertRaises (ValueError , msg = "Rollover file appears to be missing" ):
55- EventLogBuilder (Path (temp_dir ).as_uri (), temp_dir ).build ()
49+ self .check_value_error (Path (temp_dir ), "Rollover log file appears to be missing" )
5650
5751 def test_empty_log_dir (self ):
5852 with tempfile .TemporaryDirectory () as temp_dir :
59- with self .assertRaises (ValueError , msg = "No log files found" ):
60- EventLogBuilder (Path (temp_dir ).as_uri (), temp_dir ).build ()
53+ self .check_value_error (Path (temp_dir ), "No files found" )
0 commit comments