From bc35e7f94e211ce753ed4eef0ffbb30ad1fbaeb4 Mon Sep 17 00:00:00 2001 From: Florian Zimmermann Date: Wed, 7 Aug 2024 16:28:29 +0200 Subject: [PATCH] fix assertion for badly formed JSON input on Python 3.13 --- graphene/types/tests/test_json.py | 39 ++++++++++++++----------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/graphene/types/tests/test_json.py b/graphene/types/tests/test_json.py index bb754b3a..0d4ae7a6 100644 --- a/graphene/types/tests/test_json.py +++ b/graphene/types/tests/test_json.py @@ -51,35 +51,30 @@ def test_jsonstring_invalid_query(): Test that if an invalid type is provided we get an error """ result = schema.execute("{ json(input: 1) }") - assert result.errors - assert len(result.errors) == 1 - assert result.errors[0].message == "Expected value of type 'JSONString', found 1." + assert result.errors == [ + {"message": "Expected value of type 'JSONString', found 1."}, + ] result = schema.execute("{ json(input: {}) }") - assert result.errors - assert len(result.errors) == 1 - assert result.errors[0].message == "Expected value of type 'JSONString', found {}." + assert result.errors == [ + {"message": "Expected value of type 'JSONString', found {}."}, + ] result = schema.execute('{ json(input: "a") }') - assert result.errors - assert len(result.errors) == 1 - assert result.errors[0].message == ( - "Expected value of type 'JSONString', found \"a\"; " - "Badly formed JSONString: Expecting value: line 1 column 1 (char 0)" - ) + assert result.errors == [ + { + "message": "Expected value of type 'JSONString', found \"a\"; " + "Badly formed JSONString: Expecting value: line 1 column 1 (char 0)", + }, + ] result = schema.execute("""{ json(input: "{\\'key\\': 0}") }""") - assert result.errors - assert len(result.errors) == 1 - assert ( - result.errors[0].message - == "Syntax Error: Invalid character escape sequence: '\\''." - ) + assert result.errors == [ + {"message": "Syntax Error: Invalid character escape sequence: '\\''."}, + ] result = schema.execute("""{ json(input: "{\\"key\\": 0,}") }""") - assert result.errors assert len(result.errors) == 1 - assert result.errors[0].message == ( - 'Expected value of type \'JSONString\', found "{\\"key\\": 0,}"; ' - "Badly formed JSONString: Expecting property name enclosed in double quotes: line 1 column 11 (char 10)" + assert result.errors[0].message.startswith( + 'Expected value of type \'JSONString\', found "{\\"key\\": 0,}"; Badly formed JSONString:' )