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_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_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_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
import io from datetime import datetime import pytest from copier.config import make_config from copier.config.objects import DEFAULT_DATA, EnvOps from copier.config.user_data import InvalidTypeError, query_user_data answers_data = DEFAULT_DATA.copy() envops = EnvOps() main_default = "copier" main_question = {"main": {"default": main_default}} @pytest.mark.parametrize( "questions_data, expected_value, expected_outputs", [ ( { "templated_default": { "default": "[[ main ]]default" } }, "copierdefault", ["[copierdefault]"], ), ( { "templated_type": { "type": "[% if main == 'copier' %]int[% endif %]",
def test_envops_good_data(): ops = EnvOps(**GOOD_ENV_OPS) assert ops.dict() == GOOD_ENV_OPS
def test_envops_bad_data(data): with pytest.raises(ValidationError): EnvOps(**data)