@@ -842,3 +842,61 @@ def test_avro_type_none(self):
842842 def test_avro_type_string (self ):
843843 from datamorph .converters import _avro_type
844844 assert _avro_type ("hello" ) == "string"
845+
846+
847+ class TestScalarJsonRootAndRowsRead :
848+ """Coverage for scalar/bare JSON roots and the previously-unpopulated rows_read."""
849+
850+ def test_rows_read_dict_root (self , tmp_path ):
851+ inp = tmp_path / "in.json"
852+ out = tmp_path / "out.json"
853+ inp .write_text (json .dumps ({"a" : 1 , "b" : 2 }), encoding = "utf-8" )
854+ result = convert (inp , out , input_format = "json" , output_format = "json" )
855+ assert result .rows_read == 1
856+ assert result .rows_written == 1
857+ assert json .loads (out .read_text (encoding = "utf-8" )) == [{"a" : 1 , "b" : 2 }]
858+
859+ def test_rows_read_list_root (self , tmp_path ):
860+ inp = tmp_path / "in.json"
861+ out = tmp_path / "out.json"
862+ inp .write_text (json .dumps ([{"a" : 1 }, {"a" : 2 }]), encoding = "utf-8" )
863+ result = convert (inp , out , input_format = "json" , output_format = "json" )
864+ assert result .rows_read == 2
865+ assert result .rows_written == 2
866+ assert json .loads (out .read_text (encoding = "utf-8" )) == [{"a" : 1 }, {"a" : 2 }]
867+
868+ def test_scalar_string_root_round_trip (self , tmp_path ):
869+ inp = tmp_path / "in.json"
870+ out = tmp_path / "out.json"
871+ inp .write_text ('"hello world"' , encoding = "utf-8" )
872+ result = convert (inp , out , input_format = "json" , output_format = "json" )
873+ assert result .rows_read == 1
874+ assert result .rows_written == 1
875+ assert json .loads (out .read_text (encoding = "utf-8" )) == [{"data" : "hello world" }]
876+
877+ def test_scalar_number_root_round_trip (self , tmp_path ):
878+ inp = tmp_path / "in.json"
879+ out = tmp_path / "out.json"
880+ inp .write_text ("42" , encoding = "utf-8" )
881+ result = convert (inp , out , input_format = "json" , output_format = "json" )
882+ assert result .rows_read == 1
883+ assert result .rows_written == 1
884+ assert json .loads (out .read_text (encoding = "utf-8" )) == [{"data" : 42 }]
885+
886+ def test_scalar_null_root_round_trip (self , tmp_path ):
887+ inp = tmp_path / "in.json"
888+ out = tmp_path / "out.json"
889+ inp .write_text ("null" , encoding = "utf-8" )
890+ result = convert (inp , out , input_format = "json" , output_format = "json" )
891+ assert result .rows_read == 1
892+ assert result .rows_written == 1
893+ assert json .loads (out .read_text (encoding = "utf-8" )) == [{"data" : None }]
894+
895+ def test_scalar_bool_root_round_trip (self , tmp_path ):
896+ inp = tmp_path / "in.json"
897+ out = tmp_path / "out.json"
898+ inp .write_text ("true" , encoding = "utf-8" )
899+ result = convert (inp , out , input_format = "json" , output_format = "json" )
900+ assert result .rows_read == 1
901+ assert result .rows_written == 1
902+ assert json .loads (out .read_text (encoding = "utf-8" )) == [{"data" : True }]
0 commit comments