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_get_default_opts_with_nogit(nogit_mock):
with pytest.raises(GitNotInstalled):
get_default_options({}, dict(project="my-project"))
def test_get_default_opts():
_, opts = get_default_options(
{}, dict(project="project", package="package", description="description")
)
assert all(k in opts for k in "project update force author".split())
assert isinstance(opts["extensions"], list)
assert isinstance(opts["requirements"], list)
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"])
.strip()
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_create_project_with_license(tmpfolder, git_mock):
_, opts = get_default_options({}, dict(project="my-project", license="new-bsd"))
# ^ The entire default options are needed, since template
# uses computed information
create_project(opts)
assert path_exists("my-project")
content = tmpfolder.join("my-project/LICENSE.txt").read()
assert content == templates.license(opts)
def test_get_default_opts_with_git_not_configured(noconfgit_mock):
with pytest.raises(GitNotConfigured):
get_default_options({}, dict(project="my-project"))
def test_move_old_package(tmpfolder):
# Given a package is already created without namespace
create_project(project="proj", package="my_pkg")
assert tmpfolder.join("proj/src/my_pkg/__init__.py").check()
opts = dict(project="proj", package="my_pkg", namespace="my.ns")
struct = dict(proj={"src": {"my_pkg": {"file.py": ""}}})
# when the '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 should be moved
assert not tmpfolder.join("proj/src/my_pkg/__init__.py").check()
assert tmpfolder.join("proj/src/my/ns/my_pkg/__init__.py").check()
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")))
for text in expected_log:
assert text in log
# but user should see no warning,
unexpected_warnings = (
"A folder",