pytest-openfiles-0.2.0/0000755000175000017500000000000013212330077014347 5ustar dandan00000000000000pytest-openfiles-0.2.0/LICENSE.rst0000644000175000017500000000273013160576123016173 0ustar dandan00000000000000Copyright (c) 2011-2017, Astropy Developers All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the Astropy Team nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. pytest-openfiles-0.2.0/setup.cfg0000644000175000017500000000012313212330077016164 0ustar dandan00000000000000[pytest] minversion = 2.8 testpaths = tests [egg_info] tag_build = tag_date = 0 pytest-openfiles-0.2.0/setup.py0000755000175000017500000000351013212330070016054 0ustar dandan00000000000000#!/usr/bin/env python # Licensed under a 3-clause BSD style license - see LICENSE.rst # -*- encoding: utf-8 -*- import io import re from glob import glob from os.path import basename from os.path import dirname from os.path import join from os.path import splitext from setuptools import setup, find_packages def readme(): with open('README.rst') as ff: return ff.read() setup( name='pytest-openfiles', version='0.2.0', license='BSD', description='Pytest plugin for detecting inadvertent open file handles', long_description=readme(), author='The Astropy Developers', author_email='astropy.team@gmail.com', url='https://astropy.org', packages=find_packages(), include_package_data=True, zip_safe=False, classifiers=[ # complete classifier list: http://pypi.python.org/pypi?%3Aaction=list_classifiers 'Development Status :: 3 - Alpha', 'Framework :: Pytest', 'Intended Audience :: Developers', 'License :: OSI Approved :: BSD License', 'Operating System :: OS Independent', 'Programming Language :: Python', '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 :: 3.6', 'Programming Language :: Python :: Implementation :: CPython', 'Topic :: Software Development :: Testing', 'Topic :: Utilities', ], keywords=[ 'detect', 'open', 'file', 'handle', 'psutil', 'pytest', 'py.test' ], install_requires=[ 'pytest>=2.8.0', 'psutil' ], python_requires='>=2.7', entry_points={ 'pytest11': [ 'pytest_openfiles = pytest_openfiles.plugin', ], }, ) pytest-openfiles-0.2.0/pytest_openfiles/0000755000175000017500000000000013212330077017743 5ustar dandan00000000000000pytest-openfiles-0.2.0/pytest_openfiles/plugin.py0000644000175000017500000000624613202667427021636 0ustar dandan00000000000000# Licensed under a 3-clause BSD style license - see LICENSE.rst """ This plugin provides support for testing whether file-like objects are properly closed. """ import imp import os try: import importlib.machinery as importlib_machinery except ImportError: importlib_machinery = None def pytest_addoption(parser): parser.addoption("--open-files", action="store_true", help="fail if any test leaves files open") parser.addini("open_files_ignore", "when used with the --open-files option, allows " "specifying names of files that may be ignored when " "left open between tests--files in this list are matched " "may be specified by their base name (ignoring their full " "path) or by absolute path", type="args", default=()) # Open file detection. # # This works by calling out to psutil to get the list of open files # held by the process both before and after the test. If something is # still open after the test that wasn't open before the test, an # AssertionError is raised. # # This is not thread-safe. We're not currently running our tests # multi-threaded, but that is worth noting. def _get_open_file_list(): import psutil files = [] p = psutil.Process() if importlib_machinery is not None: suffixes = tuple(importlib_machinery.all_suffixes()) else: suffixes = tuple(info[0] for info in imp.get_suffixes()) files = [x.path for x in p.open_files() if not x.path.endswith(suffixes)] return set(files) def pytest_runtest_setup(item): # Store a list of the currently opened files so we can compare # against them when the test is done. if item.config.getvalue('open_files'): item.open_files = _get_open_file_list() def pytest_runtest_teardown(item, nextitem): # a "skipped" test will not have been called with # pytest_runtest_setup, so therefore won't have an # "open_files" member if (not item.config.getvalue('open_files') or not hasattr(item, 'open_files')): return start_open_files = item.open_files del item.open_files open_files = _get_open_file_list() # This works in tandem with the test_open_file_detection test to # ensure that it creates one extra open file. if item.name == 'test_open_file_detection': assert len(start_open_files) + 1 == len(open_files) return not_closed = set() open_files_ignore = item.config.getini('open_files_ignore') for filename in open_files: ignore = False for ignored in open_files_ignore: if not os.path.isabs(ignored): if os.path.basename(filename) == ignored: ignore = True break else: if filename == ignored: ignore = True break if ignore: continue if filename not in start_open_files: not_closed.add(filename) if len(not_closed): msg = ['File(s) not closed:'] for name in not_closed: msg.append(' {0}'.format(name)) raise AssertionError('\n'.join(msg)) pytest-openfiles-0.2.0/pytest_openfiles/__init__.py0000644000175000017500000000022613202667427022067 0ustar dandan00000000000000# Licensed under a 3-clause BSD style license - see LICENSE.rst """ This package contains pytest plugins that are used by the astropy test suite. """ pytest-openfiles-0.2.0/PKG-INFO0000644000175000017500000000732513212330077015453 0ustar dandan00000000000000Metadata-Version: 1.2 Name: pytest-openfiles Version: 0.2.0 Summary: Pytest plugin for detecting inadvertent open file handles Home-page: https://astropy.org Author: The Astropy Developers Author-email: astropy.team@gmail.com License: BSD Description-Content-Type: UNKNOWN Description: ================ pytest-openfiles ================ This package provides a plugin for the `pytest`_ framework that allows developers to detect whether any file handles or other file-like objects were inadvertently left open at the end of a unit test. It has been moved from the core `astropy`_ project since it is of use more generally. .. _pytest: https://pytest.org/en/latest/ .. _astropy: https://astropy.org/en/latest/ **NOTE**: This plugin is not supported with Py2.7 on Win32 platforms. Motivation ---------- The `pytest-openfiles`_ plugin allows for the detection of open I/O resources at the end of unit tests. This is particularly useful for testing code that manipulates file handles or other I/O resources. It allows developers to ensure that this kind of code properly cleans up I/O resources when they are no longer needed. Installation ------------ The ``pytest-openfiles`` plugin can be installed using ``pip``:: $ pip install pytest-openfiles It is also possible to install the latest development version from the source repository:: $ git clone https://github.com/astropy/pytest-openfiles $ cd pytest-openfiles $ python ./setup.py install In either case, the plugin will automatically be registered for use with ``pytest``. Usage ----- This plugin adds the ``--open-files`` option to the ``pytest`` command. When running tests with ``--open-files``, if a file is opened during the course of a unit test but that file is not closed before the test finishes, the test will fail. Development Status ------------------ .. image:: https://travis-ci.org/astropy/pytest-openfile.svg :target: https://travis-ci.org/astropy/pytest-openfiles :alt: Travis CI Status .. image:: https://ci.appveyor.com/api/projects/status/944gtt7n0o1d6826/branch/master?svg=true :target: https://ci.appveyor.com/project/Astropy/pytest-openfiles/branch/master :alt: Appveyor Status Questions, bug reports, and feature requests can be submitted on `github`_. .. _github: https://github.com/astropy/pytest-openfiles License ------- This plugin is licensed under a 3-clause BSD style license - see the ``LICENSE.rst`` file. Keywords: detect,open,file,handle,psutil,pytest,py.test Platform: UNKNOWN Classifier: Development Status :: 3 - Alpha Classifier: Framework :: Pytest Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: BSD License Classifier: Operating System :: OS Independent Classifier: Programming Language :: Python 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 :: 3.6 Classifier: Programming Language :: Python :: Implementation :: CPython Classifier: Topic :: Software Development :: Testing Classifier: Topic :: Utilities Requires-Python: >=2.7 pytest-openfiles-0.2.0/CHANGES.rst0000644000175000017500000000020313212330070016135 0ustar dandan000000000000000.2 (2017-12-07) ================ - Remove test dependency on astropy. [#4] 0.1 (2017-10-09) ================ - Alpha release. pytest-openfiles-0.2.0/README.rst0000644000175000017500000000416213210041444016034 0ustar dandan00000000000000================ pytest-openfiles ================ This package provides a plugin for the `pytest`_ framework that allows developers to detect whether any file handles or other file-like objects were inadvertently left open at the end of a unit test. It has been moved from the core `astropy`_ project since it is of use more generally. .. _pytest: https://pytest.org/en/latest/ .. _astropy: https://astropy.org/en/latest/ **NOTE**: This plugin is not supported with Py2.7 on Win32 platforms. Motivation ---------- The `pytest-openfiles`_ plugin allows for the detection of open I/O resources at the end of unit tests. This is particularly useful for testing code that manipulates file handles or other I/O resources. It allows developers to ensure that this kind of code properly cleans up I/O resources when they are no longer needed. Installation ------------ The ``pytest-openfiles`` plugin can be installed using ``pip``:: $ pip install pytest-openfiles It is also possible to install the latest development version from the source repository:: $ git clone https://github.com/astropy/pytest-openfiles $ cd pytest-openfiles $ python ./setup.py install In either case, the plugin will automatically be registered for use with ``pytest``. Usage ----- This plugin adds the ``--open-files`` option to the ``pytest`` command. When running tests with ``--open-files``, if a file is opened during the course of a unit test but that file is not closed before the test finishes, the test will fail. Development Status ------------------ .. image:: https://travis-ci.org/astropy/pytest-openfile.svg :target: https://travis-ci.org/astropy/pytest-openfiles :alt: Travis CI Status .. image:: https://ci.appveyor.com/api/projects/status/944gtt7n0o1d6826/branch/master?svg=true :target: https://ci.appveyor.com/project/Astropy/pytest-openfiles/branch/master :alt: Appveyor Status Questions, bug reports, and feature requests can be submitted on `github`_. .. _github: https://github.com/astropy/pytest-openfiles License ------- This plugin is licensed under a 3-clause BSD style license - see the ``LICENSE.rst`` file. pytest-openfiles-0.2.0/MANIFEST.in0000644000175000017500000000022513202667427016117 0ustar dandan00000000000000include LICENSE.rst include README.rst include CHANGES.rst include setup.cfg include tests/*.py include tests/data/*.txt global-exclude *.pyc *.o pytest-openfiles-0.2.0/pytest_openfiles.egg-info/0000755000175000017500000000000013212330077021435 5ustar dandan00000000000000pytest-openfiles-0.2.0/pytest_openfiles.egg-info/not-zip-safe0000644000175000017500000000000113212330077023663 0ustar dandan00000000000000 pytest-openfiles-0.2.0/pytest_openfiles.egg-info/SOURCES.txt0000644000175000017500000000075113212330077023324 0ustar dandan00000000000000CHANGES.rst LICENSE.rst MANIFEST.in README.rst setup.cfg setup.py pytest_openfiles/__init__.py pytest_openfiles/plugin.py pytest_openfiles.egg-info/PKG-INFO pytest_openfiles.egg-info/SOURCES.txt pytest_openfiles.egg-info/dependency_links.txt pytest_openfiles.egg-info/entry_points.txt pytest_openfiles.egg-info/not-zip-safe pytest_openfiles.egg-info/requires.txt pytest_openfiles.egg-info/top_level.txt tests/__init__.py tests/test_open_file_detection.py tests/data/open_file_detection.txtpytest-openfiles-0.2.0/pytest_openfiles.egg-info/dependency_links.txt0000644000175000017500000000000113212330077025503 0ustar dandan00000000000000 pytest-openfiles-0.2.0/pytest_openfiles.egg-info/PKG-INFO0000644000175000017500000000732513212330077022541 0ustar dandan00000000000000Metadata-Version: 1.2 Name: pytest-openfiles Version: 0.2.0 Summary: Pytest plugin for detecting inadvertent open file handles Home-page: https://astropy.org Author: The Astropy Developers Author-email: astropy.team@gmail.com License: BSD Description-Content-Type: UNKNOWN Description: ================ pytest-openfiles ================ This package provides a plugin for the `pytest`_ framework that allows developers to detect whether any file handles or other file-like objects were inadvertently left open at the end of a unit test. It has been moved from the core `astropy`_ project since it is of use more generally. .. _pytest: https://pytest.org/en/latest/ .. _astropy: https://astropy.org/en/latest/ **NOTE**: This plugin is not supported with Py2.7 on Win32 platforms. Motivation ---------- The `pytest-openfiles`_ plugin allows for the detection of open I/O resources at the end of unit tests. This is particularly useful for testing code that manipulates file handles or other I/O resources. It allows developers to ensure that this kind of code properly cleans up I/O resources when they are no longer needed. Installation ------------ The ``pytest-openfiles`` plugin can be installed using ``pip``:: $ pip install pytest-openfiles It is also possible to install the latest development version from the source repository:: $ git clone https://github.com/astropy/pytest-openfiles $ cd pytest-openfiles $ python ./setup.py install In either case, the plugin will automatically be registered for use with ``pytest``. Usage ----- This plugin adds the ``--open-files`` option to the ``pytest`` command. When running tests with ``--open-files``, if a file is opened during the course of a unit test but that file is not closed before the test finishes, the test will fail. Development Status ------------------ .. image:: https://travis-ci.org/astropy/pytest-openfile.svg :target: https://travis-ci.org/astropy/pytest-openfiles :alt: Travis CI Status .. image:: https://ci.appveyor.com/api/projects/status/944gtt7n0o1d6826/branch/master?svg=true :target: https://ci.appveyor.com/project/Astropy/pytest-openfiles/branch/master :alt: Appveyor Status Questions, bug reports, and feature requests can be submitted on `github`_. .. _github: https://github.com/astropy/pytest-openfiles License ------- This plugin is licensed under a 3-clause BSD style license - see the ``LICENSE.rst`` file. Keywords: detect,open,file,handle,psutil,pytest,py.test Platform: UNKNOWN Classifier: Development Status :: 3 - Alpha Classifier: Framework :: Pytest Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: BSD License Classifier: Operating System :: OS Independent Classifier: Programming Language :: Python 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 :: 3.6 Classifier: Programming Language :: Python :: Implementation :: CPython Classifier: Topic :: Software Development :: Testing Classifier: Topic :: Utilities Requires-Python: >=2.7 pytest-openfiles-0.2.0/pytest_openfiles.egg-info/entry_points.txt0000644000175000017500000000006713212330077024736 0ustar dandan00000000000000[pytest11] pytest_openfiles = pytest_openfiles.plugin pytest-openfiles-0.2.0/pytest_openfiles.egg-info/top_level.txt0000644000175000017500000000002713212330077024166 0ustar dandan00000000000000pytest_openfiles tests pytest-openfiles-0.2.0/pytest_openfiles.egg-info/requires.txt0000644000175000017500000000002513212330077024032 0ustar dandan00000000000000pytest>=2.8.0 psutil pytest-openfiles-0.2.0/tests/0000755000175000017500000000000013212330077015511 5ustar dandan00000000000000pytest-openfiles-0.2.0/tests/__init__.py0000644000175000017500000000010013160601574017616 0ustar dandan00000000000000# Licensed under a 3-clause BSD style license - see LICENSE.rst pytest-openfiles-0.2.0/tests/test_open_file_detection.py0000644000175000017500000000046513202667427023140 0ustar dandan00000000000000# Licensed under a 3-clause BSD style license - see LICENSE.rst import os PKG_DATA_DIR = os.path.dirname(__file__) fd = None def test_open_file_detection(): global fd fd = open(os.path.join(PKG_DATA_DIR, 'data/open_file_detection.txt')) def teardown(): if fd is not None: fd.close() pytest-openfiles-0.2.0/tests/data/0000755000175000017500000000000013212330077016422 5ustar dandan00000000000000pytest-openfiles-0.2.0/tests/data/open_file_detection.txt0000644000175000017500000000001113160603615023154 0ustar dandan00000000000000CONTENTS