1313# limitations under the License.
1414
1515import yaml
16+ import pytest
1617from garf_core import query_editor
1718from garf_executors .execution_context import ExecutionContext
1819
@@ -80,4 +81,51 @@ def test_save_returns_correct_data(self, tmp_path):
8081 context .save (tmp_config )
8182 with open (tmp_config , 'r' , encoding = 'utf-8' ) as f :
8283 config_data = yaml .safe_load (f )
83- assert config_data == data
84+ # Check that the data is saved correctly without extra fields
85+ assert config_data ['writer' ] == data ['writer' ]
86+ assert config_data ['writer_parameters' ] == data ['writer_parameters' ]
87+
88+ def test_multiple_writers_creates_multiple_clients (self , tmp_path ):
89+ context = ExecutionContext (
90+ writer = ['console' , 'json' ],
91+ writer_parameters = {'destination_folder' : str (tmp_path )},
92+ )
93+ writer_clients = context .writer_clients
94+ assert len (writer_clients ) == 2
95+ assert writer_clients [0 ].__class__ .__name__ == 'ConsoleWriter'
96+ assert writer_clients [1 ].__class__ .__name__ == 'JsonWriter'
97+
98+ def test_multiple_writers_without_parameters_creates_empty_dicts (self ):
99+ context = ExecutionContext (
100+ writer = ['console' , 'json' ],
101+ )
102+ writer_clients = context .writer_clients
103+ assert len (writer_clients ) == 2
104+
105+ def test_backward_compatibility_single_writer_still_works (self , tmp_path ):
106+ context = ExecutionContext (
107+ writer = 'json' ,
108+ writer_parameters = {'destination_folder' : str (tmp_path )},
109+ )
110+ # Should work with writer_client property
111+ writer_client = context .writer_client
112+ assert writer_client .__class__ .__name__ == 'JsonWriter'
113+ # Should also work with writer_clients property
114+ writer_clients = context .writer_clients
115+ assert len (writer_clients ) == 1
116+ assert writer_clients [0 ].__class__ .__name__ == 'JsonWriter'
117+
118+
119+ def test_from_file_with_multiple_writers (self , tmp_path ):
120+ tmp_config = tmp_path / 'config.yaml'
121+ data = {
122+ 'writer' : ['console' , 'json' ],
123+ 'writer_parameters' : {
124+ 'destination_folder' : '/tmp' ,
125+ },
126+ }
127+ with open (tmp_config , 'w' , encoding = 'utf-8' ) as f :
128+ yaml .dump (data , f , encoding = 'utf-8' )
129+ context = ExecutionContext .from_file (tmp_config )
130+ assert context .writer == ['console' , 'json' ]
131+ assert len (context .writer_clients ) == 2
0 commit comments