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
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
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)
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)
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 )
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 )
def sdy(cont): with dump_struct(cont, as_yaml=True) as res: return res
def sdj(cont): with dump_struct(cont, as_yaml=False) as res: return res