def test_no_config(): opts = parse("--no-config") assert opts["config_files"] == api.NO_CONFIG # Even after bootstrap_options opts = api.bootstrap_options(opts) assert opts["config_files"] == api.NO_CONFIG
def test_define_structure(): args = ["project", "-p", "package", "-d", "description"] opts = cli.parse_args(args) opts = api.bootstrap_options(opts) _, opts = actions.get_default_options({}, opts) struct, _ = structure.define_structure({}, opts) assert isinstance(struct, dict)
def test_no_cli_opts(default_file): # When no --config or --save-config is passed cli_opts = parse() # Then no save_config or config_files should be found in the opts assert "save_files" not in cli_opts # and config_files will be bootstraped with an empty list # if the default file does not exist opts = api.bootstrap_options(cli_opts) assert opts["config_files"] == [] # or config_files will be bootstraped with the # default file if it exists default_file.write_text("[pyscaffold]\n") opts = api.bootstrap_options(cli_opts) assert opts["config_files"] == [default_file]
def test_bootstrap_using_config_file(tmpfolder): # First we create a config file opts = dict(project_path="proj", name="my-proj", license="MPL-2.0") opts = bootstrap_options(opts) _, opts = get_default_options({}, opts) setup_cfg = Path(str(tmpfolder.join("setup.cfg"))) setup_cfg.write_text(templates.setup_cfg(opts)) # Then we input this configfile to the API new_opts = dict(project_path="another", config_files=[str(setup_cfg)]) new_opts = bootstrap_options(new_opts) # Finally, the bootstraped options should contain the same values # as the given config file assert new_opts["name"] == "my-proj" assert new_opts["package"] == "my_proj" assert new_opts["license"] == "MPL-2.0" assert str(new_opts["project_path"]) == "another" assert all(k in new_opts for k in "author email url".split())
def test_bootstrap_with_no_config(tmpfolder, with_default_config): # Given a default config file exists and contains stuff _ = with_default_config # when bootstrapping options with NO_CONFIG opts = dict(project_path="xoxo", config_files=NO_CONFIG) new_opts = bootstrap_options(opts) # the stuff will not be considered assert new_opts.get("author") != "John Doe" assert new_opts.get("email") != "*****@*****.**" assert new_opts.get("namespace") != "my_namespace.my_sub_namespace" extensions = new_opts.get("extensions", []) assert len(extensions) != 2 extensions_names = sorted([e.name for e in extensions]) assert " ".join(extensions_names) != "cirrus namespace"
def test_bootstrap_with_default_config(tmpfolder, with_default_config): # Given a default config file exists and contains stuff _ = with_default_config # when bootstrapping options opts = dict(project_path="xoxo") new_opts = bootstrap_options(opts) # the stuff will be considered assert new_opts["author"] == "John Doe" assert new_opts["email"] == "*****@*****.**" assert new_opts["namespace"] == "my_namespace.my_sub_namespace" extensions = new_opts["extensions"] assert len(extensions) == 2 extensions_names = sorted([e.name for e in extensions]) assert " ".join(extensions_names) == "cirrus namespace"
def test_setup_cfg(): reqs = ("mydep1>=789.8.1", "mydep3<=90009;python_version>'3.5'", "other") opts = api.bootstrap_options({ "project_path": "myproj", "requirements": reqs }) _, opts = actions.get_default_options({}, opts) text = templates.setup_cfg(opts) setup_cfg = ConfigParser() setup_cfg.read_string(text) # Assert install_requires is correctly assigned install_requires = deps.split(setup_cfg["options"]["install_requires"]) for dep in reqs: assert dep in install_requires # Assert PyScaffold section assert setup_cfg["pyscaffold"].get("version")
def test_options_with_existing_proj_config_and_cli(with_existing_proj_config): # Given an existing project with a setup.cfg _ = with_existing_proj_config # When the CLI is called with no extra parameters opts = cli.parse_args(["--update", "."]) opts = bootstrap_options(opts) _, opts = get_default_options({}, opts) # After all the opt processing actions are finished # The parameters in the old setup.py files are preserved assert opts["name"] == "SuperProj" assert opts["description"] == "some text" assert opts["author"] == "John Doe" assert opts["email"] == "*****@*****.**" assert opts["url"] == "www.example.com" assert opts["license"] == "GPL-3.0-only" assert opts["package"] == "super_proj"
def test_config_opts(default_file, fake_config_dir): files = [] for j in range(3): file = fake_config_dir / f"test{j}.cfg" file.write_text("[pyscaffold]\n") files.append(file) # --config can be passed with 1 value opts = parse("--config", str(files[0])) assert opts["config_files"] == files[:1] # --config can be passed with many opts = parse("--config", *map(str, files)) assert opts["config_files"] == files # after bootstrap_options, the given files are kept # and the default is not included opts = api.bootstrap_options(opts) assert default_file not in opts["config_files"] assert opts["config_files"] == files
def test_version_of_subdir(tmpfolder): projects = ["main_project", "inner_project"] for project in projects: opts = cli.parse_args([project]) opts = api.bootstrap_options(opts) _, opts = actions.get_default_options({}, opts) struct, _ = structure.define_structure({}, opts) struct, _ = structure.create_structure(struct, opts) repo.init_commit_repo(project, struct) rm_rf(Path("inner_project", ".git")) move("inner_project", target="main_project/inner_project") # setuptools_scm required explicitly setting the git root when setup.py is # not at the root of the repository nested_setup_py = Path(tmpfolder, "main_project/inner_project/setup.py") content = nested_setup_py.read_text() content = content.replace( "use_scm_version={", 'use_scm_version={"root": "..", "relative_to": __file__, ' ) nested_setup_py.write_text(content) nested_pyproject_toml = Path(tmpfolder, "main_project/inner_project/pyproject.toml") config = toml.loads(nested_pyproject_toml.read_text()) config["tool"]["setuptools_scm"]["root"] = ".." nested_pyproject_toml.write_text(toml.dumps(config)) with chdir("main_project"): main_version = ( subprocess.check_output([sys.executable, "setup.py", "--version"]) .strip() .splitlines()[-1] ) with chdir("inner_project"): inner_version = ( subprocess.check_output([sys.executable, "setup.py", "--version"]) .strip() .splitlines()[-1] ) assert main_version.strip() == inner_version.strip()
def test_get_default_opts(): opts = bootstrap_options(project_path="project", package="package") _, opts = get_default_options({}, opts) assert all(k in opts for k in "project_path update force author".split()) assert isinstance(opts["extensions"], list) assert isinstance(opts["requirements"], list)
def test_bootstrap_opts_raises_when_config_file_doesnt_exist(): opts = dict(project_path="non-existent", config_files=["non-existent.cfg"]) with pytest.raises(FileNotFoundError): bootstrap_options(opts)
def test_bootstrap_opts_raises_when_updating_non_existing(): with pytest.raises(NoPyScaffoldProject): bootstrap_options(project_path="non-existent", update=True)