3535
3636def  data_file_path (filename : str ) ->  str :
3737    path_list  =  []
38-     if  re .match (r"example\.(json|msgpack|toml|yaml|cbor)$" , filename ):
38+     if  re .match (r"example\.(json|msgpack|py| toml|yaml|cbor)$" , filename ):
3939        path_list .append (".." )
4040    path_list .append (filename )
4141    return  str (TEST_PATH .joinpath (* path_list ))
@@ -140,6 +140,14 @@ def convert_and_read(tmp_path):
140140    )
141141
142142
143+ def  patch_date (x : Any ) ->  Any :
144+     x ["owner" ]["dob" ] =  datetime .datetime (
145+         1979 , 5 , 27 , 7 , 32 , 0 , 0 , datetime .timezone .utc 
146+     )
147+ 
148+     return  x 
149+ 
150+ 
143151class  TestRemarshal :
144152    def  test_cbor2cbor (self , convert_and_read ) ->  None :
145153        output  =  convert_and_read ("example.cbor" , "cbor" , "cbor" )
@@ -177,23 +185,16 @@ def test_yaml2yaml(self, convert_and_read) -> None:
177185        assert  output  ==  reference 
178186
179187    def  test_json2cbor (self , convert_and_read ) ->  None :
180-         def  patch (x : Any ) ->  Any :
181-             x ["owner" ]["dob" ] =  datetime .datetime (
182-                 1979 , 5 , 27 , 7 , 32 , 0 , 0 , datetime .timezone .utc 
183-             )
184-             return  x 
185- 
186188        output  =  convert_and_read (
187189            "example.json" ,
188190            "json" ,
189-             "cbor " ,
190-             transform = patch ,
191+             "msgpack " ,
192+             transform = patch_date ,
191193        )
194+         reference  =  read_file ("example.msgpack" )
195+         assert  output  ==  reference 
192196
193-         reference  =  read_file ("example.cbor" )
194-         assert_cbor_same (output , reference )
195- 
196-     def  test_json2msgpack (self , convert_and_read ) ->  None :
197+     def  test_json2python (self , convert_and_read ) ->  None :
197198        def  patch (x : Any ) ->  Any :
198199            x ["owner" ]["dob" ] =  datetime .datetime (
199200                1979 , 5 , 27 , 7 , 32 , tzinfo = datetime .timezone .utc 
@@ -203,10 +204,11 @@ def patch(x: Any) -> Any:
203204        output  =  convert_and_read (
204205            "example.json" ,
205206            "json" ,
206-             "msgpack" ,
207+             "python" ,
208+             indent = Defaults .PYTHON_INDENT ,
207209            transform = patch ,
208210        )
209-         reference  =  read_file ("example.msgpack " )
211+         reference  =  read_file ("example.py " )
210212        assert  output  ==  reference 
211213
212214    def  test_json2toml (self , convert_and_read ) ->  None :
@@ -248,6 +250,13 @@ def test_msgpack2json(self, convert_and_read) -> None:
248250        reference  =  read_file ("example.json" )
249251        assert  output  ==  reference 
250252
253+     def  test_msgpack2python (self , convert_and_read ) ->  None :
254+         output  =  convert_and_read (
255+             "example.msgpack" , "msgpack" , "python" , indent = Defaults .PYTHON_INDENT 
256+         )
257+         reference  =  read_file ("example.py" )
258+         assert  output  ==  reference 
259+ 
251260    def  test_msgpack2toml (self , convert_and_read ) ->  None :
252261        output  =  convert_and_read ("example.msgpack" , "msgpack" , "toml" )
253262        reference  =  read_file ("example.toml" )
@@ -287,6 +296,16 @@ def test_toml2msgpack(self, convert_and_read) -> None:
287296        reference  =  read_file ("example.msgpack" )
288297        assert  output  ==  reference 
289298
299+     def  test_toml2python (self , convert_and_read ) ->  None :
300+         output  =  convert_and_read (
301+             "example.toml" ,
302+             "toml" ,
303+             "python" ,
304+             indent = Defaults .PYTHON_INDENT ,
305+         )
306+         reference  =  read_file ("example.py" )
307+         assert  output  ==  reference 
308+ 
290309    def  test_toml2yaml (self , convert_and_read ) ->  None :
291310        output  =  convert_and_read ("example.toml" , "toml" , "yaml" )
292311        reference  =  read_file ("example.yaml" )
@@ -321,6 +340,17 @@ def test_yaml2msgpack(self, convert_and_read) -> None:
321340        reference  =  read_file ("example.msgpack" )
322341        assert  output  ==  reference 
323342
343+     def  test_yaml2python (self , convert_and_read ) ->  None :
344+         output  =  convert_and_read (
345+             "example.yaml" ,
346+             "yaml" ,
347+             "python" ,
348+             indent = Defaults .PYTHON_INDENT ,
349+             transform = patch_date ,
350+         )
351+         reference  =  read_file ("example.py" )
352+         assert  output  ==  reference 
353+ 
324354    def  test_yaml2toml (self , convert_and_read ) ->  None :
325355        output  =  convert_and_read ("example.yaml" , "yaml" , "toml" )
326356        reference  =  read_file ("example.toml" )
0 commit comments