Ejemplo n.º 1
0
def test_stcsave_list_to_string():
    src = [1, 2, 3, 4, 5]
    res = dm_utils.stcsave_list_to_string(src)
    assert "1 2 3 4 5" == res
    src = ["something", "", "a space", "thanks"]
    res = dm_utils.stcsave_list_to_string(src)
    assert "something {} {a space} thanks" == res
    # This is the non-recoverable case where a collection has braces
    src = ['{"key" : "value"}', "json}", "yucky"]
    res = dm_utils.stcsave_list_to_string(src)
    assert '{{"key" : "value"}} json} yucky' == res
def get_prop_val_lists(src_dict, prefix=None):
    '''
    Return the property value lists as expected. The output is usable directly
    in an STC XML save file, meaning the string value is properly formatted
    for a collection property as used in XML (including the errors we have
    with braces)
    '''
    if prefix is None:
        prefix = ''
    else:
        prefix = prefix + '.'
    prop_list = [prefix + k for k in src_dict.keys()]
    val_list = [v if not isinstance(v, collections.Sequence) or
                isinstance(v, str)
                else dm_utils.stcsave_list_to_string(v)
                for v in src_dict.values()]
    return prop_list, val_list