pax_global_header00006660000000000000000000000064126762732610014526gustar00rootroot0000000000000052 comment=ec250d3a721df9ebdab39ab551a912ebdcab0088 pytest-cookies-0.2.0/000077500000000000000000000000001267627326100145075ustar00rootroot00000000000000pytest-cookies-0.2.0/.gitignore000066400000000000000000000013111267627326100164730ustar00rootroot00000000000000# 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/ pytest-cookies-0.2.0/.travis.yml000066400000000000000000000005561267627326100166260ustar00rootroot00000000000000# 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 pytest-cookies-0.2.0/LICENSE000066400000000000000000000020721267627326100155150ustar00rootroot00000000000000The 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.pytest-cookies-0.2.0/Makefile000066400000000000000000000007041267627326100161500ustar00rootroot00000000000000.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/ pytest-cookies-0.2.0/README.rst000066400000000000000000000123151267627326100162000ustar00rootroot00000000000000Pytest-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/ pytest-cookies-0.2.0/appveyor.yml000066400000000000000000000020631267627326100171000ustar00rootroot00000000000000# 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 pytest-cookies-0.2.0/docs/000077500000000000000000000000001267627326100154375ustar00rootroot00000000000000pytest-cookies-0.2.0/docs/about.md000066400000000000000000000014201267627326100170700ustar00rootroot00000000000000# 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 pytest-cookies-0.2.0/docs/features.md000066400000000000000000000015251267627326100176020ustar00rootroot00000000000000# 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 pytest-cookies-0.2.0/docs/getting_started.md000066400000000000000000000023261267627326100211530ustar00rootroot00000000000000# 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 pytest-cookies-0.2.0/docs/index.md000066400000000000000000000030301267627326100170640ustar00rootroot00000000000000# 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) ![Cookiecutter Logo](https://raw.github.com/audreyr/cookiecutter/aa309b73bdc974788ba265d843a65bb94c2e608e/cookiecutter_medium.png) [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 pytest-cookies-0.2.0/mkdocs.yml000066400000000000000000000004561267627326100165170ustar00rootroot00000000000000site_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 pytest-cookies-0.2.0/pytest_cookies.py000066400000000000000000000055371267627326100201370ustar00rootroot00000000000000# -*- 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 ''.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) @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 @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', ) pytest-cookies-0.2.0/setup.cfg000066400000000000000000000002071267627326100163270ustar00rootroot00000000000000[bumpversion] current_version = 0.2.0 commit = True tag = True tag_name = {new_version} files = setup.py [bdist_wheel] universal = 1 pytest-cookies-0.2.0/setup.py000066400000000000000000000030621267627326100162220ustar00rootroot00000000000000#!/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@hackebrot.de', maintainer='Raphael Pierzina', maintainer_email='raphael@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'], ) pytest-cookies-0.2.0/tests/000077500000000000000000000000001267627326100156515ustar00rootroot00000000000000pytest-cookies-0.2.0/tests/conftest.py000066400000000000000000000000341267627326100200450ustar00rootroot00000000000000pytest_plugins = 'pytester' pytest-cookies-0.2.0/tests/test_cookies.py000066400000000000000000000067521267627326100207300ustar00rootroot00000000000000# -*- 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) == ''.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', ]) pytest-cookies-0.2.0/tests/test_help_message.py000066400000000000000000000004021267627326100217120ustar00rootroot00000000000000# -*- 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*', ]) pytest-cookies-0.2.0/tests/test_user_config.py000066400000000000000000000025601267627326100215700ustar00rootroot00000000000000# -*- 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 pytest-cookies-0.2.0/tox.ini000066400000000000000000000002771267627326100160300ustar00rootroot00000000000000[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