def test_cli(monkeypatch, tmpfolder): # When the user edit the contents of the file fake_content = """\ myproj_path --name myproj --license gpl3 --no-config # --namespace myns # ^ test commented options """ fake_edit = tmpfolder / "pyscaffold.args" fake_edit.write_text(dedent(fake_content), "utf-8") monkeypatch.setattr("pyscaffold.shell.edit", lambda *_, **__: fake_edit) # Then, the options in the file should take place, not the ones given in the cli args = [ "-vv", "--no-config", "--interactive", "myproj", "--no-tox", "--license", "mpl", ] cli.run(args) assert not (tmpfolder / "myproj").exists() assert (tmpfolder / "myproj_path/tox.ini").exists() assert (tmpfolder / "myproj_path/src/myproj/__init__.py").exists() license = (tmpfolder / "myproj_path/LICENSE.txt").read_text("utf-8") assert "GNU GENERAL PUBLIC LICENSE" in license assert "Version 3" in license # Commented options (or options that were not mentioned) should not take place assert not (tmpfolder / "myproj_path/src/myns").exists() assert not (tmpfolder / "myproj_path/.pre-commit-config.yaml").exists()
def test_cli_with_tox(tmpfolder): # when the project is created with the CLI sys.argv = ["pyscaffold", "proj"] run() # then tox files should exist assert Path("proj/tox.ini").exists()
def test_cli_without_no_pyproject(tmpfolder): # Given the command line without the no-pyproject option, # when pyscaffold runs, run(["--no-pyproject", "proj"]) # then file should not exist assert not Path("proj/pyproject.toml").exists()
def test_cli_with_no_pyproject_and_pretend(tmpfolder): # Given the command line with the no-pyproject and pretend options, # when pyscaffold runs, run(["--pretend", "--no-pyproject", "proj"]) # then file should not exist (or the project itself) assert not Path("proj/pyproject.toml").exists() assert not Path("proj").exists()
def test_cli_without_cirrus(tmpfolder): # Given the command line without the cirrus option, sys.argv = ["pyscaffold", "proj"] # when pyscaffold runs, run() # then cirrus files should not exist assert not path_exists("proj/.cirrus.yml")
def test_cli_without_tox(tmpfolder): # Given the command line without the tox option, sys.argv = ["pyscaffold", "proj"] # when pyscaffold runs, run() # then tox files should not exist assert not path_exists("proj/tox.ini")
def test_cli_without_pyproject(tmpfolder): # Given the command line without the pyproject option, sys.argv = ["pyscaffold", "proj"] # when pyscaffold runs, run() # then pyproject files should not exist assert not path_exists("proj/pyproject.toml")
def test_cli_without_tox(tmpfolder): # Given the command line with --no-tox sys.argv = ["pyscaffold", "proj", "-vv", "--no-tox"] # when pyscaffold runs, run() # then tox files should not exist assert not Path("proj/tox.ini").exists()
def test_cli_without_namespace(tmpfolder): # Given the command line without the namespace option, sys.argv = ["pyscaffold", "proj"] # when pyscaffold runs, run() # then namespace dir should not exist assert not Path("proj/src/ns").exists()
def test_cli_without_namespace(tmpfolder): # Given the command line without the namespace option, sys.argv = ["pyscaffold", "proj"] # when pyscaffold runs, run() # then namespace files should not exist assert not path_exists("proj/src/ns/__init__.py")
def test_cli_without_pre_commit(tmpfolder): # Given the command line without the pre-commit option, sys.argv = ["pyscaffold", "proj"] # when pyscaffold runs, run() # then pre-commit files should not exist assert not path_exists("proj/.pre-commit-config.yaml")
def test_cli_with_no_skeleton_and_pretend(tmpfolder): # Given the command line with the no-skeleton and pretend options, sys.argv = ["pyscaffold", "--pretend", "--no-skeleton", "proj"] # when pyscaffold runs, run() # then skeleton file should not exist (or the project itself) assert not Path("proj/src/proj/skeleton.py").exists() assert not Path("proj").exists()
def test_cli_with_no_skeleton(tmpfolder): # Given the command line with the no-skeleton option, sys.argv = ["pyscaffold", "--no-skeleton", "proj"] # when pyscaffold runs, run() # then skeleton file should not exist assert not Path("proj/src/proj/skeleton.py").exists() assert not Path("proj/tests/test_skeleton.py").exists()
def test_cli_with_namespace_and_pretend(tmpfolder): # Given the command line with the namespace and pretend options sys.argv = ["pyscaffold", "proj", "--namespace", "ns", "--pretend"] # when pyscaffold runs, run() # then namespace __init__ package should not exist (or even the project) assert not Path("proj/src/ns/__init__.py").exists() assert not Path("proj").exists()
def test_cli_without_django(tmpfolder): # Given the command line without the django option, sys.argv = ["pyscaffold", PROJ_NAME] # when pyscaffold runs, run() # then django files should not exist for path in DJANGO_FILES: assert not path_exists(path)
def test_cli_without_tox_but_pretend(tmpfolder): # Given the command line with --no-tox and --pretend sys.argv = ["pyscaffold", "proj", "-vv", "--no-tox", "--pretend"] # when pyscaffold runs, run() # then tox files should not exist (or even the project) assert not Path("proj/tox.ini").exists() assert not Path("proj").exists()
def test_cli_without_travis(tmpfolder): # Given the command line without the travis option, sys.argv = ["pyscaffold", "proj"] # when pyscaffold runs, run() # then travis files should not exist assert not Path("proj/.travis.yml").exists() assert not Path("proj/tests/travis_install.sh").exists()
def test_cli_without_cookiecutter(tmpfolder): # Given the command line without the cookiecutter option, sys.argv = ["pyscaffold", PROJ_NAME] # when pyscaffold runs, run() # then cookiecutter files should not exist for path in COOKIECUTTER_FILES: assert not path_exists(path)
def test_cli_with_travis(tmpfolder): # Given the command line with the travis option, sys.argv = ["pyscaffold", "--travis", "proj"] # when pyscaffold runs, run() # then travis files should exist assert path_exists("proj/.travis.yml") assert path_exists("proj/tests/travis_install.sh")
def test_cli_without_no_skeleton(tmpfolder): # Given the command line without the tox option, sys.argv = ["pyscaffold", "proj"] # when pyscaffold runs, run() # then skeleton file should exist assert path_exists("proj/src/proj/skeleton.py") assert path_exists("proj/tests/test_skeleton.py")
def test_cli_with_pre_commit(tmpfolder): # Given the command line with the pre-commit option, sys.argv = ["pyscaffold", "--pre-commit", "proj"] # when pyscaffold runs, run() # then pre-commit files should exist assert Path("proj/.pre-commit-config.yaml").exists() assert Path("proj/.isort.cfg").exists()
def test_cli_with_namespace(tmpfolder): # Given the command line with the namespace option, sys.argv = ["pyscaffold", "proj", "--namespace", "ns"] # when pyscaffold runs, run() # then namespace package should exist assert path_exists("proj/src/ns/__init__.py") assert path_exists("proj/src/ns/proj/__init__.py")
def test_cli_with_pre_commit_or_pretend(tmpfolder): # Given the command line with the pre-commit option and pretend sys.argv = ["pyscaffold", "--pretend", "--pre-commit", "proj"] # when pyscaffold runs, run() # then pre-commit files should not exist (or the project itself) assert not Path("proj/.pre-commit-config.yaml").exists() assert not Path("proj").exists()
def test_cli_with_empty_namespace(tmpfolder, capsys): # Given the command line with the namespace option, sys.argv = ["pyscaffold", "proj", "--namespace"] # when pyscaffold runs, with pytest.raises(SystemExit): run() # then an error occurs _, err = capsys.readouterr() assert 'expected one argument' in err
def test_cli_with_cirrus_and_pretend(tmpfolder): # Given the command line with the cirrus and pretend options sys.argv = ["pyscaffold", "--pretend", "--cirrus", "proj"] # when pyscaffold runs, run() # then cirrus files should not exist assert not path_exists("proj/.cirrus.yml") # (or the project itself) assert not path_exists("proj")
def test_cli_with_empty_namespace(tmpfolder, capsys): # Given the command line with the namespace option, sys.argv = ["pyscaffold", "proj", "--namespace"] # when pyscaffold runs, with pytest.raises(SystemExit): run() # then an error occurs _, err = capsys.readouterr() assert "expected one argument" in err
def test_cli_with_travis_and_pretend(tmpfolder): # Given the command line with the travis option and pretend sys.argv = ["pyscaffold", "--pretend", "--travis", "proj"] # when pyscaffold runs, run() # then travis files (or the project itself) should not exist assert not Path("proj/.travis.yml").exists() assert not Path("proj/tests/travis_install.sh").exists() assert not Path("proj").exists()
def test_with_numpydoc(tmpdir): # noqa sys.argv = ["pyscaffold", "--with-numpydoc", "my_project"] cli.run() conffile = os.path.join(os.path.abspath(os.path.curdir), "my_project", "docs", "conf.py") conf = imp.load_source('conf', conffile) assert sorted(conf.extensions) == sorted([ 'sphinx.ext.autodoc', 'sphinx.ext.intersphinx', 'sphinx.ext.todo', 'sphinx.ext.autosummary', 'sphinx.ext.viewcode', 'sphinx.ext.coverage', 'sphinx.ext.doctest', 'sphinx.ext.ifconfig', 'sphinx.ext.pngmath', 'numpydoc' ])
def test_cli_with_cookiecutter_but_no_template(tmpfolder, capsys): # Given the command line with the cookiecutter option, but no template sys.argv = ["pyscaffold", PROJ_NAME, "--cookiecutter"] # when pyscaffold runs, # then an exception should be raised. with pytest.raises(SystemExit): run() # make sure the exception is related to the missing argument out, err = capsys.readouterr() assert "--cookiecutter: expected one argument" in out + err
def test_cli_with_cirrus(tmpfolder): # Given the command line with the cirrus option, sys.argv = ["pyscaffold", "--cirrus", "proj"] # when pyscaffold runs, run() # then files from cirrus and other extensions automatically added should # exist assert path_exists("proj/.cirrus.yml") assert path_exists("proj/tox.ini") assert path_exists("proj/.pre-commit-config.yaml")
def test_cli_with_django_and_update(tmpfolder, capsys): # Given a project exists create_project(project=PROJ_NAME) # when the project is updated # with the django extension, sys.argv = ["pyscaffold", PROJ_NAME, "--update", "--django"] run() # then a warning should be displayed out, err = capsys.readouterr() assert all(warn in out + err for warn in ( 'external tools', 'not supported', 'will be ignored'))
def test_with_numpydoc(tmpdir): # noqa sys.argv = ["pyscaffold", "--with-numpydoc", "my_project"] cli.run() conffile = os.path.join( os.path.abspath(os.path.curdir), "my_project", "docs", "conf.py") conf = imp.load_source('conf', conffile) assert sorted(conf.extensions) == sorted(['sphinx.ext.autodoc', 'sphinx.ext.intersphinx', 'sphinx.ext.todo', 'sphinx.ext.autosummary', 'sphinx.ext.viewcode', 'sphinx.ext.coverage', 'sphinx.ext.doctest', 'sphinx.ext.ifconfig', 'sphinx.ext.pngmath', 'numpydoc'])
def test_overwrite_git_repo(tmpdir): # noqa sys.argv = ["pyscaffold", "my_project"] cli.run() with pytest.raises(SystemExit): cli.run() sys.argv = ["pyscaffold", "--force", "my_project"] cli.run()
def test_with_namespaces(tmpdir): # noqa sys.argv = ["pyscaffold", "--with-namespace", "com.blue_yonder", "my_project"] cli.run() assert os.path.exists("my_project/com/blue_yonder")
def test_with_gitlab(tmpdir): # noqa sys.argv = ["pyscaffold", "--with-gitlab-ci", "my_project"] cli.run()
def test_django_proj(tmpdir): # noqa sys.argv = ["pyscaffold", "--with-django", "my_project"] cli.run()
def test_overwrite_dir(tmpdir): # noqa os.mkdir("my_project") sys.argv = ["pyscaffold", "--force", "my_project"] cli.run()
def test_run(tmpdir, git_mock): # noqa sys.argv = ["pyscaffold", "my-project"] cli.run() assert os.path.exists(sys.argv[1])
def test_with_travis(tmpdir): # noqa sys.argv = ["pyscaffold", "--with-travis", "my_project"] cli.run()