@@ -30,10 +30,10 @@ def sample_geojson():
3030 "properties" : {
3131 "string" : "string" ,
3232 "int" : 42 ,
33- # "int2": -101,
33+ "int2" : - 101 ,
3434 "double" : 3.141592653 ,
3535 "list" : ["a" , "list" , "is" , "a" , "list" ],
36- # "dict": {"key": 42, "value": 3.14},
36+ "dict" : {"key" : 42 , "value" : 3.14 },
3737 },
3838 "geometry" : {
3939 "coordinates" : [
@@ -97,6 +97,12 @@ def test_rapidjson_empty():
9797 assert rapidjson ([4 , 2 ]).clear () != rapidjson ({})
9898 assert rapidjson ({"key" : "value" }).clear () == rapidjson ({})
9999
100+ obj1 = rapidjson ({"k1" : 1 , "k2" : 2 })
101+ obj2 = rapidjson ({"k2" : 2 , "k1" : 1 })
102+ assert obj1 == obj2
103+ assert list (obj1 .keys ()) == ["k1" , "k2" ]
104+ assert list (obj2 .keys ()) == ["k2" , "k1" ]
105+
100106
101107def test_rapidjson_arr ():
102108 arr = rapidjson ([1 , 3 , "text" , {"key" : 3.2 }])
@@ -924,8 +930,10 @@ def test_geobuf_from_geojson():
924930 decoded_again = Decoder ().decode (
925931 Encoder (max_precision = int (10 ** 8 )).encode (decoded )
926932 )
927- assert decoded_again == decoded
928- assert decoded_again == Decoder ().decode (encoded )
933+ assert rapidjson ().loads (decoded_again ) == rapidjson ().loads (decoded )
934+ assert rapidjson ().loads (decoded_again ) == rapidjson ().loads (
935+ Decoder ().decode (encoded )
936+ )
929937
930938 j = Decoder ().decode_to_rapidjson (encoded )
931939 g = Decoder ().decode_to_geojson (encoded )
@@ -1008,19 +1016,19 @@ def test_geojson_feature():
10081016 props = feature .properties ()
10091017 assert not isinstance (props , dict )
10101018 assert isinstance (props , geojson .value .object_type )
1011- # assert (
1012- # props.to_rapidjson().sort_keys().dumps()
1013- # == '{"dict":{"key":42,"value":3.14},"double":3.141592653,"int":42,"int2":-101,"list":["a","list","is","a","list"],"string":"string"}' # noqa
1014- # )
1015-
1016- # assert set(props.keys()) == {
1017- # # "dict",
1018- # "double",
1019- # "int",
1020- # # "int2",
1021- # "list",
1022- # "string",
1023- # }
1019+ assert (
1020+ props .to_rapidjson ().sort_keys ().dumps ()
1021+ == '{"dict":{"key":42,"value":3.14},"double":3.141592653,"int":42,"int2":-101,"list":["a","list","is","a","list"],"string":"string"}' # noqa
1022+ )
1023+
1024+ assert set (props .keys ()) == {
1025+ "dict" ,
1026+ "double" ,
1027+ "int" ,
1028+ "int2" ,
1029+ "list" ,
1030+ "string" ,
1031+ }
10241032 keys = list (props .keys ())
10251033 values = list (props .values ())
10261034 for i , (k , v ) in enumerate (props .items ()):
@@ -1039,21 +1047,21 @@ def test_geojson_feature():
10391047 assert props ["list" ]() == ["a" , "list" , "is" , "a" , "list" ]
10401048 assert props ["list" ].as_array ()() == ["a" , "list" , "is" , "a" , "list" ]
10411049
1042- # assert props["dict"].is_object()
1043- # for k, v in props["dict"].as_object().items():
1044- # assert isinstance(k, str)
1045- # assert isinstance(v, geojson.value)
1046- # assert type(x) == geojson.value
1047- # with pytest.raises(RuntimeError) as excinfo:
1048- # props["dict"].as_array()
1049- # assert "in get<T>()" in repr(excinfo)
1050- # assert props["dict"]() == {"key": 42, "value": 3.14}
1051- # assert props["dict"].as_object()() == {"key": 42, "value": 3.14}
1052- # assert list(props["dict"].keys()) in [
1053- # # order no guarantee (rapidjson has order, value(unordered_map) not)
1054- # ["key", "value"],
1055- # ["value", "key"],
1056- # ]
1050+ assert props ["dict" ].is_object ()
1051+ for k , v in props ["dict" ].as_object ().items ():
1052+ assert isinstance (k , str )
1053+ assert isinstance (v , geojson .value )
1054+ assert type (x ) == geojson .value
1055+ with pytest .raises (RuntimeError ) as excinfo :
1056+ props ["dict" ].as_array ()
1057+ assert "in get<T>()" in repr (excinfo )
1058+ assert props ["dict" ]() == {"key" : 42 , "value" : 3.14 }
1059+ assert props ["dict" ].as_object ()() == {"key" : 42 , "value" : 3.14 }
1060+ assert list (props ["dict" ].keys ()) in [
1061+ # order no guarantee (rapidjson has order, value(unordered_map) not)
1062+ ["key" , "value" ],
1063+ ["value" , "key" ],
1064+ ]
10571065
10581066 d = props ["double" ]
10591067 assert d .GetType () == "double"
@@ -1072,13 +1080,13 @@ def test_geojson_feature():
10721080 i .GetInt64 ()
10731081 assert "in get<T>()" in repr (excinfo )
10741082
1075- # i = props["int2"]
1076- # assert i.GetType() == "int64_t"
1077- # assert i.GetInt64() == -101
1078- # assert isinstance(i.GetInt64(), int)
1079- # with pytest.raises(RuntimeError) as excinfo:
1080- # i.GetUint64()
1081- # assert "in get<T>()" in repr(excinfo)
1083+ i = props ["int2" ]
1084+ assert i .GetType () == "int64_t"
1085+ assert i .GetInt64 () == - 101
1086+ assert isinstance (i .GetInt64 (), int )
1087+ with pytest .raises (RuntimeError ) as excinfo :
1088+ i .GetUint64 ()
1089+ assert "in get<T>()" in repr (excinfo )
10821090
10831091 props ["new" ] = 6
10841092 assert props ["new" ]() == 6
0 commit comments