[Python-modules-commits] [pytest-cookies] 01/02: Imported Upstream version 0.2.0
Hugo Lefeuvre
hle at moszumanska.debian.org
Sat Sep 10 13:12:19 UTC 2016
This is an automated email from the git hooks/post-receive script.
hle pushed a commit to branch master
in repository pytest-cookies.
commit 0cbc094cf8d1b5c5ccfbf8dc032c8e200f2853d0
Author: Hugo Lefeuvre <hle at debian.org>
Date: Sat Sep 10 15:11:36 2016 +0200
Imported Upstream version 0.2.0
---
.gitignore | 58 +++++++++++++++++++
.travis.yml | 24 ++++++++
LICENSE | 21 +++++++
Makefile | 21 +++++++
README.rst | 139 +++++++++++++++++++++++++++++++++++++++++++++
appveyor.yml | 43 ++++++++++++++
docs/about.md | 22 +++++++
docs/features.md | 22 +++++++
docs/getting_started.md | 38 +++++++++++++
docs/index.md | 29 ++++++++++
mkdocs.yml | 13 +++++
pytest_cookies.py | 106 ++++++++++++++++++++++++++++++++++
setup.cfg | 10 ++++
setup.py | 52 +++++++++++++++++
tests/conftest.py | 1 +
tests/test_cookies.py | 112 ++++++++++++++++++++++++++++++++++++
tests/test_help_message.py | 12 ++++
tests/test_user_config.py | 46 +++++++++++++++
tox.ini | 10 ++++
19 files changed, 779 insertions(+)
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..a65d046
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,58 @@
+# Byte-compiled / optimized / DLL files
+__pycache__/
+*.py[cod]
+*$py.class
+
+# C extensions
+*.so
+
+# Distribution / packaging
+.Python
+env/
+build/
+develop-eggs/
+dist/
+downloads/
+eggs/
+.eggs/
+lib/
+lib64/
+parts/
+sdist/
+var/
+*.egg-info/
+.installed.cfg
+*.egg
+
+# PyInstaller
+# Usually these files are written by a python script from a template
+# before PyInstaller builds the exe, so as to inject date/other infos into it.
+*.manifest
+*.spec
+
+# Installer logs
+pip-log.txt
+pip-delete-this-directory.txt
+
+# Unit test / coverage reports
+htmlcov/
+.tox/
+.coverage
+.coverage.*
+.cache
+nosetests.xml
+coverage.xml
+*,cover
+
+# Translations
+*.mo
+*.pot
+
+# Django stuff:
+*.log
+
+# Sphinx documentation
+docs/_build/
+
+# PyBuilder
+target/
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..2b960df
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,24 @@
+# Config file for automatic testing at travis-ci.org
+
+sudo: false
+language: python
+python: 3.5
+env:
+ - TOX_ENV=py27
+ - TOX_ENV=py33
+ - TOX_ENV=py34
+ - TOX_ENV=py35
+ - TOX_ENV=pypy
+ - TOX_ENV=flake8
+
+install:
+ - pip install tox
+
+script: tox -e $TOX_ENV
+
+before_cache:
+ - rm -rf $HOME/.cache/pip/log
+
+cache:
+ directories:
+ - $HOME/.cache/pip
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..fc7a41e
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,21 @@
+The MIT License (MIT)
+
+Copyright (c) 2015 Raphael Pierzina
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
\ No newline at end of file
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..e35d784
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,21 @@
+.PHONY: clean-py clean-build clean-tox
+
+help:
+ @echo "clean-build - remove build artifacts"
+ @echo "clean-py - remove Python file artifacts"
+ @echo "clean-tox - remove tox file artifacts"
+ @echo "clean remove all file artifacts"
+
+clean: clean-tox clean-build clean-py
+
+clean-build:
+ rm -rf build/
+ rm -rf dist/
+ rm -rf *.egg-info
+
+clean-py:
+ find . -type f -name "*.py[co]" -delete
+ find . -type d -name "__pycache__" -delete
+
+clean-tox:
+ rm -rf .tox/
diff --git a/README.rst b/README.rst
new file mode 100644
index 0000000..b43a6bb
--- /dev/null
+++ b/README.rst
@@ -0,0 +1,139 @@
+Pytest-Cookies
+==============
+
+|gitter| |pypi| |pyversions| |license| |rtfd| |travis-ci| |appveyor|
+
+.. |gitter| image:: https://badges.gitter.im/Join%20Chat.svg
+ :alt: Join the chat at https://gitter.im/hackebrot/pytest-cookies
+ :target: https://gitter.im/hackebrot/pytest-cookies?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge
+
+.. |pypi| image:: https://img.shields.io/pypi/v/pytest-cookies.svg
+ :target: https://pypi.python.org/pypi/pytest-cookies
+ :alt: PyPI Package
+
+.. |pyversions| image:: https://img.shields.io/pypi/pyversions/pytest-cookies.svg
+ :target: https://pypi.python.org/pypi/pytest-cookies/
+ :alt: PyPI Python Versions
+
+.. |license| image:: https://img.shields.io/pypi/l/pytest-cookies.svg
+ :target: https://pypi.python.org/pypi/pytest-cookies
+ :alt: PyPI Package License
+
+.. |rtfd| image:: https://readthedocs.org/projects/pytest-cookies/badge/?version=latest
+ :target: http://pytest-cookies.readthedocs.org/en/latest/?badge=latest
+ :alt: Documentation Status
+
+.. |travis-ci| image:: https://travis-ci.org/hackebrot/pytest-cookies.svg?branch=master
+ :target: https://travis-ci.org/hackebrot/pytest-cookies
+ :alt: See Build Status on Travis CI
+
+.. |appveyor| image:: https://ci.appveyor.com/api/projects/status/github/hackebrot/pytest-cookies?branch=master
+ :target: https://ci.appveyor.com/project/hackebrot/pytest-cookies/branch/master
+ :alt: See Build Status on AppVeyor
+
+`pytest`_ is a mature full-featured Python testing tool that provides easy
+no boilerplate testing. Its hook-based customization system supports integration
+of external plugins such as **pytest-cookies**.
+
+This plugin comes with a ``cookies`` fixture which is a wrapper for the
+`cookiecutter`_ API for generating projects. It helps you verify that your
+template is working as expected and takes care of cleaning up after running the
+tests.
+
+.. image:: https://raw.github.com/audreyr/cookiecutter/aa309b73bdc974788ba265d843a65bb94c2e608e/cookiecutter_medium.png
+
+
+Installation
+------------
+
+**pytest-cookies** is available for download from `PyPI`_ via `pip`_::
+
+ $ pip install pytest-cookies
+
+It will automatically install `pytest`_ along with `cookiecutter`_.
+
+Usage
+-----
+
+The ``cookies.bake()`` method generates a new project from your template based on the
+default values specified in ``cookiecutter.json``:
+
+.. code-block:: python
+
+ def test_bake_project(cookies):
+ result = cookies.bake(extra_context={'repo_name': 'helloworld'})
+
+ assert result.exit_code == 0
+ assert result.exception is None
+ assert result.project.basename == 'helloworld'
+ assert result.project.isdir()
+
+It accepts the ``extra_context`` keyword argument that will be
+passed to cookiecutter. The given dictionary will override the default values
+of the template context, allowing you to test arbitrary user input data.
+
+Please see the `Injecting Extra Context`_ section of the
+official cookiecutter documentation.
+
+Features
+--------
+
+``cookies.bake()`` returns a result instance with a bunch of fields that
+hold useful information:
+
+* ``exit_code``: is the exit code of cookiecutter, ``0`` means successful termination
+* ``exception``: is the exception that happened if one did
+* ``project``: a `py.path.local`_ object pointing to the rendered project
+
+The returned ``LocalPath`` instance provides you with a powerful interface
+to filesystem related information, that comes in handy for validating the generated
+project layout and even file contents:
+
+.. code-block:: python
+
+ def test_readme(cookies):
+ result = cookies.bake()
+
+ readme_file = result.project.join('README.rst')
+ readme_lines = readme_file.readlines(cr=False)
+ assert readme_lines == ['helloworld', '==========']
+
+Issues
+------
+
+If you encounter any problems, please `file an issue`_ along with a detailed description.
+
+Contributing
+------------
+Contributions are very welcome! Tests can be run with `tox`_, please make sure
+all of the tests are green before you submit a pull request.
+
+Code of Conduct
+---------------
+
+Everyone interacting in the Pytest-Cookies project's codebases, issue trackers, chat
+rooms, and mailing lists is expected to follow the `PyPA Code of Conduct`_.
+
+License
+-------
+
+Distributed under the terms of the `MIT`_ license, Pytest-Cookies is free and open source software
+
+.. image:: https://opensource.org/trademarks/osi-certified/web/osi-certified-120x100.png
+ :align: left
+ :alt: OSI certified
+ :target: https://opensource.org/
+
+
+.. _`cookiecutter`: https://github.com/audreyr/cookiecutter
+.. _`@hackebrot`: https://github.com/hackebrot
+.. _`MIT`: http://opensource.org/licenses/MIT
+.. _`cookiecutter-pytest-plugin`: https://github.com/pytest-dev/cookiecutter-pytest-plugin
+.. _`file an issue`: https://github.com/hackebrot/pytest-cookies/issues
+.. _`pytest`: https://github.com/pytest-dev/pytest
+.. _`tox`: https://tox.readthedocs.org/en/latest/
+.. _`pip`: https://pypi.python.org/pypi/pip/
+.. _`PyPI`: https://pypi.python.org/pypi
+.. _`Injecting Extra Context`: http://cookiecutter.readthedocs.org/en/latest/advanced_usage.html#injecting-extra-context
+.. _`py.path.local`: http://pylib.readthedocs.org/en/latest/path.html#py._path.local.LocalPath
+.. _`PyPA Code of Conduct`: https://www.pypa.io/en/latest/code-of-conduct/
diff --git a/appveyor.yml b/appveyor.yml
new file mode 100644
index 0000000..967fdf7
--- /dev/null
+++ b/appveyor.yml
@@ -0,0 +1,43 @@
+# What Python version is installed where:
+# http://www.appveyor.com/docs/installed-software#python
+
+environment:
+ matrix:
+ - PYTHON: "C:\\Python27-x64"
+ TOX_ENV: "py27"
+
+ - PYTHON: "C:\\Python33-x64"
+ TOX_ENV: "py33"
+
+ - PYTHON: "C:\\Python34-x64"
+ TOX_ENV: "py34"
+
+ - PYTHON: "C:\\Python35-x64"
+ TOX_ENV: "py35"
+
+
+init:
+ - "%PYTHON%/python -V"
+ - "%PYTHON%/python -c \"import struct;print( 8 * struct.calcsize(\'P\'))\""
+ - "%PYTHON%/python -c \"import sys;print(sys.version_info[0] == 2)\""
+ - "%PYTHON%/python -c \"import platform;print(platform.system().lower().startswith(\'windows\'))\""
+
+install:
+ - "%PYTHON%/Scripts/easy_install -U pip"
+ - "%PYTHON%/Scripts/pip install tox"
+ - "%PYTHON%/Scripts/pip install wheel"
+
+build: false # Not a C# project, build stuff at the test step instead.
+
+test_script:
+ - "%PYTHON%/Scripts/tox -e %TOX_ENV%"
+
+after_test:
+ - "%PYTHON%/python setup.py bdist_wheel"
+ - ps: "ls dist"
+
+artifacts:
+ - path: dist\*
+
+#on_success:
+# - TODO: upload the content of dist/*.whl to a public wheelhouse
diff --git a/docs/about.md b/docs/about.md
new file mode 100644
index 0000000..578455d
--- /dev/null
+++ b/docs/about.md
@@ -0,0 +1,22 @@
+# Issues
+
+If you encounter any problems, please [file an issue] along with a detailed description.
+
+# Contributing
+
+Contributions are very welcome! Tests can be run with [tox], please make sure
+all of the tests are green before you submit a pull request.
+
+# Code of Conduct
+
+Everyone interacting in the Pyest-Cookies project's codebases, issue trackers, chat
+rooms, and mailing lists is expected to follow the [PyPA Code of Conduct].
+
+# License
+
+Distributed under the terms of the [MIT] license, **pytest-cookies** is free and open source software
+
+ [file an issue]: https://github.com/hackebrot/pytest-cookies/issues
+ [tox]: https://tox.readthedocs.org/en/latest/
+ [PyPA Code of Conduct]: https://www.pypa.io/en/latest/code-of-conduct/
+ [MIT]: http://opensource.org/licenses/MIT
diff --git a/docs/features.md b/docs/features.md
new file mode 100644
index 0000000..bfefffe
--- /dev/null
+++ b/docs/features.md
@@ -0,0 +1,22 @@
+# Bake Result
+
+``cookies.bake()`` returns a result instance with a bunch of fields that
+hold useful information:
+
+* ``exit_code``: is the exit code of cookiecutter, ``0`` means successful termination
+* ``exception``: is the exception that happened if one did
+* ``project``: a [py.path.local] object pointing to the rendered project
+
+The returned ``LocalPath`` instance provides you with a powerful interface
+to filesystem related information, that comes in handy for validating the generated
+project layout and even file contents:
+
+```python
+def test_readme(cookies):
+ result = cookies.bake()
+
+ readme_file = result.project.join('README.rst')
+ readme_lines = readme_file.readlines(cr=False)
+ assert readme_lines == ['helloworld', '==========']
+```
+ [py.path.local]: http://pylib.readthedocs.org/en/latest/path.html#py._path.local.LocalPath
diff --git a/docs/getting_started.md b/docs/getting_started.md
new file mode 100644
index 0000000..0907ca3
--- /dev/null
+++ b/docs/getting_started.md
@@ -0,0 +1,38 @@
+# Installation
+
+**pytest-cookies** is available for download from [PyPI] via [pip]:
+
+```no-highlight
+$ pip install pytest-cookies
+```
+
+It will automatically install [pytest] along with [cookiecutter].
+
+ [PyPI]: https://pypi.python.org/pypi
+ [cookiecutter]: https://github.com/audreyr/cookiecutter
+ [pip]: https://pypi.python.org/pypi/pip/
+ [pytest]: https://github.com/pytest-dev/pytest
+
+# Usage
+
+The ``cookies.bake()`` method generates a new project from your template based on the
+default values specified in ``cookiecutter.json``:
+
+```python
+def test_bake_project(cookies):
+ result = cookies.bake(extra_context={'repo_name': 'helloworld'})
+
+ assert result.exit_code == 0
+ assert result.exception is None
+ assert result.project.basename == 'helloworld'
+ assert result.project.isdir()
+```
+
+It accepts the ``extra_context`` keyword argument that will be
+passed to cookiecutter. The given dictionary will override the default values
+of the template context, allowing you to test arbitrary user input data.
+
+Please see the [Injecting Extra Context] section of the
+official cookiecutter documentation.
+
+ [Injecting Extra Context]: http://cookiecutter.readthedocs.org/en/latest/advanced_usage.html#injecting-extra-context
diff --git a/docs/index.md b/docs/index.md
new file mode 100644
index 0000000..5a58df1
--- /dev/null
+++ b/docs/index.md
@@ -0,0 +1,29 @@
+# Welcome to Pytest-Cookies
+
+[![Join Chat on Gitter.im][gitter_badge]][gitter]
+
+[pytest] is a mature full-featured Python testing tool that provides easy
+no boilerplate testing. Its hook-baesd customization system supports integration
+of external plugins such as **pytest-cookies**.
+
+This plugin comes with a ``cookies`` fixture which is a wrapper for the
+[cookiecutter] API for generating projects. It helps you verify that your
+template is working as expected and takes care of cleaning up after running the
+tests.
+
+## GitHub Project
+
+[https://github.com/hackebrot/pytest-cookies](https://github.com/hackebrot/pytest-cookies)
+
+
+
+ [gitter_badge]: https://badges.gitter.im/Join%20Chat.svg
+ [gitter]: https://gitter.im/hackebrot/pytest-cookies?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge
+ [travis_badge]: https://travis-ci.org/hackebrot/pytest-cookies.svg?branch=master
+ [travis]: https://travis-ci.org/hackebrot/pytest-cookies
+ [appveyor_badge]: https://ci.appveyor.com/api/projects/status/github/hackebrot/pytest-cookies?branch=master
+ [appveyor]: https://ci.appveyor.com/project/hackebrot/pytest-cookies/branch/master
+ [docs_badge]: https://readthedocs.org/projects/pytest-cookies/badge/?version=latest
+ [documentation]: http://pytest-cookies.readthedocs.org/en/latest/?badge=latest
+ [pytest]: https://github.com/pytest-dev/pytest
+ [cookiecutter]: https://github.com/audreyr/cookiecutter
diff --git a/mkdocs.yml b/mkdocs.yml
new file mode 100644
index 0000000..1ad88a9
--- /dev/null
+++ b/mkdocs.yml
@@ -0,0 +1,13 @@
+site_name: pytest-cookies
+site_description: A Pytest plugin for your Cookiecutter templates
+site_author: Raphael Pierzina
+
+theme: readthedocs
+
+repo_url: https://github.com/hackebrot/pytest-cookies
+
+pages:
+- Home: index.md
+- Getting Started: getting_started.md
+- Features: features.md
+- About: about.md
diff --git a/pytest_cookies.py b/pytest_cookies.py
new file mode 100644
index 0000000..d68591b
--- /dev/null
+++ b/pytest_cookies.py
@@ -0,0 +1,106 @@
+# -*- coding: utf-8 -*-
+
+import py
+import pytest
+
+from cookiecutter.main import cookiecutter
+
+USER_CONFIG = u"""
+cookiecutters_dir: "{cookiecutters_dir}"
+replay_dir: "{replay_dir}"
+"""
+
+
+class Result(object):
+ """Holds the captured result of the cookiecutter project generation."""
+
+ def __init__(self, exception=None, exit_code=0, project_dir=None):
+ self.exception = exception
+ self.exit_code = exit_code
+ self._project_dir = project_dir
+
+ @property
+ def project(self):
+ if self.exception is None:
+ return py.path.local(self._project_dir)
+ return None
+
+ def __repr__(self):
+ return '<Result {}>'.format(
+ self.exception and repr(self.exception) or self.project
+ )
+
+
+class Cookies(object):
+ """Class to provide convenient access to the cookiecutter API."""
+
+ def __init__(self, template, output_factory, config_file):
+ self._template = template
+ self._output_factory = output_factory
+ self._config_file = config_file
+ self._counter = 0
+
+ def _new_output_dir(self):
+ dirname = 'bake{:02d}'.format(self._counter)
+ output_dir = self._output_factory(dirname)
+ self._counter += 1
+ return str(output_dir)
+
+ def bake(self, extra_context=None):
+ exception = None
+ exit_code = 0
+ project_dir = None
+
+ try:
+ project_dir = cookiecutter(
+ self._template,
+ no_input=True,
+ extra_context=extra_context,
+ output_dir=self._new_output_dir(),
+ config_file=str(self._config_file)
+ )
+ except SystemExit as e:
+ if e.code != 0:
+ exception = e
+ exit_code = e.code
+ except Exception as e:
+ exception = e
+ exit_code = -1
+
+ return Result(exception, exit_code, project_dir)
+
+
+ at pytest.fixture(scope='session')
+def _cookiecutter_config_file(tmpdir_factory):
+ user_dir = tmpdir_factory.mktemp('user_dir')
+
+ cookiecutters_dir = user_dir.mkdir('cookiecutters')
+ replay_dir = user_dir.mkdir('cookiecutter_replay')
+
+ config_text = USER_CONFIG.format(
+ cookiecutters_dir=cookiecutters_dir,
+ replay_dir=replay_dir,
+ )
+ config_file = user_dir.join('config')
+
+ config_file.write_text(config_text, encoding='utf8')
+ return config_file
+
+
+ at pytest.fixture
+def cookies(request, tmpdir, _cookiecutter_config_file):
+ template_dir = request.config.option.template
+ output_factory = tmpdir.mkdir('cookies').mkdir
+ return Cookies(template_dir, output_factory, _cookiecutter_config_file)
+
+
+def pytest_addoption(parser):
+ group = parser.getgroup('cookies')
+ group.addoption(
+ '--template',
+ action='store',
+ default='.',
+ dest='template',
+ help='specify the template to be rendered',
+ type='string',
+ )
diff --git a/setup.cfg b/setup.cfg
new file mode 100644
index 0000000..1ab82a8
--- /dev/null
+++ b/setup.cfg
@@ -0,0 +1,10 @@
+[bumpversion]
+current_version = 0.2.0
+commit = True
+tag = True
+tag_name = {new_version}
+files = setup.py
+
+[bdist_wheel]
+universal = 1
+
diff --git a/setup.py b/setup.py
new file mode 100644
index 0000000..0b280fd
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,52 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+import os
+import codecs
+from setuptools import setup
+
+
+def read(fname):
+ file_path = os.path.join(os.path.dirname(__file__), fname)
+ return codecs.open(file_path, encoding='utf-8').read()
+
+
+setup(
+ name='pytest-cookies',
+ version='0.2.0',
+ author='Raphael Pierzina',
+ author_email='raphael at hackebrot.de',
+ maintainer='Raphael Pierzina',
+ maintainer_email='raphael at hackebrot.de',
+ license='MIT',
+ url='https://github.com/hackebrot/pytest-cookies',
+ description='A Pytest plugin for your Cookiecutter templates',
+ long_description=read('README.rst'),
+ py_modules=['pytest_cookies'],
+ install_requires=[
+ 'pytest>=2.8.1',
+ 'cookiecutter>=1.4.0'
+ ],
+ classifiers=[
+ 'Development Status :: 4 - Beta',
+ 'Intended Audience :: Developers',
+ 'License :: OSI Approved :: MIT License',
+ 'Operating System :: OS Independent',
+ 'Programming Language :: Python :: 2',
+ 'Programming Language :: Python :: 2.7',
+ 'Programming Language :: Python :: 3',
+ 'Programming Language :: Python :: 3.3',
+ 'Programming Language :: Python :: 3.4',
+ 'Programming Language :: Python :: 3.5',
+ 'Programming Language :: Python :: Implementation :: CPython',
+ 'Programming Language :: Python',
+ 'Topic :: Software Development :: Testing',
+ 'Framework :: Pytest',
+ ],
+ entry_points={
+ 'pytest11': [
+ 'cookies = pytest_cookies',
+ ],
+ },
+ keywords=['cookiecutter', 'pytest'],
+)
diff --git a/tests/conftest.py b/tests/conftest.py
new file mode 100644
index 0000000..bc711e5
--- /dev/null
+++ b/tests/conftest.py
@@ -0,0 +1 @@
+pytest_plugins = 'pytester'
diff --git a/tests/test_cookies.py b/tests/test_cookies.py
new file mode 100644
index 0000000..a41e07b
--- /dev/null
+++ b/tests/test_cookies.py
@@ -0,0 +1,112 @@
+# -*- coding: utf-8 -*-
+
+import json
+
+
+def test_cookies_fixture(testdir):
+ """Make sure that pytest accepts the `cookies` fixture."""
+
+ # create a temporary pytest test module
+ testdir.makepyfile("""
+ def test_valid_fixture(cookies):
+ assert hasattr(cookies, 'bake')
+ assert callable(cookies.bake)
+ """)
+
+ # run pytest with the following cmd args
+ result = testdir.runpytest('-v')
+
+ # fnmatch_lines does an assertion internally
+ result.stdout.fnmatch_lines([
+ '*::test_valid_fixture PASSED',
+ ])
+
+ # make sure that that we get a '0' exit code for the testsuite
+ assert result.ret == 0
+
+
+def test_cookies_bake(testdir):
+ """Programmatically create a **Cookiecutter** template and use `bake` to
+ create a project from it.
+ """
+ template = testdir.tmpdir.ensure('cookiecutter-template', dir=True)
+
+ template_config = {
+ 'repo_name': 'foobar',
+ 'short_description': 'Test Project'
+ }
+ template.join('cookiecutter.json').write(json.dumps(template_config))
+
+ template_readme = '\n'.join([
+ '{{cookiecutter.repo_name}}',
+ '{% for _ in cookiecutter.repo_name %}={% endfor %}',
+ '{{cookiecutter.short_description}}',
+ ])
+
+ repo = template.ensure('{{cookiecutter.repo_name}}', dir=True)
+ repo.join('README.rst').write(template_readme)
+
+ testdir.makepyfile("""
+ def test_bake_project(cookies):
+ result = cookies.bake(extra_context={'repo_name': 'helloworld'})
+
+ assert result.exit_code == 0
+ assert result.exception is None
+ assert result.project.basename == 'helloworld'
+ assert result.project.isdir()
+
+ assert str(result) == '<Result {}>'.format(result.project)
+
+
+ def test_bake_should_create_new_output(cookies):
+ first_result = cookies.bake()
+ assert first_result.exception is None
+ assert first_result.project.dirname.endswith('bake00')
+
+ second_result = cookies.bake()
+ assert second_result.exception is None
+ assert second_result.project.dirname.endswith('bake01')
+ """)
+
+ # run pytest with the following cmd args
+ result = testdir.runpytest('-v', '--template={}'.format(template))
+
+ # fnmatch_lines does an assertion internally
+ result.stdout.fnmatch_lines([
+ '*::test_bake_project PASSED',
+ '*::test_bake_should_create_new_output PASSED',
+ ])
+
+
+def test_cookies_bake_should_handle_exception(testdir):
+ """Programmatically create a **Cookiecutter** template and make sure that
+ cookies.bake() handles exceptions that happen during project generation.
+
+ We expect **Cookiecutter** to raise a `NonTemplatedInputDirException`.
+ """
+ template = testdir.tmpdir.ensure('cookiecutter-fail', dir=True)
+
+ template_config = {
+ 'repo_name': 'foobar',
+ 'short_description': 'Test Project'
+ }
+ template.join('cookiecutter.json').write(json.dumps(template_config))
+
+ template.ensure('cookiecutter.repo_name', dir=True)
+
+ testdir.makepyfile("""
+ def test_bake_should_fail(cookies):
+ result = cookies.bake()
+
+ assert result.exit_code == -1
+ assert result.exception is not None
+ assert result.project is None
+ """)
+
+ # run pytest with the following cmd args
+ result = testdir.runpytest('-v', '--template={}'.format(template))
+
+ # fnmatch_lines does an assertion internally
+ result.stdout.fnmatch_lines([
+ '*::test_bake_should_fail PASSED',
+ ])
diff --git a/tests/test_help_message.py b/tests/test_help_message.py
new file mode 100644
index 0000000..7de594a
--- /dev/null
+++ b/tests/test_help_message.py
@@ -0,0 +1,12 @@
+# -*- coding: utf-8 -*-
+
+
+def test_cookies_group(testdir):
+ result = testdir.runpytest(
+ '--help',
+ )
+ # fnmatch_lines does an assertion internally
+ result.stdout.fnmatch_lines([
+ 'cookies:',
+ '*--template=TEMPLATE*',
+ ])
diff --git a/tests/test_user_config.py b/tests/test_user_config.py
new file mode 100644
index 0000000..ba33818
--- /dev/null
+++ b/tests/test_user_config.py
@@ -0,0 +1,46 @@
+# -*- coding: utf-8 -*-
+
+
+def test_config(testdir):
+ """Make sure that pytest accepts the `cookies` fixture."""
+
+ # create a temporary pytest test module
+ testdir.makepyfile("""
+ import poyo
+
+
+ def test_user_dir(tmpdir_factory, _cookiecutter_config_file):
+ basetemp = tmpdir_factory.getbasetemp()
+
+ assert _cookiecutter_config_file.basename == 'config'
+
+ user_dir = _cookiecutter_config_file.dirpath()
+ assert user_dir.fnmatch('user_dir?')
+
+ assert user_dir.dirpath() == basetemp
+
+
+ def test_valid_cookiecutter_config(_cookiecutter_config_file):
+ config_text = _cookiecutter_config_file.read()
+ config = poyo.parse_string(config_text)
+
+ user_dir = _cookiecutter_config_file.dirpath()
+
+ expected = {
+ 'cookiecutters_dir': str(user_dir.join('cookiecutters')),
+ 'replay_dir': str(user_dir.join('cookiecutter_replay')),
+ }
+ assert config == expected
+ """)
+
+ # run pytest with the following cmd args
+ result = testdir.runpytest('-v')
+
+ # fnmatch_lines does an assertion internally
+ result.stdout.fnmatch_lines([
+ '*::test_user_dir PASSED',
+ '*::test_valid_cookiecutter_config PASSED',
+ ])
+
+ # make sure that that we get a '0' exit code for the testsuite
+ assert result.ret == 0
diff --git a/tox.ini b/tox.ini
new file mode 100644
index 0000000..048722d
--- /dev/null
+++ b/tox.ini
@@ -0,0 +1,10 @@
+[tox]
+envlist = py27,py33,py34,py35,pypy,flake8
+
+[testenv]
+deps = pytest
+commands = py.test {posargs:tests}
+
+[testenv:flake8]
+deps = flake8
+commands = flake8 pytest_cookies.py setup.py tests
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/pytest-cookies.git
More information about the Python-modules-commits
mailing list