From 9f769de74cfd72cf63618fda9f108bf59c27dbc3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 7 Jun 2022 08:07:08 +0000 Subject: [PATCH 01/12] Bump cookiecutter from 1.7.3 to 2.1.1 Bumps [cookiecutter](https://github.com/cookiecutter/cookiecutter) from 1.7.3 to 2.1.1. - [Release notes](https://github.com/cookiecutter/cookiecutter/releases) - [Changelog](https://github.com/cookiecutter/cookiecutter/blob/master/HISTORY.md) - [Commits](https://github.com/cookiecutter/cookiecutter/compare/1.7.3...2.1.1) --- updated-dependencies: - dependency-name: cookiecutter dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- requirements/base.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements/base.txt b/requirements/base.txt index d3e91551..b9a1858c 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -1 +1 @@ -cookiecutter==1.7.3 +cookiecutter==2.1.1 From 0e563057d42622feb9bd24765341b82d655c411e Mon Sep 17 00:00:00 2001 From: Andrii Khomiak Date: Mon, 13 Jun 2022 17:43:13 +0300 Subject: [PATCH 02/12] test: Change order of returncode and exception test --- tests/unit/test_bake_project.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/tests/unit/test_bake_project.py b/tests/unit/test_bake_project.py index fff17f0b..7bd6c73f 100644 --- a/tests/unit/test_bake_project.py +++ b/tests/unit/test_bake_project.py @@ -1,9 +1,9 @@ +import logging import os import subprocess import sys from pathlib import Path -import py import pytest import yaml from cookiecutter.exceptions import FailedHookException @@ -14,15 +14,19 @@ from tests.utils import inside_dir +logger = logging.getLogger(__name__) + + def test_project_tree(cookies: Cookies) -> None: result = cookies.bake(extra_context={"project_dir": "test-project"}) - assert result.exit_code == 0 assert result.exception is None + assert result.exit_code == 0 assert result.project_path.name == "test-project" def test_run_flake8(cookies: Cookies) -> None: result = cookies.bake(extra_context={"project_dir": "flake8-compat"}) + assert result.exception is None with inside_dir(str(result.project_path)): subprocess.check_call(["flake8"]) @@ -127,7 +131,7 @@ def test_project_description(cookies: Cookies) -> None: @pytest.mark.parametrize("venv_install_packages", ["", "neuro-cli", "neuro-all"]) def test_user_role_added( - tmpdir: py.path.local, venv_install_packages: str, monkeypatch: pytest.MonkeyPatch + tmp_path: Path, venv_install_packages: str, monkeypatch: pytest.MonkeyPatch ) -> None: cwd = Path(os.getcwd()) @@ -145,11 +149,18 @@ def test_user_role_added( venv.install_package(venv_install_packages, installer="pip") venv.run( - ("cookiecutter", cwd, "-o", tmpdir, "--no-input", "--default-config"), + ( + "cookiecutter", + cwd, + "-o", + str(tmp_path), + "--no-input", + "--default-config", + ), capture=True, ) proj_yml = yaml.safe_load( - Path(tmpdir / "neuro project" / ".neuro" / "project.yml").read_text() + Path(tmp_path / "neuro project" / ".neuro" / "project.yml").read_text() ) if venv_install_packages: From a4b2311cb8e4c581052d816b0df3f7f8cab9d275 Mon Sep 17 00:00:00 2001 From: Andrii Khomiak Date: Mon, 13 Jun 2022 18:17:55 +0300 Subject: [PATCH 03/12] test: Intercept yaml parsing --- tests/unit/test_bake_project.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/unit/test_bake_project.py b/tests/unit/test_bake_project.py index 7bd6c73f..8c9de85b 100644 --- a/tests/unit/test_bake_project.py +++ b/tests/unit/test_bake_project.py @@ -17,6 +17,24 @@ logger = logging.getLogger(__name__) +def patch_yaml_safe_load() -> None: + """Make yaml safe load print the file contents before parsing""" + old_impl = yaml.safe_load + + def safe_load(file): + if isinstance(file, str): + data = file + else: + data = f"#{file.name}\n{Path(file.name).read_text()}" + print(f"yaml.safe_load: got input: {data}") + return old_impl(file) + + yaml.safe_load = safe_load + + +patch_yaml_safe_load() + + def test_project_tree(cookies: Cookies) -> None: result = cookies.bake(extra_context={"project_dir": "test-project"}) assert result.exception is None From 6bb9f5ca0b09d90e0e45e7828df89716ff859264 Mon Sep 17 00:00:00 2001 From: Andrii Khomiak Date: Mon, 13 Jun 2022 18:24:19 +0300 Subject: [PATCH 04/12] test: Add type: ignore --- tests/unit/test_bake_project.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/test_bake_project.py b/tests/unit/test_bake_project.py index 8c9de85b..5d5dffcc 100644 --- a/tests/unit/test_bake_project.py +++ b/tests/unit/test_bake_project.py @@ -21,7 +21,7 @@ def patch_yaml_safe_load() -> None: """Make yaml safe load print the file contents before parsing""" old_impl = yaml.safe_load - def safe_load(file): + def safe_load(file): # type: ignore if isinstance(file, str): data = file else: From 3f7ccc09692a3d81384d39a2f2c38af2d91d7dc2 Mon Sep 17 00:00:00 2001 From: Andrii Khomiak Date: Mon, 13 Jun 2022 18:33:02 +0300 Subject: [PATCH 05/12] test: Intercept yaml parsing --- tests/unit/test_bake_project.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/unit/test_bake_project.py b/tests/unit/test_bake_project.py index 5d5dffcc..32623574 100644 --- a/tests/unit/test_bake_project.py +++ b/tests/unit/test_bake_project.py @@ -27,6 +27,7 @@ def safe_load(file): # type: ignore else: data = f"#{file.name}\n{Path(file.name).read_text()}" print(f"yaml.safe_load: got input: {data}") + print(old_impl(data)) return old_impl(file) yaml.safe_load = safe_load From 0626eb51d044f24ce65df67f85393db8eebbf563 Mon Sep 17 00:00:00 2001 From: Andrii Khomiak Date: Mon, 13 Jun 2022 18:46:00 +0300 Subject: [PATCH 06/12] test: Intercept yaml parsing --- tests/unit/test_bake_project.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/unit/test_bake_project.py b/tests/unit/test_bake_project.py index 32623574..d0a293db 100644 --- a/tests/unit/test_bake_project.py +++ b/tests/unit/test_bake_project.py @@ -10,6 +10,7 @@ from pipx.constants import DEFAULT_PIPX_BIN_DIR, LOCAL_BIN_DIR from pytest_cookies.plugin import Cookies # type: ignore from pytest_virtualenv import VirtualEnv +from yaml import YAMLError from tests.utils import inside_dir @@ -27,7 +28,10 @@ def safe_load(file): # type: ignore else: data = f"#{file.name}\n{Path(file.name).read_text()}" print(f"yaml.safe_load: got input: {data}") - print(old_impl(data)) + try: + print(old_impl(data)) + except YAMLError as e: + logger.error(e) return old_impl(file) yaml.safe_load = safe_load From 47f55e220d1e181700e99fc78c3b4887345b2733 Mon Sep 17 00:00:00 2001 From: Andrii Khomiak Date: Tue, 14 Jun 2022 13:15:13 +0300 Subject: [PATCH 07/12] test: Patch user config template --- tests/unit/test_bake_project.py | 29 +++++++---------------------- 1 file changed, 7 insertions(+), 22 deletions(-) diff --git a/tests/unit/test_bake_project.py b/tests/unit/test_bake_project.py index d0a293db..6e174ba6 100644 --- a/tests/unit/test_bake_project.py +++ b/tests/unit/test_bake_project.py @@ -8,36 +8,21 @@ import yaml from cookiecutter.exceptions import FailedHookException from pipx.constants import DEFAULT_PIPX_BIN_DIR, LOCAL_BIN_DIR +from pytest_cookies import plugin as cookies_plugin from pytest_cookies.plugin import Cookies # type: ignore from pytest_virtualenv import VirtualEnv -from yaml import YAMLError from tests.utils import inside_dir logger = logging.getLogger(__name__) - -def patch_yaml_safe_load() -> None: - """Make yaml safe load print the file contents before parsing""" - old_impl = yaml.safe_load - - def safe_load(file): # type: ignore - if isinstance(file, str): - data = file - else: - data = f"#{file.name}\n{Path(file.name).read_text()}" - print(f"yaml.safe_load: got input: {data}") - try: - print(old_impl(data)) - except YAMLError as e: - logger.error(e) - return old_impl(file) - - yaml.safe_load = safe_load - - -patch_yaml_safe_load() +# patch config to be pyyaml-friendly +# TODO: remove after https://github.com/hackebrot/pytest-cookies/pull/61 is merged +cookies_plugin.USER_CONFIG = """ +cookiecutters_dir: '{cookiecutters_dir}' +replay_dir: '{replay_dir}' +""" def test_project_tree(cookies: Cookies) -> None: From b1f27334d0befc6024c915239d42f673e2ccf565 Mon Sep 17 00:00:00 2001 From: Andrii Khomiak Date: Tue, 14 Jun 2022 13:30:43 +0300 Subject: [PATCH 08/12] test: Fix lint --- tests/unit/test_bake_project.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/test_bake_project.py b/tests/unit/test_bake_project.py index 6e174ba6..ad08d311 100644 --- a/tests/unit/test_bake_project.py +++ b/tests/unit/test_bake_project.py @@ -8,7 +8,7 @@ import yaml from cookiecutter.exceptions import FailedHookException from pipx.constants import DEFAULT_PIPX_BIN_DIR, LOCAL_BIN_DIR -from pytest_cookies import plugin as cookies_plugin +from pytest_cookies import plugin as cookies_plugin # type: ignore from pytest_cookies.plugin import Cookies # type: ignore from pytest_virtualenv import VirtualEnv From 1bc20806389fca1e6492a7e25523652d4f38db7b Mon Sep 17 00:00:00 2001 From: Andrii Khomiak Date: Tue, 14 Jun 2022 14:02:17 +0300 Subject: [PATCH 09/12] test: Patch user config template in every test --- tests/unit/test_bake_project.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/tests/unit/test_bake_project.py b/tests/unit/test_bake_project.py index ad08d311..ae10ef67 100644 --- a/tests/unit/test_bake_project.py +++ b/tests/unit/test_bake_project.py @@ -17,15 +17,18 @@ logger = logging.getLogger(__name__) -# patch config to be pyyaml-friendly -# TODO: remove after https://github.com/hackebrot/pytest-cookies/pull/61 is merged -cookies_plugin.USER_CONFIG = """ -cookiecutters_dir: '{cookiecutters_dir}' -replay_dir: '{replay_dir}' -""" + +def patch_config_template() -> None: + # patch config to be pyyaml-friendly + # TODO: remove after https://github.com/hackebrot/pytest-cookies/pull/61 is merged + cookies_plugin.USER_CONFIG = """ + cookiecutters_dir: '{cookiecutters_dir}' + replay_dir: '{replay_dir}' + """ def test_project_tree(cookies: Cookies) -> None: + patch_config_template() result = cookies.bake(extra_context={"project_dir": "test-project"}) assert result.exception is None assert result.exit_code == 0 @@ -33,6 +36,7 @@ def test_project_tree(cookies: Cookies) -> None: def test_run_flake8(cookies: Cookies) -> None: + patch_config_template() result = cookies.bake(extra_context={"project_dir": "flake8-compat"}) assert result.exception is None with inside_dir(str(result.project_path)): @@ -40,6 +44,7 @@ def test_run_flake8(cookies: Cookies) -> None: def test_project_dir_hook(cookies: Cookies) -> None: + patch_config_template() result = cookies.bake(extra_context={"project_dir": "myproject"}) assert result.exit_code == 0 result = cookies.bake(extra_context={"project_dir": "my-project"}) @@ -59,6 +64,7 @@ def test_project_dir_hook(cookies: Cookies) -> None: def test_project_id_hook(cookies: Cookies) -> None: + patch_config_template() wrong_ids = [ "qwe/qwe", "qwe?qwe", @@ -94,6 +100,7 @@ def test_project_id_hook(cookies: Cookies) -> None: @pytest.mark.parametrize("preserve_comments", ["yes", "no"]) def test_project_config_with_comments(cookies: Cookies, preserve_comments: str) -> None: + patch_config_template() result = cookies.bake( extra_context={ "project_dir": "project-with-comments", @@ -121,6 +128,7 @@ def test_project_config_with_comments(cookies: Cookies, preserve_comments: str) def test_project_description(cookies: Cookies) -> None: + patch_config_template() descriptions = [ # " ", "Descrition!", @@ -141,6 +149,7 @@ def test_project_description(cookies: Cookies) -> None: def test_user_role_added( tmp_path: Path, venv_install_packages: str, monkeypatch: pytest.MonkeyPatch ) -> None: + patch_config_template() cwd = Path(os.getcwd()) # This 'hides' neuro-cli installed via pipx From a547581ad8fa1ec92a31450fb64ad8eaddc752ab Mon Sep 17 00:00:00 2001 From: Andrii Khomiak Date: Tue, 14 Jun 2022 14:13:29 +0300 Subject: [PATCH 10/12] test: Intercept yaml parsing --- tests/unit/test_bake_project.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/unit/test_bake_project.py b/tests/unit/test_bake_project.py index ae10ef67..ed27787a 100644 --- a/tests/unit/test_bake_project.py +++ b/tests/unit/test_bake_project.py @@ -11,6 +11,7 @@ from pytest_cookies import plugin as cookies_plugin # type: ignore from pytest_cookies.plugin import Cookies # type: ignore from pytest_virtualenv import VirtualEnv +from yaml import YAMLError from tests.utils import inside_dir @@ -18,6 +19,28 @@ logger = logging.getLogger(__name__) +def patch_yaml_safe_load() -> None: + """Make yaml safe load print the file contents before parsing""" + old_impl = yaml.safe_load + + def safe_load(file): # type: ignore + if isinstance(file, str): + data = file + else: + data = f"#{file.name}\n{Path(file.name).read_text()}" + print(f"yaml.safe_load: got input: {data}") + try: + print(old_impl(data)) + except YAMLError as e: + logger.error(e) + return old_impl(file) + + yaml.safe_load = safe_load + + +patch_yaml_safe_load() + + def patch_config_template() -> None: # patch config to be pyyaml-friendly # TODO: remove after https://github.com/hackebrot/pytest-cookies/pull/61 is merged From 6e8fc2c993ebb3f4dd7f6d5efc5f24ca426a25b0 Mon Sep 17 00:00:00 2001 From: Andrii Khomiak Date: Tue, 14 Jun 2022 14:32:35 +0300 Subject: [PATCH 11/12] test: Replace pytest-cookies with a fork --- requirements/dev.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements/dev.txt b/requirements/dev.txt index 38e0b925..6852375a 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -1,6 +1,7 @@ -r base.txt black==22.1.0 flake8==4.0.1 +git+https://github.com/andriihomiak/pytest-cookies.git@fix/quotes_in_user_config isort==5.10.1 mypy==0.961 pipx==1.1.0 @@ -8,8 +9,7 @@ pre-commit==2.19.0 PyGithub==1.55 # Bump also {{cookiecutter.project_dir}}/.github/workflows/update-neuro-flow-actions.yml:15 pytest==6.2.5 pytest-asyncio==0.18.3 -pytest-cookies==0.6.1 -git+https://github.com/man-group/pytest-plugins@c2bc068#egg=pytest-virtualenv&subdirectory=pytest-virtualenv +git+https://github.com/man-group/pytest-plugins@c2bc068#egg=pytest-virtualenv&subdirectory=pytest-virtualenv # pytest-cookies==0.6.1 pytest-xdist==2.5.0 PyYAML==6.0 towncrier==21.9.0 From f7efe10ffeeae63af36b0bca809ac640f3133149 Mon Sep 17 00:00:00 2001 From: Andrii Khomiak Date: Tue, 14 Jun 2022 14:40:49 +0300 Subject: [PATCH 12/12] test: Cleanup --- requirements/dev.txt | 4 ++-- tests/unit/test_bake_project.py | 40 --------------------------------- 2 files changed, 2 insertions(+), 42 deletions(-) diff --git a/requirements/dev.txt b/requirements/dev.txt index 6852375a..93121d9b 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -1,7 +1,7 @@ -r base.txt black==22.1.0 flake8==4.0.1 -git+https://github.com/andriihomiak/pytest-cookies.git@fix/quotes_in_user_config +git+https://github.com/andriihomiak/pytest-cookies.git@fix/quotes_in_user_config # pytest-cookies==0.6.1 isort==5.10.1 mypy==0.961 pipx==1.1.0 @@ -9,7 +9,7 @@ pre-commit==2.19.0 PyGithub==1.55 # Bump also {{cookiecutter.project_dir}}/.github/workflows/update-neuro-flow-actions.yml:15 pytest==6.2.5 pytest-asyncio==0.18.3 -git+https://github.com/man-group/pytest-plugins@c2bc068#egg=pytest-virtualenv&subdirectory=pytest-virtualenv # pytest-cookies==0.6.1 +git+https://github.com/man-group/pytest-plugins@c2bc068#egg=pytest-virtualenv&subdirectory=pytest-virtualenv pytest-xdist==2.5.0 PyYAML==6.0 towncrier==21.9.0 diff --git a/tests/unit/test_bake_project.py b/tests/unit/test_bake_project.py index ed27787a..7bd6c73f 100644 --- a/tests/unit/test_bake_project.py +++ b/tests/unit/test_bake_project.py @@ -8,10 +8,8 @@ import yaml from cookiecutter.exceptions import FailedHookException from pipx.constants import DEFAULT_PIPX_BIN_DIR, LOCAL_BIN_DIR -from pytest_cookies import plugin as cookies_plugin # type: ignore from pytest_cookies.plugin import Cookies # type: ignore from pytest_virtualenv import VirtualEnv -from yaml import YAMLError from tests.utils import inside_dir @@ -19,39 +17,7 @@ logger = logging.getLogger(__name__) -def patch_yaml_safe_load() -> None: - """Make yaml safe load print the file contents before parsing""" - old_impl = yaml.safe_load - - def safe_load(file): # type: ignore - if isinstance(file, str): - data = file - else: - data = f"#{file.name}\n{Path(file.name).read_text()}" - print(f"yaml.safe_load: got input: {data}") - try: - print(old_impl(data)) - except YAMLError as e: - logger.error(e) - return old_impl(file) - - yaml.safe_load = safe_load - - -patch_yaml_safe_load() - - -def patch_config_template() -> None: - # patch config to be pyyaml-friendly - # TODO: remove after https://github.com/hackebrot/pytest-cookies/pull/61 is merged - cookies_plugin.USER_CONFIG = """ - cookiecutters_dir: '{cookiecutters_dir}' - replay_dir: '{replay_dir}' - """ - - def test_project_tree(cookies: Cookies) -> None: - patch_config_template() result = cookies.bake(extra_context={"project_dir": "test-project"}) assert result.exception is None assert result.exit_code == 0 @@ -59,7 +25,6 @@ def test_project_tree(cookies: Cookies) -> None: def test_run_flake8(cookies: Cookies) -> None: - patch_config_template() result = cookies.bake(extra_context={"project_dir": "flake8-compat"}) assert result.exception is None with inside_dir(str(result.project_path)): @@ -67,7 +32,6 @@ def test_run_flake8(cookies: Cookies) -> None: def test_project_dir_hook(cookies: Cookies) -> None: - patch_config_template() result = cookies.bake(extra_context={"project_dir": "myproject"}) assert result.exit_code == 0 result = cookies.bake(extra_context={"project_dir": "my-project"}) @@ -87,7 +51,6 @@ def test_project_dir_hook(cookies: Cookies) -> None: def test_project_id_hook(cookies: Cookies) -> None: - patch_config_template() wrong_ids = [ "qwe/qwe", "qwe?qwe", @@ -123,7 +86,6 @@ def test_project_id_hook(cookies: Cookies) -> None: @pytest.mark.parametrize("preserve_comments", ["yes", "no"]) def test_project_config_with_comments(cookies: Cookies, preserve_comments: str) -> None: - patch_config_template() result = cookies.bake( extra_context={ "project_dir": "project-with-comments", @@ -151,7 +113,6 @@ def test_project_config_with_comments(cookies: Cookies, preserve_comments: str) def test_project_description(cookies: Cookies) -> None: - patch_config_template() descriptions = [ # " ", "Descrition!", @@ -172,7 +133,6 @@ def test_project_description(cookies: Cookies) -> None: def test_user_role_added( tmp_path: Path, venv_install_packages: str, monkeypatch: pytest.MonkeyPatch ) -> None: - patch_config_template() cwd = Path(os.getcwd()) # This 'hides' neuro-cli installed via pipx