@@ -101,6 +101,37 @@ def test_write_yaml_append(self, tmp_path):
101101 expected_data = {** data1 , ** data2 }
102102 assert loaded_data == expected_data
103103
104+ def test_write_zipped_dataframes (self , tmp_path ):
105+ """Test the `write_zipped_dataframes` method."""
106+ # Setup
107+ base_path = tmp_path / 'sdgym_results'
108+ base_path .mkdir (parents = True , exist_ok = True )
109+ result_writer = LocalResultsWriter ()
110+ file_path = base_path / 'data.zip'
111+
112+ data = {
113+ 'table1' : pd .DataFrame ({'a' : [1 , 2 ], 'b' : [3 , 4 ]}),
114+ 'table2' : pd .DataFrame ({'x' : [5 , 6 ], 'y' : [7 , 8 ]}),
115+ }
116+
117+ # Run
118+ result_writer .write_zipped_dataframes (data , file_path )
119+
120+ # Assert
121+ assert file_path .exists ()
122+
123+ with zipfile .ZipFile (file_path , 'r' ) as zf :
124+ # Check that all tables are present
125+ names = zf .namelist ()
126+ assert 'table1.csv' in names
127+ assert 'table2.csv' in names
128+
129+ # Check each table content matches the original
130+ for table_name , df in data .items ():
131+ with zf .open (f'{ table_name } .csv' ) as f :
132+ loaded_df = pd .read_csv (f )
133+ pd .testing .assert_frame_equal (df , loaded_df )
134+
104135
105136class TestS3ResultsWriter :
106137 def test__init__ (self ):
@@ -225,34 +256,3 @@ def test_write_yaml_append(self, mockparse_s3_path):
225256 Bucket = 'bucket_name' ,
226257 Key = 'key_prefix/test_data.yaml' ,
227258 )
228-
229- def test_write_zipped_dataframes (self , tmp_path ):
230- """Test the `write_zipped_dataframes` method."""
231- # Setup
232- base_path = tmp_path / 'sdgym_results'
233- base_path .mkdir (parents = True , exist_ok = True )
234- result_writer = LocalResultsWriter ()
235- file_path = base_path / 'data.zip'
236-
237- data = {
238- 'table1' : pd .DataFrame ({'a' : [1 , 2 ], 'b' : [3 , 4 ]}),
239- 'table2' : pd .DataFrame ({'x' : [5 , 6 ], 'y' : [7 , 8 ]}),
240- }
241-
242- # Run
243- result_writer .write_zipped_dataframes (data , file_path )
244-
245- # Assert
246- assert file_path .exists ()
247-
248- with zipfile .ZipFile (file_path , 'r' ) as zf :
249- # Check that all tables are present
250- names = zf .namelist ()
251- assert 'table1.csv' in names
252- assert 'table2.csv' in names
253-
254- # Check each table content matches the original
255- for table_name , df in data .items ():
256- with zf .open (f'{ table_name } .csv' ) as f :
257- loaded_df = pd .read_csv (f )
258- pd .testing .assert_frame_equal (df , loaded_df )
0 commit comments