@@ -64,6 +64,10 @@ def test_extracted_value_error():
6464
6565def test_partial_array ():
6666 json = b'["string", true, null, 1, "foo'
67+
68+ with pytest .raises (ValueError , match = 'EOF while parsing a string at line 1 column 30' ):
69+ jiter .from_json (json , partial_mode = False )
70+
6771 parsed = jiter .from_json (json , partial_mode = True )
6872 assert parsed == ["string" , True , None , 1 ]
6973
@@ -150,6 +154,21 @@ def test_partial_nested():
150154 assert isinstance (parsed , dict )
151155
152156
157+ def test_partial_error ():
158+ json = b'["string", true, null, 1, "foo'
159+
160+ with pytest .raises (ValueError , match = 'EOF while parsing a string at line 1 column 30' ):
161+ jiter .from_json (json , partial_mode = False )
162+
163+ assert jiter .from_json (json , partial_mode = True ) == ["string" , True , None , 1 ]
164+
165+ msg = "Invalid partial mode, should be `'off'`, `'on'`, `'trailing-strings'` or a `bool`"
166+ with pytest .raises (ValueError , match = msg ):
167+ jiter .from_json (json , partial_mode = 'wrong' )
168+ with pytest .raises (TypeError , match = msg ):
169+ jiter .from_json (json , partial_mode = 123 )
170+
171+
153172def test_python_cache_usage_all ():
154173 jiter .cache_clear ()
155174 parsed = jiter .from_json (b'{"foo": "bar", "spam": 3}' , cache_mode = "all" )
@@ -254,3 +273,13 @@ def test_unicode_roundtrip_ensure_ascii():
254273 json_data = json .dumps (original , ensure_ascii = False ).encode ()
255274 assert jiter .from_json (json_data , cache_mode = False ) == original
256275 assert json .loads (json_data ) == original
276+
277+
278+ def test_catch_duplicate_keys ():
279+ assert jiter .from_json (b'{"foo": 1, "foo": 2}' ) == {"foo" : 2 }
280+
281+ with pytest .raises (ValueError , match = 'Detected duplicate key "foo" at line 1 column 18' ):
282+ jiter .from_json (b'{"foo": 1, "foo": 2}' , catch_duplicate_keys = True )
283+
284+ with pytest .raises (ValueError , match = 'Detected duplicate key "foo" at line 1 column 28' ):
285+ jiter .from_json (b'{"foo": 1, "bar": 2, "foo": 2}' , catch_duplicate_keys = True )
0 commit comments