Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_project_with_wrong_setup(tmpfolder):
os.mkdir("my_project")
open("my_project/setup.py", "a").close()
args = ["my_project"]
opts = cli.parse_args(args)
opts = cli.process_opts(opts)
with pytest.raises(FileNotFoundError):
info.project(opts)
def test_add_custom_extension(tmpfolder):
args = [EXT_FLAG, "my_project", "-p", "my_package"]
opts = parse_args(args)
opts = process_opts(opts)
create_project(opts)
assert path_exists("my_project/src/my_package/__init__.py")
def test_generated_extension_flake8(tmpfolder, venv_run):
args = [EXT_FLAG, "my_project"]
opts = parse_args(args)
opts = process_opts(opts)
create_project(opts)
with chdir("my_project"):
assert "" == venv_run(FLAKE8)
venv_run("python setup.py install")
venv_run("putup {ext_flag} the_actual_project".format(ext_flag=EXT_FLAG))
assert path_exists("the_actual_project/setup.cfg")
with chdir("the_actual_project"):
assert "" == venv_run(FLAKE8)
def test_generated_extension_flake8(tmpfolder, venv_run):
args = [EXT_FLAG, "my_project"]
opts = parse_args(args)
opts = process_opts(opts)
create_project(opts)
with chdir("my_project"):
assert "" == venv_run("flake8")
venv_run("python setup.py install")
venv_run("putup {ext_flag} the_actual_project".format(ext_flag=EXT_FLAG))
assert path_exists("the_actual_project/setup.cfg")
with chdir("the_actual_project"):
assert "" == venv_run("flake8")
def test_add_namespace():
args = ["project", "-p", "package", "--namespace", "com.blue_yonder"]
opts = parse_args(args)
opts = process_opts(opts)
opts["ns_list"] = prepare_namespace(opts["namespace"])
struct = {"project": {"src": {"package": {"file1": "Content"}}}}
ns_struct, _ = add_namespace(struct, opts)
ns_pkg_struct = ns_struct["project"]["src"]
assert ["project"] == list(ns_struct.keys())
assert "package" not in list(ns_struct.keys())
assert ["com"] == list(ns_pkg_struct.keys())
assert {"blue_yonder", "__init__.py"} == set(ns_pkg_struct["com"].keys())
assert "package" in list(ns_pkg_struct["com"]["blue_yonder"].keys())
def test_pretend_create_project_with_django(tmpfolder, caplog):
# Given options with the django extension,
caplog.set_level(logging.INFO)
opts = parse_args([PROJ_NAME, "--pretend", "--django"])
opts = process_opts(opts)
# when the project is created,
create_project(opts)
# then files should exist
assert not path_exists(PROJ_NAME)
for path in DJANGO_FILES:
assert not path_exists(path)
# but activities should be logged
logs = caplog.text
assert re.search(r"run.+django", logs)
def test_pretend_create_project_with_cookiecutter(tmpfolder, caplog):
# Given options with the cookiecutter extension,
caplog.set_level(logging.INFO)
opts = parse_args([PROJ_NAME, "--pretend", "--cookiecutter", COOKIECUTTER_URL])
opts = process_opts(opts)
# when the project is created,
create_project(opts)
# then files should exist
assert not path_exists(PROJ_NAME)
for path in COOKIECUTTER_FILES:
assert not path_exists(path)
# but activities should be logged
logs = caplog.text
assert re.search(r"run.+cookiecutter", logs)
def test_process_opts_raises():
opts = cli.parse_args(["non-existent", "--update"])
with pytest.raises(NoPyScaffoldProject):
cli.process_opts(opts)
def test_version_of_subdir(tmpfolder):
projects = ["main_project", "inner_project"]
for project in projects:
opts = cli.parse_args([project])
opts = cli.process_opts(opts)
_, opts = api.get_default_options({}, opts)
struct, _ = structure.define_structure({}, opts)
struct, _ = update.apply_update_rules(struct, opts)
structure.create_structure(struct, {})
repo.init_commit_repo(project, struct)
utils.rm_rf(os.path.join("inner_project", ".git"))
shutil.move("inner_project", "main_project/inner_project")
with utils.chdir("main_project"):
main_version = (
subprocess.check_output([sys.executable, "setup.py", "--version"])
.strip()
.splitlines()[-1]
)
with utils.chdir("inner_project"):
inner_version = (
subprocess.check_output([sys.executable, "setup.py", "--version"])
def test_project_with_no_setup(tmpfolder):
os.mkdir("my_project")
args = ["my_project"]
opts = cli.parse_args(args)
opts = cli.process_opts(opts)
with pytest.raises(FileNotFoundError):
info.project(opts)