def test_config_data_good_data(tmp_path): tmp_path = Path(tmp_path).expanduser().resolve() expected = { "src_path": tmp_path, "commit": None, "old_commit": None, "dst_path": tmp_path, "extra_paths": [tmp_path], "exclude": DEFAULT_EXCLUDE, "original_src_path": None, "skip_if_exists": ["skip_me"], "tasks": ["echo python rulez"], "templates_suffix": ".tmpl", "cleanup_on_error": True, "envops": EnvOps().dict(), "force": False, "only_diff": True, "pretend": False, "quiet": False, "skip": False, "vcs_ref": None, "migrations": (), "secret_questions": (), "subdirectory": None, } conf = ConfigData(**expected) conf.data["_folder_name"] = tmp_path.name expected["answers_file"] = Path(".copier-answers.yml") conf_dict = conf.dict() for key, value in expected.items(): assert conf_dict[key] == value
def test_config_data_good_data(dst): dst = Path(dst).expanduser().resolve() expected = { "src_path": dst, "commit": None, "old_commit": None, "dst_path": dst, "data": DEFAULT_DATA, "extra_paths": [dst], "exclude": DEFAULT_EXCLUDE, "original_src_path": None, "skip_if_exists": ["skip_me"], "tasks": ["echo python rulez"], "templates_suffix": ".tmpl", "cleanup_on_error": True, "envops": EnvOps().dict(), "force": False, "only_diff": True, "pretend": False, "quiet": False, "skip": False, "vcs_ref": None, "migrations": (), "secret_questions": (), "subdirectory": None, } conf = ConfigData(**expected) expected["data"]["_folder_name"] = dst.name expected["answers_file"] = Path(".copier-answers.yml") assert conf.dict() == expected
def test_flags_extra_ignored(): key = "i_am_not_a_member" conf_data = { "src_path": "..", "dst_path": ".", key: "and_i_do_not_belong_here" } confs = ConfigData(**conf_data) assert key not in confs.dict()
def test_config_data_good_data(dst): dst = Path(dst).expanduser().resolve() expected = { "src_path": dst, "dst_path": dst, "data": DEFAULT_DATA, "extra_paths": [dst], "exclude": DEFAULT_EXCLUDE, "include": [], "skip_if_exists": ["skip_me"], "tasks": ["echo python rulez"], "envops": EnvOps(), } conf = ConfigData(**expected) expected["data"]["folder_name"] = dst.name assert conf.dict() == expected
def test_config_data_paths_required(): try: ConfigData(envops=EnvOps()) except ValidationError as e: assert len(e.errors()) == 2 for i, p in enumerate(("src_path", "dst_path")): err = e.errors()[i] assert err["loc"][0] == p assert err["type"] == "value_error.missing" else: raise AssertionError()
def test_config_data_paths_existing(tmp_path): try: ConfigData( src_path="./i_do_not_exist", extra_paths=["./i_do_not_exist"], dst_path=tmp_path, envops=EnvOps(), ) except ValidationError as e: assert len(e.errors()) == 2 for i, p in enumerate(("src_path", "extra_paths")): err = e.errors()[i] assert err["loc"][0] == p assert err["msg"] == "Project template not found." else: raise AssertionError()
def test_flags_bad_data(data): with pytest.raises(ValidationError): ConfigData(**data)