Exemplo n.º 1
0
def test_known_type_in_wsc_raises_error():
    class Foo:
        ...
    f = Foo()
    model = loads('{foo: "bar"}', loader=ModelLoader())
    model.value.key_value_pairs[0].key.wsc_before.append(f)
    with pytest.raises(ValueError):
        ModelDumper().dump(model)
    model = loads('{foo: "bar"}', loader=ModelLoader())
    model.value.key_value_pairs[0].key.wsc_after.append(f)
    with pytest.raises(ValueError):
        ModelDumper().dump(model)
Exemplo n.º 2
0
def test_hexadecimal_load():
    json_string = """
    {
    positiveHex: 0xdecaf,
    negativeHex: -0xC0FFEE,}"""
    assert dumps(loads(json_string, loader=ModelLoader()),
                 dumper=ModelDumper()) == json_string
Exemplo n.º 3
0
def test_escape_sequences():
    json_string = r"""{
    "foo": "foo\nbar\nbaz",
    "bar": "foo\\bar\\baz",
    "baz": "foo\tbar\tbaz"}"""
    assert dumps(loads(json_string, loader=ModelLoader()),
                 dumper=ModelDumper()) == json_string
Exemplo n.º 4
0
def test_number_literals_inf_nan():
    json_string = """{
    "positiveInfinity": Infinity,
    "negativeInfinity": -Infinity,
    "notANumber": NaN,}"""
    assert dumps(loads(json_string, loader=ModelLoader()),
                 dumper=ModelDumper()) == json_string
Exemplo n.º 5
0
def test_number_literals():
    json_string = """{
    "integer": 123,
    "withFractionPart": 123.456,
    "onlyFractionPart": .456,
    "withExponent": 123e-2}"""
    assert dumps(loads(json_string, loader=ModelLoader()),
                 dumper=ModelDumper()) == json_string
Exemplo n.º 6
0
def test_array_load_with_line_comment():
    json_string = """[ // line comment
    "foo", "bar"
    ]"""
    assert dumps(loads(json_string, loader=ModelLoader()),
                 dumper=ModelDumper()) == json_string
Exemplo n.º 7
0
def test_object_with_multiline_comment():
    json_string = """{ /* foo bar
    */ "foo": "bar" // Foobar
    }"""
    assert dumps(loads(json_string, loader=ModelLoader()),
                 dumper=ModelDumper()) == json_string
Exemplo n.º 8
0
def test_object_load_with_line_comment():
    json_string = """{ // line comment
    "foo": "bar"
    }"""
    assert dumps(loads(json_string, loader=ModelLoader()),
                 dumper=ModelDumper()) == json_string
Exemplo n.º 9
0
def test_round_trip_model_load_dump(json_string):
    assert dumps(loads(json_string, loader=ModelLoader()),
                 dumper=ModelDumper()) == json_string
Exemplo n.º 10
0
def test_line_continuations_alternate_terminators(terminator):
    json_string = f"""'Hello \\{terminator}world!'"""
    assert dumps(loads(json_string, loader=ModelLoader()),
                 dumper=ModelDumper()) == json_string
Exemplo n.º 11
0
def test_escape_sequence_strings():
    json_string = r"""'\A\C\/\D\C'"""
    assert dumps(loads(json_string, loader=ModelLoader()),
                 dumper=ModelDumper()) == json_string
Exemplo n.º 12
0
def test_single_quote_with_escape_single_quote():
    json_string = r"""{'fo\'o': 'bar'}"""
    assert dumps(loads(json_string, loader=ModelLoader()),
                 dumper=ModelDumper()) == json_string
Exemplo n.º 13
0
def test_load_empty_array_with_whitespace():
    json_string = "{   }"
    assert dumps(loads(json_string, loader=ModelLoader()),
                 dumper=ModelDumper()) == json_string
Exemplo n.º 14
0
def test_empty_array():
    json_string = "[]"
    assert dumps(loads(json_string, loader=ModelLoader()),
                 dumper=ModelDumper()) == json_string
Exemplo n.º 15
0
def test_empty_object():
    json_string = "{}"
    assert dumps(loads(json_string, loader=ModelLoader()),
                 dumper=ModelDumper()) == json_string
Exemplo n.º 16
0
def test_array_with_multiline_comment():
    json_string = """[ /* foo bar
    */ "foo", "bar"
    ]"""
    assert dumps(loads(json_string, loader=ModelLoader()),
                 dumper=ModelDumper()) == json_string
Exemplo n.º 17
0
def test_nested_object():
    json_string = """{"foo": {"bacon": "eggs"}}"""
    assert dumps(loads(json_string, loader=ModelLoader()),
                 dumper=ModelDumper()) == json_string
Exemplo n.º 18
0
def test_load_empty_object_wtih_whitespace():
    json_string = "[   ]"
    assert dumps(loads(json_string, loader=ModelLoader()),
                 dumper=ModelDumper()) == json_string
Exemplo n.º 19
0
def test_double_quote_with_escape_double_quote():
    json_string = r"""{"fo\"o": "bar"}"""
    assert dumps(loads(json_string, loader=ModelLoader()),
                 dumper=ModelDumper()) == json_string
Exemplo n.º 20
0
def test_load_empty_object_with_comments():
    json_string = "{ // foo \n}"
    assert dumps(loads(json_string, loader=ModelLoader()),
                 dumper=ModelDumper()) == json_string
Exemplo n.º 21
0
def test_line_continuations():
    json_string = r"""'Hello \
world!'"""
    assert dumps(loads(json_string, loader=ModelLoader()),
                 dumper=ModelDumper()) == json_string
Exemplo n.º 22
0
def test_load_empty_array_with_comments():
    json_string = "[ // foo \n]"
    assert dumps(loads(json_string, loader=ModelLoader()),
                 dumper=ModelDumper()) == json_string