Skip to content

Commit

Permalink
test: Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
andriihomiak committed Jun 14, 2022
1 parent 6e8fc2c commit f7efe10
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 42 deletions.
4 changes: 2 additions & 2 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
-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
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
Expand Down
40 changes: 0 additions & 40 deletions tests/unit/test_bake_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,66 +8,30 @@
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


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
assert result.project_path.name == "test-project"


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)):
subprocess.check_call(["flake8"])


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"})
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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!",
Expand All @@ -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
Expand Down

0 comments on commit f7efe10

Please sign in to comment.