Exemplo n.º 1
0
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)
Exemplo n.º 2
0
def test_pretend_move_old_package(tmpfolder, caplog, isolated_logger):
    # Given a package is already created without namespace
    create_project(project_path="proj", package="my_pkg")

    opts = parse_args(
        ["proj", "-p", "my_pkg", "--namespace", "my.ns", "--pretend"])
    struct = {"src": {"my_pkg": {"file.py": ""}}}
    logger.reconfigure(opts)

    # when 'pretend' option is passed,
    struct, opts = get_default_options(struct, opts)
    struct, opts = enforce_namespace_options(struct, opts)
    struct, opts = move_old_package(struct, opts)

    # then nothing should happen,
    assert tmpfolder.join("proj/src/my_pkg/__init__.py").check()
    assert not tmpfolder.join("proj/src/my/ns").check()

    # something should be logged,
    log = caplog.text
    expected_log = ("move", "my_pkg", "to", str(Path("my/ns")))
    for text in expected_log:
        assert text in log

    # but user should see no warning,
    unexpected_warnings = (
        "A folder",
        "exists in the project directory",
        "a namespace option was passed",
        "Please make sure",
    )
    for text in unexpected_warnings:
        assert text not in log
Exemplo n.º 3
0
def test_create_project_with_license(tmpfolder, git_mock):
    _, opts = get_default_options(
        {}, dict(project_path="my-project", license="BSD-3-Clause")
    )
    # ^ The entire default options are needed, since template
    #   uses computed information

    create_project(opts)
    assert Path("my-project").exists()
    content = tmpfolder.join("my-project/LICENSE.txt").read()
    assert content == templates.license(opts)
Exemplo n.º 4
0
def test_move_old_package_without_namespace(tmpfolder):
    # Given a package is already created without namespace
    create_project(project_path="proj", package="my_pkg")

    opts = dict(project_path="proj", package="my_pkg")
    struct = {"src": {"my_pkg": {"file.py": ""}}}

    # when no 'namespace' option is passed,
    struct, opts = get_default_options(struct, opts)
    struct, opts = enforce_namespace_options(struct, opts)
    struct, opts = move_old_package(struct, opts)

    # then the old package remains,
    assert tmpfolder.join("proj/src/my_pkg/__init__.py").check()
Exemplo n.º 5
0
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")
Exemplo n.º 6
0
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"
Exemplo n.º 7
0
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())
Exemplo n.º 8
0
def test_update_setup_cfg(tmpfolder):
    # Given an existing setup.cfg
    proj = Path(tmpfolder, "proj")
    proj.mkdir(parents=True, exist_ok=True)
    (proj / "setup.cfg").write_text("[metadata]\n\n[pyscaffold]\n")
    # when we update it
    extensions = [
        Object(name="cirrus", persist=True),
        Object(name="no", persist=False)
    ]
    opts = {"project_path": proj, "extensions": extensions}
    _, opts = actions.get_default_options({}, opts)
    update.update_setup_cfg({}, opts)
    cfg = info.read_setupcfg(proj / "setup.cfg")
    # then it should show the most update pyscaffold version
    assert cfg["pyscaffold"]["version"].value == __version__
    assert "cirrus" in cfg["pyscaffold"]["extensions"].value
    assert "no" not in cfg["pyscaffold"]["extensions"].value
    # and some configuration keys should be present
    assert "options" in cfg
Exemplo n.º 9
0
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()
Exemplo n.º 10
0
def test_get_default_opts_with_git_not_configured(noconfgit_mock):
    with pytest.raises(GitNotConfigured):
        get_default_options({}, dict(project_path="my-project"))
Exemplo n.º 11
0
def test_get_default_opts_with_nogit(nogit_mock):
    with pytest.raises(GitNotInstalled):
        get_default_options({}, dict(project_path="my-project"))
Exemplo n.º 12
0
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)