Пример #1
0
def test_write_yaml(tmpdir):
    yaml_out = Path(tmpdir).joinpath("yaml_out.yaml")

    save(TEST_FILE_CONTENTS, yaml_out)
    yaml_data = load(yaml_out)

    assert TEST_FILE_CONTENTS == yaml_data
Пример #2
0
def test_write_pickle(tmpdir):
    pickle_out = Path(tmpdir).joinpath("pickle_out.pickle")

    save(TEST_FILE_CONTENTS, pickle_out)
    pickle_data = load(pickle_out)

    assert TEST_FILE_CONTENTS == pickle_data
Пример #3
0
 def from_file(cls, filename):
     filename = existing_path(filename).as_posix()
     if filename.endswith(".py"):
         module_name = osp.basename(filename)[:-3]
         if "." in module_name:
             raise ValueError("Dots are not allowed in config file path.")
         config_dir = osp.dirname(filename)
         sys.path.insert(0, config_dir)
         mod = import_module(module_name)
         sys.path.pop(0)
         cfg_dict = {
             name: value
             for name, value in mod.__dict__.items()
             if not name.startswith("_") or name == "required"
         }
     else:
         cfg_dict = load(filename)
     return cls(cfg_dict, filename=filename)
Пример #4
0
def test_read_yaml(get_asset):
    yaml_file = get_asset("yaml_file.yaml")

    yaml_data = load(yaml_file)

    assert TEST_FILE_CONTENTS == yaml_data
Пример #5
0
def test_read_json(get_asset):
    json_file = get_asset("json_file.json")

    json_data = load(json_file)

    assert TEST_FILE_CONTENTS == json_data
Пример #6
0
def test_read_pickle(get_asset):
    pickle_file = get_asset("pickle_file.pkl")

    pickle_data = load(pickle_file)

    assert TEST_FILE_CONTENTS == pickle_data