Ejemplo n.º 1
0
def dump_file(location, content, as_yaml=False):
    '''
    Pickle either *json* or *yaml* into a file

    :param location: path where to pickle into
    :param content: data to store
    :param as_yaml: output as *yaml* instead of *json*
    '''
    with dump_struct(content, as_yaml=as_yaml) as data:
        return write_file(location, data) if (data is not None) else None
Ejemplo n.º 2
0
def dump_file(location, content, as_yaml=False):
    '''
    Pickle either *json* or *yaml* into a file

    :param location: path where to pickle into
    :param content: data to store
    :param as_yaml: output as *yaml* instead of *json*
    '''
    with dump_struct(content, as_yaml=as_yaml) as data:
        return write_file(location, data) if (data is not None) else None
Ejemplo n.º 3
0
def test_dump_struct_wrong_input_data():
    for fj in [range, set, y_dump, j_dump]:
        with dump_struct(fj, as_yaml=False) as t:
            assert t is None
Ejemplo n.º 4
0
def test_dump_struct_yaml():
    for ty in [None, 'a', {'a': None}, {'a': 'b'}, {'a': ['b', 'c']}, range]:
        with dump_struct(ty, as_yaml=True) as t:
            assert t == y_dump(ty, indent=4, default_flow_style=False)
Ejemplo n.º 5
0
def test_dump_struct_json():
    for tj in ['', 'a', {}, {'a': 'b'}]:
        with dump_struct(tj, as_yaml=False) as t:
            assert t == j_dump(tj, indent=2, sort_keys=True)
Ejemplo n.º 6
0
def test_dump_struct_wrong_input_data():
    for fj in [range, set, y_dump, j_dump]:
        with dump_struct(fj, as_yaml=False) as t:
            assert t is None
Ejemplo n.º 7
0
def test_dump_struct_yaml():
    for ty in [None, 'a', {'a': None}, {'a': 'b'}, {'a': ['b', 'c']}, range]:
        with dump_struct(ty, as_yaml=True) as t:
            assert t == y_dump(
                ty, indent=4, default_flow_style=False
            )
Ejemplo n.º 8
0
def test_dump_struct_json():
    for tj in ['', 'a', {}, {'a': 'b'}]:
        with dump_struct(tj, as_yaml=False) as t:
            assert t == j_dump(
                tj, indent=2, sort_keys=True
            )
Ejemplo n.º 9
0
def sdy(cont):
    with dump_struct(cont, as_yaml=True) as res:
        return res
Ejemplo n.º 10
0
def sdj(cont):
    with dump_struct(cont, as_yaml=False) as res:
        return res