示例#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}}}'