def test_cases(self, new_project, params): proj_ctx, pyproj_ctx = new_project git = params.get("git", True) pkg = params.get("pkg", "mypkg") pyproj_data = params.get("pyproject", True) with proj_ctx(git=git, pkg=pkg) as proj: if pyproj_data: with pyproj_ctx() as pyproj: pyproj = DottedDict(pyproj) print(pyproj) if isinstance(pyproj_data, dict): for k, v in pyproj_data.items(): pyproj.set(k, v) for ith_result, result in enumerate(params.get("results", [])): for f, func in result.get("paths", {}).items(): path = proj.join(f) passes = func(path) if not passes: msg = ("Result ({}) did not pass the following" "\nFailing condition: {}".format( ith_result, inspect.getsource(func).strip())) raise AssertionError(msg) args = result.get("args", tuple()) if result.get("raises"): with pytest.raises(result["raises"]): exit_code = main(args) else: exit_code = main(args) if result.get("exit_code", None) is not None: assert exit_code == result["exit_code"]
def test_new_reqs_file_not_added(new_project): proj_ctx, pyproj_ctx = new_project with proj_ctx() as proj: with pyproj_ctx(): pass # Should not fail since 'requirements-dev.txt' is not added to git yet f = "requirements.txt" proj.join(f).write("a" * 1000) cmd_output("git", "add", f) assert main(argv=[f, "--requirements", "requirements-dev.txt"]) == 1 assert main(argv=[f, "--requirements", "requirements-dev.txt"]) == 0
def test_adding_requirements_twice(new_project): logger.setLevel("DEBUG") proj_ctx, pyproj_ctx = new_project with proj_ctx(git=True) as proj: with pyproj_ctx(): pass f = "script.py" proj.join(f).write("a" * 1000) # requirements doesn't exist, so exit=1 cmd_output("git", "add", f) assert main(argv=[f]) == 1 # requirements does exist, so exit=0 cmd_output("git", "add", f) assert main(argv=[f]) == 0
def test_adding_pyproject(new_project): proj_ctx, pyproj_ctx = new_project with proj_ctx(git=True): with pyproj_ctx(): pass cmd_output("git", "add", "pyproject.toml") assert main(argv=["pyproject.toml"]) == 1
def test_argv_none(new_project): proj_ctx, pyproj_ctx = new_project with proj_ctx(git=True) as proj: with pyproj_ctx(): pass proj.join("requirements.txt").write("") proj.join("f.py").write("a" * 1000) cmd_output("git", "add", "f.py") assert main(argv=None) == 0
def test_adding_requirements(new_project): proj_ctx, pyproj_ctx = new_project with proj_ctx(git=True) as proj: with pyproj_ctx(): pass f = "requirements.txt" proj.join(f).write("a" * 1000) cmd_output("git", "add", f) assert main(argv=[f]) == 1
def test_missing_requirments(new_project): proj_ctx, pyproj_ctx = new_project with proj_ctx(git=True) as proj: with pyproj_ctx(): pass proj.join("f.py").write("a" * 1000) cmd_output("git", "add", "f.py") assert main(argv=["f.py"]) == 1 assert proj.join("requirements.txt").isfile()
def test_adding_lock(new_project): proj_ctx, pyproj_ctx = new_project with proj_ctx(git=True) as proj: with pyproj_ctx(): pass f = "poetry.lock" assert not proj.join("poetry.lock").isfile() assert not proj.join("requirements.txt").isfile() assert main(argv=[f]) == 1 assert proj.join("poetry.lock").isfile() assert proj.join("requirements.txt").isfile()
def test_without_hashes_option(new_project): proj_ctx, pyproj_ctx = new_project with proj_ctx() as proj: with pyproj_ctx(): pass # Should not fail since 'requirements-dev.txt' is not added to git yet f = "requirements.txt" proj.join(f).write("a" * 1000) cmd_output("git", "add", f) print(cmd_output("poetry", "self", "-V")) assert (main(argv=[ f, "--requirements", "requirements-dev.txt", "--poetry='--without-hashes'", ]) == 1) assert (main(argv=[ f, "--requirements", "requirements-dev.txt", "--poetry='--without-hashes'", ]) == 0)