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_without_args(tmpfolder):
old_args = [
"my_project",
"-u",
"http://www.blue-yonder.com/",
"-d",
"my description",
]
cli.main(old_args)
args = ["my_project"]
opts = cli.parse_args(args)
opts = cli.process_opts(opts)
new_opts = info.project(opts)
assert new_opts["url"] == "http://www.blue-yonder.com/"
assert new_opts["package"] == "my_project"
assert new_opts["license"] == "mit"
assert new_opts["description"] == "my description"
def test_parse_list_actions():
opts = cli.parse_args(["my-project", "--list-actions"])
assert opts["command"] == cli.list_actions
opts = cli.parse_args(["my-project"])
assert opts["command"] == cli.run_scaffold
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)
def test_pretend_move_old_package(tmpfolder, caplog, isolated_logger):
# Given a package is already created without namespace
create_project(project="proj", package="my_pkg")
opts = parse_args(["proj", "-p", "my_pkg", "--namespace", "my.ns", "--pretend"])
opts = process_opts(opts)
logger.reconfigure(opts)
struct = dict(proj={"src": {"my_pkg": {"file.py": ""}}})
# 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")))
def test_parse_default_log_level():
args = ["my-project"]
opts = cli.parse_args(args)
assert opts["log_level"] == logging.WARNING
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_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_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 = (
def test_define_structure():
args = ["project", "-p", "package", "-d", "description"]
opts = cli.parse_args(args)
_, opts = api.get_default_options({}, opts)
struct, _ = structure.define_structure({}, opts)
assert isinstance(struct, dict)
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")