pytest-tempdir-2016.8.20/0000755000175000017500000000000012756061154015633 5ustar vampasvampas00000000000000pytest-tempdir-2016.8.20/PKG-INFO0000644000175000017500000001155112756061154016733 0ustar vampasvampas00000000000000Metadata-Version: 1.1 Name: pytest-tempdir Version: 2016.8.20 Summary: Predictable and repeatable tempdir support. Home-page: https://github.com/saltstack/pytest-tempdir Author: Pedro Algarvio Author-email: pedro@algarvio.me License: Apache Software License 2.0 Description: pytest-tempdir ============== .. image:: https://travis-ci.org/saltstack/pytest-tempdir.svg?branch=master :target: https://travis-ci.org/saltstack/pytest-tempdir :alt: See Build Status on Travis CI .. image:: https://ci.appveyor.com/api/projects/status/github/saltstack/pytest-tempdir?branch=master :target: https://ci.appveyor.com/project/saltstack-public/pytest-tempdir/branch/master :alt: See Build Status on AppVeyor .. image:: http://img.shields.io/pypi/v/pytest-tempdir.svg :target: https://pypi.python.org/pypi/pytest-tempdir Adds support for a predictable and repeatable temporary directory. ---- This `Pytest`_ plugin was generated with `Cookiecutter`_ along with `@hackebrot`_'s `Cookiecutter-pytest-plugin`_ template. Features -------- * Adds support for a predictable and repeatable temporary directory through the `tempdir` fixture which gets cleaned up in the end of the test run session(this behaviour can be disabled). Requirements ------------ * None! Installation ------------ You can install "pytest-tempdir" via `pip`_ from `PyPI`_:: $ pip install pytest-tempdir Usage ----- * Simply define a ``pytest_tempdir_basename`` function on your ``conftest.py`` which returns a string to define the basename or pass ``--tempdir-basename``. * If you wish to leave the temporary directory intact for further inspection after the tests suite ends, pass ``--tempdir-no-clean``. Contributing ------------ Contributions are very welcome. Tests can be run with `tox`_, please ensure the coverage at least stays the same before you submit a pull request. License ------- Distributed under the terms of the `Apache 2.0`_ license, "pytest-tempdir" is free and open source software Issues ------ If you encounter any problems, please `file an issue`_ along with a detailed description. Changelog --------- v2016.8.20 ~~~~~~~~~~ * Support pytest 2.x and 3.x v2015.12.6 ~~~~~~~~~~ * Each absolute path gets it's own counter v2015.11.29 ~~~~~~~~~~~ * Append a counter value to existing directory names v2015.11.17 ~~~~~~~~~~~ * Fix more encoding issues when running setup and the system locale is not set v2015.11.16 ~~~~~~~~~~~ * Fix encoding issue when running setup and the system locale is not set v2015.11.8 ~~~~~~~~~~ * Fix stale tempdir cleanup logic v2015.11.6 ~~~~~~~~~~ * Wipe the tempdir directory on test session start if it exists v2015.11.4 ~~~~~~~~~~ * First working release .. _`Cookiecutter`: https://github.com/audreyr/cookiecutter .. _`@hackebrot`: https://github.com/hackebrot .. _`cookiecutter-pytest-plugin`: https://github.com/pytest-dev/cookiecutter-pytest-plugin .. _`file an issue`: https://github.com/saltstack/pytest-tempdir/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 .. _`Apache 2.0`: http://www.apache.org/licenses/LICENSE-2.0 Platform: UNKNOWN Classifier: Development Status :: 4 - Beta Classifier: Intended Audience :: Developers Classifier: Topic :: Software Development :: Testing Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 2 Classifier: Programming Language :: Python :: 2.7 Classifier: Programming Language :: Python :: 3 Classifier: Programming Language :: Python :: 3.3 Classifier: Programming Language :: Python :: 3.4 Classifier: Programming Language :: Python :: 3.5 Classifier: Programming Language :: Python :: Implementation :: CPython Classifier: Programming Language :: Python :: Implementation :: PyPy Classifier: Operating System :: OS Independent Classifier: License :: OSI Approved :: Apache Software License pytest-tempdir-2016.8.20/pytest_tempdir/0000755000175000017500000000000012756061154020707 5ustar vampasvampas00000000000000pytest-tempdir-2016.8.20/pytest_tempdir/plugin.py0000644000175000017500000001261612756031636022567 0ustar vampasvampas00000000000000# -*- coding: utf-8 -*- ''' :codeauthor: :email:`Pedro Algarvio (pedro@algarvio.me)` :copyright: © 2015 by the SaltStack Team, see AUTHORS for more details. :license: Apache 2.0, see LICENSE for more details. pytest_logging.plugin ~~~~~~~~~~~~~~~~~~~~~ ''' # pylint: disable=protected-access,redefined-outer-name # Import python libs from __future__ import absolute_import import os import logging from functools import partial # Import py libs import py # Import pytest libs import pytest try: from _pytest.monkeypatch import MonkeyPatch except ImportError: from _pytest.monkeypatch import monkeypatch as MonkeyPatch log = logging.getLogger('pytest.tempdir') class Hooks(object): # pylint: disable=too-few-public-methods ''' Class to add new hooks to pytest ''' @pytest.hookspec(firstresult=True) def pytest_tempdir_basename(self): ''' An alternate way to define the predictable temporary directory. By default returns ``None`` and get's the basename either from the INI file or from the CLI passed option ''' def pytest_addhooks(pluginmanager): ''' Register our new hooks ''' pluginmanager.add_hookspecs(Hooks) def pytest_addoption(parser): ''' Add CLI options to py.test ''' group = parser.getgroup('tempdir', 'Temporary Directory Options') # 'Tempdir -\n' # ' Predictable and repeatable temporary directory from where additional\n' # ' temporary directories can be based off. At the start of each test\n' # ' session, if the path exists, IT WILL BE WIPED!' # ) group.addoption('--tempdir-basename', default=None, help='The predictable temporary directory base name. ' 'Defaults to the current directory name if not ' 'passed as a CLI parameter and if not defined ' 'using the tempdir_basename session scoped fixture. ' 'If the temporary directory exists when the test ' 'session starts, IT WILL BE WIPED!') group.addoption('--tempdir-no-clean', default=False, action='store_true', help='Disable the removal of the created temporary directory') def pytest_report_header(config): ''' return a string to be displayed as header info for terminal reporting. ''' return 'tempdir: {0}'.format(config._tempdir.strpath) class TempDir(object): def __init__(self, config): self.config = config self._prepare() def _prepare(self): self.counters = {} basename = None cli_tempdir_basename = self.config.getvalue('tempdir_basename') if cli_tempdir_basename is not None: basename = cli_tempdir_basename else: # Let's see if we have a pytest_tempdir_basename hook implementation basename = self.config.hook.pytest_tempdir_basename() if basename is None: # If by now, basename is still None, use the current directory name basename = os.path.basename(py.path.local().strpath) # pylint: disable=no-member mpatch = MonkeyPatch() temproot = py.path.local.get_temproot() # pylint: disable=no-member # Let's get the full real path to the tempdir tempdir = temproot.join(basename).realpath() if tempdir.exists(): # If it exists, it's a stale tempdir. Remove it log.warning('Removing stale tempdir: %s', tempdir.strpath) tempdir.remove(rec=True, ignore_errors=True) # Make sure the tempdir is created tempdir.ensure(dir=True) # Store a reference the tempdir for cleanup purposes when ending the test # session mpatch.setattr(self.config, '_tempdir', self, raising=False) # Register the cleanup actions self.config._cleanup.extend([ mpatch.undo, self._clean_up_tempdir ]) self.tempdir = tempdir def _clean_up_tempdir(self): ''' Clean up temporary directory ''' if self.config.getvalue('--tempdir-no-clean') is False: log.debug('Cleaning up the tempdir: %s', self.tempdir.strpath) try: self.tempdir.remove(rec=True, ignore_errors=True) except py.error.ENOENT: # pylint: disable=no-member pass else: log.debug('No cleaning up tempdir: %s', self.tempdir.strpath) def mkdir(self, path, use_existing=False): abspath = self.tempdir.join(path) if abspath not in self.counters: self.counters[abspath] = 0 while True: newdir = self.tempdir.join('{0}{1}'.format(path, self.counters[abspath])) if newdir.exists() and use_existing is False: self.counters[abspath] += 1 continue log.warning('New Dir: %s', newdir) return newdir.ensure(dir=True) def __getattribute__(self, name): try: return object.__getattribute__(self, name) except AttributeError: return getattr(self.tempdir, name) def pytest_configure(config): ''' Configure the tempdir ''' # Prep tempdir TempDir(config) @pytest.fixture(scope='session') def tempdir(request): ''' tmpdir pytest fixture ''' return request.config._tempdir pytest-tempdir-2016.8.20/pytest_tempdir/version.py0000644000175000017500000000073712756032153022752 0ustar vampasvampas00000000000000# -*- coding: utf-8 -*- ''' :codeauthor: :email:`Pedro Algarvio (pedro@algarvio.me)` :copyright: © 2015 by the SaltStack Team, see AUTHORS for more details. :license: Apache 2.0, see LICENSE for more details. pytest_tempdir.version ~~~~~~~~~~~~~~~~~~~~~~ pytest tempdir plugin version information ''' # Import Python Libs from __future__ import absolute_import __version_info__ = (2016, 8, 20) __version__ = '{0}.{1}.{2}'.format(*__version_info__) pytest-tempdir-2016.8.20/pytest_tempdir/__init__.py0000644000175000017500000000003012667421056023013 0ustar vampasvampas00000000000000# -*- coding: utf-8 -*- pytest-tempdir-2016.8.20/README.rst0000644000175000017500000000565112756032117017326 0ustar vampasvampas00000000000000pytest-tempdir ============== .. image:: https://travis-ci.org/saltstack/pytest-tempdir.svg?branch=master :target: https://travis-ci.org/saltstack/pytest-tempdir :alt: See Build Status on Travis CI .. image:: https://ci.appveyor.com/api/projects/status/github/saltstack/pytest-tempdir?branch=master :target: https://ci.appveyor.com/project/saltstack-public/pytest-tempdir/branch/master :alt: See Build Status on AppVeyor .. image:: http://img.shields.io/pypi/v/pytest-tempdir.svg :target: https://pypi.python.org/pypi/pytest-tempdir Adds support for a predictable and repeatable temporary directory. ---- This `Pytest`_ plugin was generated with `Cookiecutter`_ along with `@hackebrot`_'s `Cookiecutter-pytest-plugin`_ template. Features -------- * Adds support for a predictable and repeatable temporary directory through the `tempdir` fixture which gets cleaned up in the end of the test run session(this behaviour can be disabled). Requirements ------------ * None! Installation ------------ You can install "pytest-tempdir" via `pip`_ from `PyPI`_:: $ pip install pytest-tempdir Usage ----- * Simply define a ``pytest_tempdir_basename`` function on your ``conftest.py`` which returns a string to define the basename or pass ``--tempdir-basename``. * If you wish to leave the temporary directory intact for further inspection after the tests suite ends, pass ``--tempdir-no-clean``. Contributing ------------ Contributions are very welcome. Tests can be run with `tox`_, please ensure the coverage at least stays the same before you submit a pull request. License ------- Distributed under the terms of the `Apache 2.0`_ license, "pytest-tempdir" is free and open source software Issues ------ If you encounter any problems, please `file an issue`_ along with a detailed description. Changelog --------- v2016.8.20 ~~~~~~~~~~ * Support pytest 2.x and 3.x v2015.12.6 ~~~~~~~~~~ * Each absolute path gets it's own counter v2015.11.29 ~~~~~~~~~~~ * Append a counter value to existing directory names v2015.11.17 ~~~~~~~~~~~ * Fix more encoding issues when running setup and the system locale is not set v2015.11.16 ~~~~~~~~~~~ * Fix encoding issue when running setup and the system locale is not set v2015.11.8 ~~~~~~~~~~ * Fix stale tempdir cleanup logic v2015.11.6 ~~~~~~~~~~ * Wipe the tempdir directory on test session start if it exists v2015.11.4 ~~~~~~~~~~ * First working release .. _`Cookiecutter`: https://github.com/audreyr/cookiecutter .. _`@hackebrot`: https://github.com/hackebrot .. _`cookiecutter-pytest-plugin`: https://github.com/pytest-dev/cookiecutter-pytest-plugin .. _`file an issue`: https://github.com/saltstack/pytest-tempdir/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 .. _`Apache 2.0`: http://www.apache.org/licenses/LICENSE-2.0 pytest-tempdir-2016.8.20/setup.py0000644000175000017500000000500612667421056017350 0ustar vampasvampas00000000000000#!/usr/bin/env python # -*- coding: utf-8 -*- from __future__ import absolute_import, with_statement import os import sys import codecs from setuptools import setup, find_packages # Change to source's directory prior to running any command try: SETUP_DIRNAME = os.path.dirname(__file__) except NameError: # We're most likely being frozen and __file__ triggered this NameError # Let's work around that SETUP_DIRNAME = os.path.dirname(sys.argv[0]) if SETUP_DIRNAME != '': os.chdir(SETUP_DIRNAME) def read(fname): ''' Read a file from the directory where setup.py resides ''' file_path = os.path.join(SETUP_DIRNAME, fname) with codecs.open(file_path, encoding='utf-8') as rfh: return rfh.read() # Version info -- read without importing _LOCALS = {} with codecs.open(os.path.join(SETUP_DIRNAME, 'pytest_tempdir', 'version.py'), encoding='utf-8') as rfh: contents = rfh.read() try: exec(contents, None, _LOCALS) # pylint: disable=exec-used except SyntaxError: # SyntaxError: encoding declaration in Unicode string exec(contents.encode('utf-8'), None, _LOCALS) # pylint: disable=exec-used VERSION = _LOCALS['__version__'] LONG_DESCRIPTION = read('README.rst') setup( name='pytest-tempdir', version=VERSION, author='Pedro Algarvio', author_email='pedro@algarvio.me', maintainer='Pedro Algarvio', maintainer_email='pedro@algarvio.me', license='Apache Software License 2.0', url='https://github.com/saltstack/pytest-tempdir', description='Predictable and repeatable tempdir support.', long_description=LONG_DESCRIPTION, packages=find_packages(), install_requires=['pytest>=2.8.1'], classifiers=[ 'Development Status :: 4 - Beta', 'Intended Audience :: Developers', 'Topic :: Software Development :: Testing', 'Programming Language :: Python', '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 :: Implementation :: PyPy', 'Operating System :: OS Independent', 'License :: OSI Approved :: Apache Software License', ], entry_points={ 'pytest11': [ 'tempdir = pytest_tempdir.plugin', ], }, ) pytest-tempdir-2016.8.20/pytest_tempdir.egg-info/0000755000175000017500000000000012756061154022401 5ustar vampasvampas00000000000000pytest-tempdir-2016.8.20/pytest_tempdir.egg-info/dependency_links.txt0000644000175000017500000000000112756061150026443 0ustar vampasvampas00000000000000 pytest-tempdir-2016.8.20/pytest_tempdir.egg-info/PKG-INFO0000644000175000017500000001155112756061150023475 0ustar vampasvampas00000000000000Metadata-Version: 1.1 Name: pytest-tempdir Version: 2016.8.20 Summary: Predictable and repeatable tempdir support. Home-page: https://github.com/saltstack/pytest-tempdir Author: Pedro Algarvio Author-email: pedro@algarvio.me License: Apache Software License 2.0 Description: pytest-tempdir ============== .. image:: https://travis-ci.org/saltstack/pytest-tempdir.svg?branch=master :target: https://travis-ci.org/saltstack/pytest-tempdir :alt: See Build Status on Travis CI .. image:: https://ci.appveyor.com/api/projects/status/github/saltstack/pytest-tempdir?branch=master :target: https://ci.appveyor.com/project/saltstack-public/pytest-tempdir/branch/master :alt: See Build Status on AppVeyor .. image:: http://img.shields.io/pypi/v/pytest-tempdir.svg :target: https://pypi.python.org/pypi/pytest-tempdir Adds support for a predictable and repeatable temporary directory. ---- This `Pytest`_ plugin was generated with `Cookiecutter`_ along with `@hackebrot`_'s `Cookiecutter-pytest-plugin`_ template. Features -------- * Adds support for a predictable and repeatable temporary directory through the `tempdir` fixture which gets cleaned up in the end of the test run session(this behaviour can be disabled). Requirements ------------ * None! Installation ------------ You can install "pytest-tempdir" via `pip`_ from `PyPI`_:: $ pip install pytest-tempdir Usage ----- * Simply define a ``pytest_tempdir_basename`` function on your ``conftest.py`` which returns a string to define the basename or pass ``--tempdir-basename``. * If you wish to leave the temporary directory intact for further inspection after the tests suite ends, pass ``--tempdir-no-clean``. Contributing ------------ Contributions are very welcome. Tests can be run with `tox`_, please ensure the coverage at least stays the same before you submit a pull request. License ------- Distributed under the terms of the `Apache 2.0`_ license, "pytest-tempdir" is free and open source software Issues ------ If you encounter any problems, please `file an issue`_ along with a detailed description. Changelog --------- v2016.8.20 ~~~~~~~~~~ * Support pytest 2.x and 3.x v2015.12.6 ~~~~~~~~~~ * Each absolute path gets it's own counter v2015.11.29 ~~~~~~~~~~~ * Append a counter value to existing directory names v2015.11.17 ~~~~~~~~~~~ * Fix more encoding issues when running setup and the system locale is not set v2015.11.16 ~~~~~~~~~~~ * Fix encoding issue when running setup and the system locale is not set v2015.11.8 ~~~~~~~~~~ * Fix stale tempdir cleanup logic v2015.11.6 ~~~~~~~~~~ * Wipe the tempdir directory on test session start if it exists v2015.11.4 ~~~~~~~~~~ * First working release .. _`Cookiecutter`: https://github.com/audreyr/cookiecutter .. _`@hackebrot`: https://github.com/hackebrot .. _`cookiecutter-pytest-plugin`: https://github.com/pytest-dev/cookiecutter-pytest-plugin .. _`file an issue`: https://github.com/saltstack/pytest-tempdir/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 .. _`Apache 2.0`: http://www.apache.org/licenses/LICENSE-2.0 Platform: UNKNOWN Classifier: Development Status :: 4 - Beta Classifier: Intended Audience :: Developers Classifier: Topic :: Software Development :: Testing Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 2 Classifier: Programming Language :: Python :: 2.7 Classifier: Programming Language :: Python :: 3 Classifier: Programming Language :: Python :: 3.3 Classifier: Programming Language :: Python :: 3.4 Classifier: Programming Language :: Python :: 3.5 Classifier: Programming Language :: Python :: Implementation :: CPython Classifier: Programming Language :: Python :: Implementation :: PyPy Classifier: Operating System :: OS Independent Classifier: License :: OSI Approved :: Apache Software License pytest-tempdir-2016.8.20/pytest_tempdir.egg-info/SOURCES.txt0000644000175000017500000000052112756061150024257 0ustar vampasvampas00000000000000README.rst setup.cfg setup.py pytest_tempdir/__init__.py pytest_tempdir/plugin.py pytest_tempdir/version.py pytest_tempdir.egg-info/PKG-INFO pytest_tempdir.egg-info/SOURCES.txt pytest_tempdir.egg-info/dependency_links.txt pytest_tempdir.egg-info/entry_points.txt pytest_tempdir.egg-info/requires.txt pytest_tempdir.egg-info/top_level.txtpytest-tempdir-2016.8.20/pytest_tempdir.egg-info/entry_points.txt0000644000175000017500000000005412756061150025672 0ustar vampasvampas00000000000000[pytest11] tempdir = pytest_tempdir.plugin pytest-tempdir-2016.8.20/pytest_tempdir.egg-info/top_level.txt0000644000175000017500000000001712756061150025125 0ustar vampasvampas00000000000000pytest_tempdir pytest-tempdir-2016.8.20/pytest_tempdir.egg-info/requires.txt0000644000175000017500000000001612756061150024772 0ustar vampasvampas00000000000000pytest>=2.8.1 pytest-tempdir-2016.8.20/setup.cfg0000644000175000017500000000027712756061154017462 0ustar vampasvampas00000000000000[upload] sign = true identity = 84A298FF [aliases] release = clean register sdist bdist_wheel upload [bdist_wheel] universal = 1 [egg_info] tag_build = tag_date = 0 tag_svn_revision = 0