Repository: hackebrot/pytest-cookies (language: python)

Issue:
Pytest-cookies fails on Windows (YAML config erroneous)

The YAML config is built by simple string formatting in https://github.com/hackebrot/pytest-cookies/blob/master/src/pytest_cookies/plugin.py

But since on Windows, filepaths use backslashes, this makes an invalid YAML file with wrong escape sequences :

```
while scanning a double-quoted scalar
  in "C:\Users\Pascal\AppData\Local\Temp\pytest-of-Pascal\pytest-67\user_dir0\config", line 2, column 20
expected escape sequence of 8 hexadecimal numbers, but found 's'
  in "C:\Users\Pascal\AppData\Local\Temp\pytest-of-Pascal\pytest-67\user_dir0\config", line 2, column 25
```

So this config should be dumped with a proper YAML parser.

For some reason, all works with old cookiecutter==1.7.2, probably the parser it uses is different



Discussion / hints:
Simplest solution that avoids adding dependencies is to dump the config as JSON, since YAML is a superset of JSON.

Fix patch:
diff --git a/.github/workflows/run-checks.yml b/.github/workflows/run-checks.yml
index 39df810..a7359df 100644
--- a/.github/workflows/run-checks.yml
+++ b/.github/workflows/run-checks.yml
@@ -8,17 +8,19 @@ jobs:
       fail-fast: false
       matrix:
         os: ["ubuntu-latest", "macos-latest", "windows-latest"]
-        environment: ["py36", "py37", "py38", "py39", "flake8"]
+        environment: ["py37", "py38", "py39", "py310", "py311", "flake8"]
 
         include:
-          - environment: "py36"
-            python: "3.6"
           - environment: "py37"
             python: "3.7"
           - environment: "py38"
             python: "3.8"
           - environment: "py39"
             python: "3.9"
+          - environment: "py310"
+            python: "3.10"
+          - environment: "py311"
+            python: "3.11"
           - environment: "flake8"
             python: "3.7"
 
diff --git a/setup.py b/setup.py
index 7fe9fdc..b7dbb38 100644
--- a/setup.py
+++ b/setup.py
@@ -13,7 +13,7 @@ def read(fname):
 
 setuptools.setup(
     name="pytest-cookies",
-    version="0.6.1",
+    version="0.7.0",
     author="Raphael Pierzina",
     author_email="raphael@hackebrot.de",
     maintainer="Raphael Pierzina",
@@ -31,10 +31,10 @@ def read(fname):
     package_dir={"": "src"},
     include_package_data=True,
     zip_safe=False,
-    python_requires=">=3.6",
+    python_requires=">=3.7",
     install_requires=[
-        "cookiecutter>=1.4.0",
-        "pytest>=3.3.0",
+        "cookiecutter>=2.1.0",  # uses pyyaml
+        "pytest>=3.9.0",  # adds tmp_path fixtures
     ],
     classifiers=[
         "Development Status :: 5 - Production/Stable",
@@ -42,10 +42,11 @@ def read(fname):
         "License :: OSI Approved :: MIT License",
         "Operating System :: OS Independent",
         "Programming Language :: Python :: 3 :: Only",
-        "Programming Language :: Python :: 3.6",
         "Programming Language :: Python :: 3.7",
         "Programming Language :: Python :: 3.8",
         "Programming Language :: Python :: 3.9",
+        "Programming Language :: Python :: 3.10",
+        "Programming Language :: Python :: 3.11",
         "Programming Language :: Python :: Implementation :: CPython",
         "Programming Language :: Python",
         "Topic :: Software Development :: Testing",
diff --git a/tox.ini b/tox.ini
index 2c0f673..bb93750 100644
--- a/tox.ini
+++ b/tox.ini
@@ -1,12 +1,12 @@
 [tox]
-envlist = py{36,37,38,39}-pytest{3,4,5,6},flake8
+envlist = py{37,38,39,310,311}-pytest{4,5,6,7},flake8
 
 [testenv]
 deps =
-  pytest3: pytest>=3,<4
   pytest4: pytest>=4,<5
   pytest5: pytest>=5,<6
   pytest6: pytest>=6,<7
+  pytest7: pytest>=7,<8
 commands = pytest {posargs:tests}
 
 [testenv:flake8]


Test patch:
diff --git a/src/pytest_cookies/plugin.py b/src/pytest_cookies/plugin.py
index 6e077c5..375ff4c 100644
--- a/src/pytest_cookies/plugin.py
+++ b/src/pytest_cookies/plugin.py
@@ -6,15 +6,12 @@
 
 import py
 import pytest
+import yaml
+
 from cookiecutter.generate import generate_context
 from cookiecutter.main import cookiecutter
 from cookiecutter.prompt import prompt_for_config
 
-USER_CONFIG = u"""
-cookiecutters_dir: "{cookiecutters_dir}"
-replay_dir: "{replay_dir}"
-"""
-
 
 class Result(object):
     """Holds the captured result of the cookiecutter project generation."""
@@ -122,16 +119,16 @@ def bake(self, extra_context=None, template=None):
 @pytest.fixture(scope="session")
 def _cookiecutter_config_file(tmpdir_factory):
     user_dir = tmpdir_factory.mktemp("user_dir")
+    config_file = user_dir.join("config")
 
-    cookiecutters_dir = user_dir.mkdir("cookiecutters")
-    replay_dir = user_dir.mkdir("cookiecutter_replay")
+    config = {
+        "cookiecutters_dir": str(user_dir.mkdir("cookiecutters")),
+        "replay_dir": str(user_dir.mkdir("cookiecutter_replay")),
+    }
 
-    config_text = USER_CONFIG.format(
-        cookiecutters_dir=cookiecutters_dir, replay_dir=replay_dir
-    )
-    config_file = user_dir.join("config")
+    with config_file.open("w", encoding="utf-8") as f:
+        yaml.dump(config, f, Dumper=yaml.Dumper)
 
-    config_file.write_text(config_text, encoding="utf8")
     return config_file
 
 
diff --git a/tests/test_user_config.py b/tests/test_user_config.py
index c28f6f7..836c771 100644
--- a/tests/test_user_config.py
+++ b/tests/test_user_config.py
@@ -9,7 +9,7 @@ def test_config(testdir):
         """
         # -*- coding: utf-8 -*-
 
-        import poyo
+        import yaml
 
 
         def test_user_dir(tmpdir_factory, _cookiecutter_config_file):
@@ -24,8 +24,8 @@ def test_user_dir(tmpdir_factory, _cookiecutter_config_file):
 
 
         def test_valid_cookiecutter_config(_cookiecutter_config_file):
-            config_text = _cookiecutter_config_file.read()
-            config = poyo.parse_string(config_text)
+            with open(_cookiecutter_config_file) as f:
+                config = yaml.load(f, Loader=yaml.Loader)
 
             user_dir = _cookiecutter_config_file.dirpath()