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 create_project(path: LocalPath, project_name, pkg=None, git: bool = True): project = path.join(project_name).mkdir() if pkg: project.join(pkg).mkdir() with project.as_cwd(): if git: cmd_output("git", "init") yield project
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_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 poetry_export(filename: str, args): retv = 0 out = cmd_output(*poetry_cmd(*args)) create_new = False if not os.path.isfile(filename): logger.info("File '{}' does not exist.".format(filename)) create_new = True else: a = open(filename).read().strip() b = out.strip() if not a == b: create_new = True logger.info("'{f}' and new '{f}' do not match.".format(f=filename)) # try: # if logger.isEnabledFor("DEBUG"): # result = difflib.unified_diff( # a.split("\n"), b.split("\n"), fromfile=filename, tofile="new" # ) # for r in result: # logger.debug(r) # except Exception as e: # logger.error( # "There was an error logging difference. exception: {}".format( # str(e) # ) # ) if create_new: logger.info("Writing new '{}'".format(filename)) with open(filename, "w") as f: f.write(out) logger.debug(out) retv = 1 return retv
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_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)
def tempdir(tmpdir, pyproject): myproject = tmpdir.join("myproject").mkdir() with myproject.as_cwd(): cmd_output("git", "init")