def test_project_config_with_comments(cookies: Cookies, preserve_comments: str) -> None: result = cookies.bake( extra_context={ "project_dir": "project-with-comments", "preserve Neuro Flow template hints": preserve_comments, } ) assert result.exit_code == 0 comment_sign = "#" with inside_dir(str(result.project_path)): live_file_content = Path(".neuro/live.yml").read_text() project_file_content = Path(".neuro/project.yml").read_text() l_com_exists = comment_sign in live_file_content p_com_exists = comment_sign in project_file_content if preserve_comments == "yes": assert l_com_exists, ".neuro/live.yml file does not contain comments" assert p_com_exists, ".neuro/project.yml file does not contain comments" elif preserve_comments == "no": assert not l_com_exists, ".neuro/live.yml file contains comments" assert not p_com_exists, ".neuro/project.yml file contains comments" else: raise RuntimeError( f"invalid value '{preserve_comments}' for 'preserve_comments' arg. " " Only 'yes' and 'no' are allowed." )
def test_doit_coverage(cookies): result = cookies.bake() with inside_dir(result.project): with poetryenv_in_project(): importlib.reload(dodo) dodo.webbrowser = mock.MagicMock() assert DoitMain(ModuleTaskLoader(dodo)).run(["coverage"]) == 0 importlib.reload(dodo)
def test_entrypoints(cookies, capfd): result = cookies.bake() with inside_dir(result.project): with poetryenv_in_project(): assert subprocess.run(["doit", "install"]).returncode == 0 emoji_cmd = ["poetry", "run", "emoji", "-e", "snek", "-c", "3"] assert subprocess.run(emoji_cmd).returncode == 0 captured = capfd.readouterr() assert "\n🐍🐍🐍\n" in captured.out
def test_doit_style_with_fails(cookies, capfd, pkg_name, expected_error): result = cookies.bake(extra_context={"project_name": "mypackage"}) project = result.project with inside_dir(project): with project.join(pkg_name, "dummy.py").open("w") as fo: fo.write(bad_style_code()[expected_error]) with poetryenv_in_project(): assert subprocess.run(["doit", "style"]).returncode != 0 captured = capfd.readouterr() assert expected_error in captured.out
def test_copy_directory(cookies): result = cookies.bake() project = result.project with inside_dir(project): importlib.reload(dodo) with mock.patch("dodo.os") as m_os: with mock.patch("dodo.shutil") as m_shutil: m_os.path.join = lambda *paths: "/".join(paths) m_os.path.basename.return_value = "b" m_os.path.isdir.side_effect = [True, True] m_os.path.exists.return_value = False dodo.copy_directory("a/b", "c") m_shutil.copytree.called_once_with("a/b", "c/b")
def test_doit_docs(cookies, docs_generator): extra_context = {"docs_generator": docs_generator} result = cookies.bake(extra_context=extra_context) project = result.project with inside_dir(project): with poetryenv_in_project(): importlib.reload(dodo) dodo.webbrowser = mock.MagicMock() project.mkdir("docs", "htmlcov") with project.join("docs", "htmlcov", "index.html").open("w") as fo: fo.write("") assert DoitMain(ModuleTaskLoader(dodo)).run(["docs"]) == 0 assert project.join("site", "htmlcov").check(dir=1) importlib.reload(dodo)
def test_project_description(cookies: Cookies) -> None: descriptions = [ # " ", "Descrition!", "123", "https://github.com/neuro-inc/cookiecutter-neuro-project/", ] for descr in descriptions: result = cookies.bake(extra_context={"project_description": descr}) assert result.exit_code == 0, descr with inside_dir(str(result.project_path)): readme_content = Path("README.md").read_text() if descr: assert "## Project description" in readme_content assert descr in readme_content
def test_bumpversion(cookies): result = cookies.bake() with inside_dir(result.project): with poetryenv_in_project(): subprocess.run(["poetry", "install"]) bump = subprocess.run( ["poetry", "run", "bump2version", "patch", "-n", "--verbose"], stderr=subprocess.PIPE, universal_newlines=True, ).stderr assert '+version = "0.1.1"' in bump assert '+__version__ = "0.1.1"' in bump now = datetime.utcnow().strftime("%Y-%m-%d") assert ( "+## [v0.1.1]({repo}/compare/0.1.0...0.1.1) ({now})".format( repo="https://github.com/your_email/your_project_name", now=now, ) in bump)
def test_clean_paths(cookies): result = cookies.bake() project = result.project with inside_dir(project): importlib.reload(dodo) with mock.patch("dodo.os") as m_os: with mock.patch("dodo.glob") as m_glob: with mock.patch("dodo.shutil") as m_shutil: m_glob.glob.side_effect = (("c", "d"), ("e", "f")) m_os.path.isdir.side_effect = lambda path_: path_ > "c" m_os.path.isfile.side_effect = lambda path_: path_ <= "c" dodo.clean_paths("a", "b", "*", "?") m_os.remove.assert_has_calls( [mock.call("a"), mock.call("b"), mock.call("c")]) m_shutil.rmtree.assert_has_calls( [mock.call("d"), mock.call("e"), mock.call("f")]) importlib.reload(dodo)
def test_neuro_flow_live(cookies: Cookies, preserve_comments: str) -> None: result = cookies.bake( extra_context={ "project_dir": "test-project", "project_id": "awesome_project", "preserve Neuro Flow template hints": preserve_comments, } ) with inside_dir(str(result.project_path)): proc = exec("neuro-flow --show-traceback ps") assert "JOB" in proc.stdout, proc proc = exec("neuro-flow --show-traceback status train", assert_exit_code=False) assert "is not running" in proc.stdout, proc proc = exec("neuro-flow --show-traceback run --dry-run train") assert "neuro run" in proc.stdout, proc assert "--tag=project:awesome-project" in proc.stdout, proc proc = exec("neuro-flow --show-traceback run --dry-run remote_debug") assert "neuro run" in proc.stdout, proc assert "--tag=project:awesome-project" in proc.stdout, proc
def test_run_flake8(cookies: Cookies) -> None: result = cookies.bake(extra_context={"project_dir": "flake8-compat"}) with inside_dir(str(result.project_path)): subprocess.check_call(["flake8"])
def test_doit_command_run_in_project(cookies, command): result = cookies.bake() with inside_dir(result.project): with poetryenv_in_project(): assert subprocess.run(["doit", command]).returncode == 0