コード例 #1
0
def test_delete_nested():
    val = loads_roundtrip('{\n'
                          '    a: {\n'
                          '        b: true,\n'
                          '        c: true,\n'
                          '    },\n'
                          '}\n')
    del val['a']['b']
    ret = dumps_roundtrip(val)
    assert ret == ('{\n' '    a: {\n' '        c: true,\n' '    },\n' '}\n')
コード例 #2
0
def test_replace_map_value_top_level():
    val = loads_roundtrip('{\n'
                          '    a: true,  # comment\n'
                          '    b: false,  # comment\n'
                          '}\n')
    val['b'] = None
    ret = dumps_roundtrip(val)
    assert ret == ('{\n'
                   '    a: true,  # comment\n'
                   '    b: null,  # comment\n'
                   '}\n')
コード例 #3
0
def test_replace_list_value_top_level():
    val = loads_roundtrip('[\n'
                          '    true,  # comment\n'
                          '    false,  # comment\n'
                          ']\n')
    val[0] = None
    ret = dumps_roundtrip(val)
    assert ret == ('[\n'
                   '    null,  # comment\n'
                   '    false,  # comment\n'
                   ']\n')
コード例 #4
0
def test_delete_dictionary_key():
    val = loads_roundtrip('{\n'
                          '    # comment documenting a\n'
                          '    a: true,  # comment\n'
                          '    # comment documenting b\n'
                          '    b: false,  # comment\n'
                          '}\n')
    del val['a']
    ret = dumps_roundtrip(val)
    assert ret == ('{\n'
                   '    # comment documenting b\n'
                   '    b: false,  # comment\n'
                   '}\n')
コード例 #5
0
def test_replace_nested_map_value():
    val = loads_roundtrip('{\n'
                          '    a: {\n'
                          '        b: true,  # comment\n'
                          '    },\n'
                          '}\n')
    val['a']['b'] = None
    ret = dumps_roundtrip(val)
    assert ret == ('{\n'
                   '    a: {\n'
                   '        b: null,  # comment\n'
                   '    },\n'
                   '}\n')
コード例 #6
0
def test_replace_key():
    val = loads_roundtrip("{k: 'v'}")
    val['k'].replace_key('new key!')
    ret = dumps_roundtrip(val)
    assert ret == "{'new key!': 'v'}"
コード例 #7
0
def test_replace_float():
    val = loads_roundtrip('true  # comment')
    val.replace_value(5.)
    ret = dumps_roundtrip(val)
    assert ret == '5.0  # comment'
コード例 #8
0
def test_load_dump_roundtrip():
    s = ('{\n' '    true: false,  # comment\n' '}')
    sio = io.StringIO(s)
    assert dumps_roundtrip(load_roundtrip(sio)) == s
コード例 #9
0
def test_replace_string():
    val = loads_roundtrip('true  # comment')
    val.replace_value('ohai')
    ret = dumps_roundtrip(val)
    assert ret == "'ohai'  # comment"
コード例 #10
0
def test_replace_value_new_type():
    val = loads_roundtrip('true  # comment')
    val.replace_value(None)
    ret = dumps_roundtrip(val)
    assert ret == 'null  # comment'
コード例 #11
0
def test_delete_fixup_indent():
    val = loads_roundtrip('[\n' '    true, false,\n' ']')
    del val[0]
    ret = dumps_roundtrip(val)
    assert ret == ('[\n' '    false,\n' ']')
コード例 #12
0
def test_delete_fixup_trailing_space_multiline():
    val = loads_roundtrip('[\n' '    true, false,\n' ']')
    del val[1]
    ret = dumps_roundtrip(val)
    assert ret == ('[\n' '    true,\n' ']')
コード例 #13
0
def test_replace_value_same_type():
    val = loads_roundtrip('true  # comment')
    val.replace_value(False)
    ret = dumps_roundtrip(val)
    assert ret == 'false  # comment'
コード例 #14
0
def test_delete_nested_fixup_trailing_comma_inline():
    val = loads_roundtrip('{a: {b: {c: true, d: false}}}')
    del val['a']['b']['d']
    ret = dumps_roundtrip(val)
    assert ret == '{a: {b: {c: true}}}'
コード例 #15
0
def test_replace_nested_top_level_map():
    val = loads_roundtrip('true: {false: "hello"}\n'
                          'false: {true: "world"}\n')
    val[True][False] = 'goodbye'
    ret = dumps_roundtrip(val)
    assert ret == ("true: {false: 'goodbye'}\n" 'false: {true: "world"}\n')
コード例 #16
0
def test_replace_nested_map_value_deeper():
    val = loads_roundtrip('{a: {b: {c: true}}}')
    val['a']['b']['c'] = False
    ret = dumps_roundtrip(val)
    assert ret == '{a: {b: {c: false}}}'