pytest-remotedata-0.2.0/0000755000224300020070000000000013201341423017320 5ustar ddavellaSTSCI\science00000000000000pytest-remotedata-0.2.0/CHANGES.rst0000644000224300020070000000062713201341330021124 0ustar ddavellaSTSCI\science000000000000000.2.0 (2017-11-10) ================== - Do not accept invalid values passed to ``--remote-data`` argument. [#15] - Update list of valid hosts URLs recognized as astropy data sources. [#13] - Remove test dependency on astropy core. [#14] - Allow strict remote data checking to be configurable. This introduces a dependency on ``pytest>=3.1``. [#18] 0.1 (2017-10-10) ================ - Alpha release. pytest-remotedata-0.2.0/LICENSE.rst0000644000224300020070000000273013162216774021156 0ustar ddavellaSTSCI\science00000000000000Copyright (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-remotedata-0.2.0/MANIFEST.in0000644000224300020070000000017413167203401021064 0ustar ddavellaSTSCI\science00000000000000include LICENSE.rst include README.rst include CHANGES.rst include setup.cfg include tests/*.py global-exclude *.pyc *.o pytest-remotedata-0.2.0/PKG-INFO0000644000224300020070000001416013201341423020417 0ustar ddavellaSTSCI\science00000000000000Metadata-Version: 1.2 Name: pytest-remotedata Version: 0.2.0 Summary: Pytest plugin for controlling remote data access. Home-page: https://astropy.org Author: The Astropy Developers Author-email: astropy.team@gmail.com License: BSD Description-Content-Type: UNKNOWN Description: ================= pytest-remotedata ================= This package provides a plugin for the `pytest`_ framework that allows developers to control unit tests that require access to data from the internet. It was originally part of the `astropy`_ core package, but has been moved to a separate package in order to be of more general use. .. _pytest: https://pytest.org/en/latest/ .. _astropy: https://astropy.org/en/latest/ Motivation ---------- Many software packages provide features that require access to data from the internet. These features need to be tested, but unit tests that access the internet can dominate the overall runtime of a test suite. The ``pytest-remotedata`` plugin allows developers to indicate which unit tests require access to the internet, and to control when and whether such tests should execute as part of any given run of the test suite. Installation ------------ The ``pytest-remotedata`` plugin can be installed using ``pip``:: $ pip install pytest-remotedata It is also possible to install the latest development version from the source repository:: $ git clone https://github.com/astropy/pytest-remotedata $ cd pytest-remotedata $ python ./setup.py install In either case, the plugin will automatically be registered for use with ``pytest``. Usage ----- Installing this plugin makes two decorators available for use with ``pytest``: * ``remote_data`` for marking tests that require data from the internet * ``internet_off`` for marking tests that should run only when internet access is disabled These decorators can be used to mark test functions, methods, and classes using ``@pytest.mark``. For example, consider the following test function that requires access to data from the internet: .. code-block:: python import pytest from urllib.request import urlopen @pytest.mark.remote_data def test_remote_data(): urlopen('https://astropy.org') Marking the ``test_remote_data`` function with ``@pytest.mark.remote_data`` indicates to ``pytest`` that this test should be run only when access to remote data sources is explicitly requested. When this plugin is installed, the ``--remote-data`` command line option is added to the ``pytest`` command line interface. The default behavior is to skip tests that are marked with ``remote_data``. If the ``--remote-data`` option is not provided to the ``pytest`` command, or if ``--remote-data=none`` is provided, all tests that are marked with ``remote_data`` will be skipped. All tests that are marked with ``internet_off`` will be executed. Sometimes it is useful to check that certain tests do not unexpectedly access the internet. Strict remote data access checking can be enabled by setting ``remote_data_strict = true`` in the tested package's ``setup.cfg`` file. If this option is enabled, any test that attempts to access the network but is not marked with ``@pytest.mark.remote_data`` will fail. Providing either the ``--remote-data`` option, or ``--remote-data=any`` to the ``pytest`` command line interface will cause all tests that are marked with ``remote-data`` to execute. Any tests that are marked with ``internet_off`` will be skipped. Running the tests with ``--remote-data=astropy`` will cause only tests that receive remote data from Astropy data sources to be run. Tests with any other data sources will be skipped. This is indicated in the test code by marking test functions with ``@pytest.mark.remote_data(source='astropy')``. In the future, we intend to support a configurable way to indicate specific remote data sources in addition to ``astropy``. Development Status ------------------ .. image:: https://travis-ci.org/astropy/pytest-remotedata.svg :target: https://travis-ci.org/astropy/pytest-remotedata :alt: Travis CI Status .. image:: https://ci.appveyor.com/api/projects/status/ym7lxajcs5qwm31e/branch/master?svg=true :target: https://ci.appveyor.com/project/Astropy/pytest-remotedata/branch/master :alt: Appveyor Status Questions, bug reports, and feature requests can be submitted on `github`_. .. _github: https://github.com/astropy/pytest-remotedata License ------- This plugin is licensed under a 3-clause BSD style license - see the ``LICENSE.rst`` file. Keywords: remote,data,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-remotedata-0.2.0/pytest_remotedata/0000755000224300020070000000000013201341423023055 5ustar ddavellaSTSCI\science00000000000000pytest-remotedata-0.2.0/pytest_remotedata/__init__.py0000644000224300020070000000022613162216774025206 0ustar ddavellaSTSCI\science00000000000000# 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-remotedata-0.2.0/pytest_remotedata/disable_internet.py0000644000224300020070000001220113201324756026750 0ustar ddavellaSTSCI\science00000000000000# Licensed under a 3-clause BSD style license - see LICENSE.rst import contextlib import socket from six.moves import urllib # save original socket method for restoration # These are global so that re-calling the turn_off_internet function doesn't # overwrite them again socket_original = socket.socket socket_create_connection = socket.create_connection socket_bind = socket.socket.bind socket_connect = socket.socket.connect ASTROPY_HOSTS = ['data.astropy.org', 'astropy.stsci.edu', 'www.astropy.org'] INTERNET_OFF = False # urllib2 uses a global variable to cache its default "opener" for opening # connections for various protocols; we store it off here so we can restore to # the default after re-enabling internet use _orig_opener = None # ::1 is apparently another valid name for localhost? # it is returned by getaddrinfo when that function is given localhost def check_internet_off(original_function, allow_astropy_data=False): """ Wraps ``original_function``, which in most cases is assumed to be a `socket.socket` method, to raise an `IOError` for any operations on non-local AF_INET sockets. """ def new_function(*args, **kwargs): if isinstance(args[0], socket.socket): if not args[0].family in (socket.AF_INET, socket.AF_INET6): # Should be fine in all but some very obscure cases # More to the point, we don't want to affect AF_UNIX # sockets. return original_function(*args, **kwargs) host = args[1][0] addr_arg = 1 valid_hosts = ('localhost', '127.0.0.1', '::1') else: # The only other function this is used to wrap currently is # socket.create_connection, which should be passed a 2-tuple, but # we'll check just in case if not (isinstance(args[0], tuple) and len(args[0]) == 2): return original_function(*args, **kwargs) host = args[0][0] addr_arg = 0 valid_hosts = ('localhost', '127.0.0.1') if allow_astropy_data: for valid_host in ASTROPY_HOSTS: valid_host_ip = socket.gethostbyname(valid_host) valid_hosts += (valid_host, valid_host_ip) hostname = socket.gethostname() fqdn = socket.getfqdn() if host in (hostname, fqdn): host = 'localhost' new_addr = (host, args[addr_arg][1]) args = args[:addr_arg] + (new_addr,) + args[addr_arg + 1:] if any(h in host for h in valid_hosts): return original_function(*args, **kwargs) else: raise IOError("An attempt was made to connect to the internet " "by a test that was not marked `remote_data`. The " "requested host was: {0}".format(host)) return new_function def turn_off_internet(verbose=False, allow_astropy_data=False): """ Disable internet access via python by preventing connections from being created using the socket module. Presumably this could be worked around by using some other means of accessing the internet, but all default python modules (urllib, requests, etc.) use socket [citation needed]. """ global INTERNET_OFF global _orig_opener if INTERNET_OFF: return INTERNET_OFF = True __tracebackhide__ = True if verbose: print("Internet access disabled") # Update urllib2 to force it not to use any proxies # Must use {} here (the default of None will kick off an automatic search # for proxies) _orig_opener = urllib.request.build_opener() no_proxy_handler = urllib.request.ProxyHandler({}) opener = urllib.request.build_opener(no_proxy_handler) urllib.request.install_opener(opener) socket.create_connection = check_internet_off(socket_create_connection, allow_astropy_data=allow_astropy_data) socket.socket.bind = check_internet_off(socket_bind, allow_astropy_data=allow_astropy_data) socket.socket.connect = check_internet_off(socket_connect, allow_astropy_data=allow_astropy_data) return socket def turn_on_internet(verbose=False): """ Restore internet access. Not used, but kept in case it is needed. """ global INTERNET_OFF global _orig_opener if not INTERNET_OFF: return INTERNET_OFF = False if verbose: print("Internet access enabled") urllib.request.install_opener(_orig_opener) socket.create_connection = socket_create_connection socket.socket.bind = socket_bind socket.socket.connect = socket_connect return socket @contextlib.contextmanager def no_internet(verbose=False): """Context manager to temporarily disable internet access (if not already disabled). If it was already disabled before entering the context manager (i.e. `turn_off_internet` was called previously) then this is a no-op and leaves internet access disabled until a manual call to `turn_on_internet`. """ already_disabled = INTERNET_OFF turn_off_internet(verbose=verbose) try: yield finally: if not already_disabled: turn_on_internet(verbose=verbose) pytest-remotedata-0.2.0/pytest_remotedata/plugin.py0000644000224300020070000000547513201341307024741 0ustar ddavellaSTSCI\science00000000000000# Licensed under a 3-clause BSD style license - see LICENSE.rst """ This plugin provides command-line options for controlling whether and how tests make use of online data. """ import pytest from .disable_internet import turn_off_internet, turn_on_internet def pytest_addoption(parser): # The following means that if --remote-data is not specified, the default # is 'none', but if it is specified without arguments (--remote-data), it # defaults to '--remote-data=any'. parser.addoption( "--remote-data", nargs="?", const='any', default='none', help="run tests with online data") parser.addini('remote_data_strict', "If 'True', tests will fail if they attempt to access the internet " "but are not explicitly marked with 'remote_data'", type="bool", default=False) def pytest_configure(config): config.getini('markers').append( 'remote_data: Apply to tests that require data from remote servers') config.getini('markers').append( 'internet_off: Apply to tests that should only run when network access is deactivated') strict_check = bool(config.getini('remote_data_strict')) remote_data = config.getoption('remote_data') if remote_data not in ['astropy', 'any', 'none']: raise pytest.UsageError( "'{}' is not a valid source for remote data".format(remote_data)) # Monkeypatch to deny access to remote resources unless explicitly told # otherwise if strict_check and remote_data != 'any': turn_off_internet( verbose=config.option.verbose, allow_astropy_data=(remote_data == 'astropy')) def pytest_unconfigure(): """ Cleanup post-testing """ # restore internet connectivity (only lost if remote_data=False and # turn_off_internet previously called) # this is harmless / does nothing if socket connections were never disabled turn_on_internet() def pytest_runtest_setup(item): remote_data = item.get_marker('remote_data') internet_off = item.get_marker('internet_off') remote_data_config = item.config.getvalue("remote_data") if remote_data is not None and internet_off is not None: raise ValueError("remote_data and internet_off are not compatible") if remote_data is not None: source = remote_data.kwargs.get('source', 'any') if source not in ('astropy', 'any'): raise ValueError("source should be 'astropy' or 'any'") if remote_data_config == 'none': pytest.skip("need --remote-data option to run") elif remote_data_config == 'astropy': if source == 'any': pytest.skip("need --remote-data option to run") if internet_off is not None: if remote_data_config != 'none': pytest.skip("run this test only when network access is disabled") pytest-remotedata-0.2.0/pytest_remotedata.egg-info/0000755000224300020070000000000013201341423024547 5ustar ddavellaSTSCI\science00000000000000pytest-remotedata-0.2.0/pytest_remotedata.egg-info/dependency_links.txt0000644000224300020070000000000113201341423030615 0ustar ddavellaSTSCI\science00000000000000 pytest-remotedata-0.2.0/pytest_remotedata.egg-info/entry_points.txt0000644000224300020070000000007113201341423030043 0ustar ddavellaSTSCI\science00000000000000[pytest11] pytest_remotedata = pytest_remotedata.plugin pytest-remotedata-0.2.0/pytest_remotedata.egg-info/not-zip-safe0000644000224300020070000000000113201341423026775 0ustar ddavellaSTSCI\science00000000000000 pytest-remotedata-0.2.0/pytest_remotedata.egg-info/PKG-INFO0000644000224300020070000001416013201341423025646 0ustar ddavellaSTSCI\science00000000000000Metadata-Version: 1.2 Name: pytest-remotedata Version: 0.2.0 Summary: Pytest plugin for controlling remote data access. Home-page: https://astropy.org Author: The Astropy Developers Author-email: astropy.team@gmail.com License: BSD Description-Content-Type: UNKNOWN Description: ================= pytest-remotedata ================= This package provides a plugin for the `pytest`_ framework that allows developers to control unit tests that require access to data from the internet. It was originally part of the `astropy`_ core package, but has been moved to a separate package in order to be of more general use. .. _pytest: https://pytest.org/en/latest/ .. _astropy: https://astropy.org/en/latest/ Motivation ---------- Many software packages provide features that require access to data from the internet. These features need to be tested, but unit tests that access the internet can dominate the overall runtime of a test suite. The ``pytest-remotedata`` plugin allows developers to indicate which unit tests require access to the internet, and to control when and whether such tests should execute as part of any given run of the test suite. Installation ------------ The ``pytest-remotedata`` plugin can be installed using ``pip``:: $ pip install pytest-remotedata It is also possible to install the latest development version from the source repository:: $ git clone https://github.com/astropy/pytest-remotedata $ cd pytest-remotedata $ python ./setup.py install In either case, the plugin will automatically be registered for use with ``pytest``. Usage ----- Installing this plugin makes two decorators available for use with ``pytest``: * ``remote_data`` for marking tests that require data from the internet * ``internet_off`` for marking tests that should run only when internet access is disabled These decorators can be used to mark test functions, methods, and classes using ``@pytest.mark``. For example, consider the following test function that requires access to data from the internet: .. code-block:: python import pytest from urllib.request import urlopen @pytest.mark.remote_data def test_remote_data(): urlopen('https://astropy.org') Marking the ``test_remote_data`` function with ``@pytest.mark.remote_data`` indicates to ``pytest`` that this test should be run only when access to remote data sources is explicitly requested. When this plugin is installed, the ``--remote-data`` command line option is added to the ``pytest`` command line interface. The default behavior is to skip tests that are marked with ``remote_data``. If the ``--remote-data`` option is not provided to the ``pytest`` command, or if ``--remote-data=none`` is provided, all tests that are marked with ``remote_data`` will be skipped. All tests that are marked with ``internet_off`` will be executed. Sometimes it is useful to check that certain tests do not unexpectedly access the internet. Strict remote data access checking can be enabled by setting ``remote_data_strict = true`` in the tested package's ``setup.cfg`` file. If this option is enabled, any test that attempts to access the network but is not marked with ``@pytest.mark.remote_data`` will fail. Providing either the ``--remote-data`` option, or ``--remote-data=any`` to the ``pytest`` command line interface will cause all tests that are marked with ``remote-data`` to execute. Any tests that are marked with ``internet_off`` will be skipped. Running the tests with ``--remote-data=astropy`` will cause only tests that receive remote data from Astropy data sources to be run. Tests with any other data sources will be skipped. This is indicated in the test code by marking test functions with ``@pytest.mark.remote_data(source='astropy')``. In the future, we intend to support a configurable way to indicate specific remote data sources in addition to ``astropy``. Development Status ------------------ .. image:: https://travis-ci.org/astropy/pytest-remotedata.svg :target: https://travis-ci.org/astropy/pytest-remotedata :alt: Travis CI Status .. image:: https://ci.appveyor.com/api/projects/status/ym7lxajcs5qwm31e/branch/master?svg=true :target: https://ci.appveyor.com/project/Astropy/pytest-remotedata/branch/master :alt: Appveyor Status Questions, bug reports, and feature requests can be submitted on `github`_. .. _github: https://github.com/astropy/pytest-remotedata License ------- This plugin is licensed under a 3-clause BSD style license - see the ``LICENSE.rst`` file. Keywords: remote,data,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-remotedata-0.2.0/pytest_remotedata.egg-info/requires.txt0000644000224300020070000000002013201341423027137 0ustar ddavellaSTSCI\science00000000000000six pytest>=3.1 pytest-remotedata-0.2.0/pytest_remotedata.egg-info/SOURCES.txt0000644000224300020070000000107313201341423026434 0ustar ddavellaSTSCI\science00000000000000CHANGES.rst LICENSE.rst MANIFEST.in README.rst setup.cfg setup.py pytest_remotedata/__init__.py pytest_remotedata/disable_internet.py pytest_remotedata/plugin.py pytest_remotedata.egg-info/PKG-INFO pytest_remotedata.egg-info/SOURCES.txt pytest_remotedata.egg-info/dependency_links.txt pytest_remotedata.egg-info/entry_points.txt pytest_remotedata.egg-info/not-zip-safe pytest_remotedata.egg-info/requires.txt pytest_remotedata.egg-info/top_level.txt tests/__init__.py tests/conftest.py tests/test_skip_remote_data.py tests/test_socketblocker.py tests/test_strict_check.pypytest-remotedata-0.2.0/pytest_remotedata.egg-info/top_level.txt0000644000224300020070000000003013201341423027272 0ustar ddavellaSTSCI\science00000000000000pytest_remotedata tests pytest-remotedata-0.2.0/README.rst0000644000224300020070000001024713201341307021014 0ustar ddavellaSTSCI\science00000000000000================= pytest-remotedata ================= This package provides a plugin for the `pytest`_ framework that allows developers to control unit tests that require access to data from the internet. It was originally part of the `astropy`_ core package, but has been moved to a separate package in order to be of more general use. .. _pytest: https://pytest.org/en/latest/ .. _astropy: https://astropy.org/en/latest/ Motivation ---------- Many software packages provide features that require access to data from the internet. These features need to be tested, but unit tests that access the internet can dominate the overall runtime of a test suite. The ``pytest-remotedata`` plugin allows developers to indicate which unit tests require access to the internet, and to control when and whether such tests should execute as part of any given run of the test suite. Installation ------------ The ``pytest-remotedata`` plugin can be installed using ``pip``:: $ pip install pytest-remotedata It is also possible to install the latest development version from the source repository:: $ git clone https://github.com/astropy/pytest-remotedata $ cd pytest-remotedata $ python ./setup.py install In either case, the plugin will automatically be registered for use with ``pytest``. Usage ----- Installing this plugin makes two decorators available for use with ``pytest``: * ``remote_data`` for marking tests that require data from the internet * ``internet_off`` for marking tests that should run only when internet access is disabled These decorators can be used to mark test functions, methods, and classes using ``@pytest.mark``. For example, consider the following test function that requires access to data from the internet: .. code-block:: python import pytest from urllib.request import urlopen @pytest.mark.remote_data def test_remote_data(): urlopen('https://astropy.org') Marking the ``test_remote_data`` function with ``@pytest.mark.remote_data`` indicates to ``pytest`` that this test should be run only when access to remote data sources is explicitly requested. When this plugin is installed, the ``--remote-data`` command line option is added to the ``pytest`` command line interface. The default behavior is to skip tests that are marked with ``remote_data``. If the ``--remote-data`` option is not provided to the ``pytest`` command, or if ``--remote-data=none`` is provided, all tests that are marked with ``remote_data`` will be skipped. All tests that are marked with ``internet_off`` will be executed. Sometimes it is useful to check that certain tests do not unexpectedly access the internet. Strict remote data access checking can be enabled by setting ``remote_data_strict = true`` in the tested package's ``setup.cfg`` file. If this option is enabled, any test that attempts to access the network but is not marked with ``@pytest.mark.remote_data`` will fail. Providing either the ``--remote-data`` option, or ``--remote-data=any`` to the ``pytest`` command line interface will cause all tests that are marked with ``remote-data`` to execute. Any tests that are marked with ``internet_off`` will be skipped. Running the tests with ``--remote-data=astropy`` will cause only tests that receive remote data from Astropy data sources to be run. Tests with any other data sources will be skipped. This is indicated in the test code by marking test functions with ``@pytest.mark.remote_data(source='astropy')``. In the future, we intend to support a configurable way to indicate specific remote data sources in addition to ``astropy``. Development Status ------------------ .. image:: https://travis-ci.org/astropy/pytest-remotedata.svg :target: https://travis-ci.org/astropy/pytest-remotedata :alt: Travis CI Status .. image:: https://ci.appveyor.com/api/projects/status/ym7lxajcs5qwm31e/branch/master?svg=true :target: https://ci.appveyor.com/project/Astropy/pytest-remotedata/branch/master :alt: Appveyor Status Questions, bug reports, and feature requests can be submitted on `github`_. .. _github: https://github.com/astropy/pytest-remotedata License ------- This plugin is licensed under a 3-clause BSD style license - see the ``LICENSE.rst`` file. pytest-remotedata-0.2.0/setup.cfg0000644000224300020070000000015513201341423021142 0ustar ddavellaSTSCI\science00000000000000[pytest] minversion = 3.1 testpaths = tests remote_data_strict = true [egg_info] tag_build = tag_date = 0 pytest-remotedata-0.2.0/setup.py0000755000224300020070000000355513201341372021050 0ustar ddavellaSTSCI\science00000000000000#!/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-remotedata', version='0.2.0', license='BSD', description='Pytest plugin for controlling remote data access.', long_description=readme(), author='The Astropy Developers', author_email='astropy.team@gmail.com', url='https://astropy.org', packages=find_packages(), py_modules=[splitext(basename(path))[0] for path in glob('src/*.py')], 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=[ 'remote', 'data', 'pytest', 'py.test' ], install_requires=[ 'six', 'pytest>=3.1' ], python_requires='>=2.7', entry_points={ 'pytest11': [ 'pytest_remotedata = pytest_remotedata.plugin', ], }, ) pytest-remotedata-0.2.0/tests/0000755000224300020070000000000013201341423020462 5ustar ddavellaSTSCI\science00000000000000pytest-remotedata-0.2.0/tests/__init__.py0000644000224300020070000000015513162216774022614 0ustar ddavellaSTSCI\science00000000000000from __future__ import (absolute_import, division, print_function, unicode_literals) pytest-remotedata-0.2.0/tests/conftest.py0000644000224300020070000000014513201341307022662 0ustar ddavellaSTSCI\science00000000000000# This enables the meta-testing of this plugin via the testdir fixture pytest_plugins = ['pytester'] pytest-remotedata-0.2.0/tests/test_skip_remote_data.py0000644000224300020070000000412513201324756025421 0ustar ddavellaSTSCI\science00000000000000# Licensed under a 3-clause BSD style license - see LICENSE.rst # this test doesn't actually use any online data, it should just be skipped # by run_tests because it has the remote_data decorator. import pytest from contextlib import closing from six.moves.urllib.request import urlopen ASTROPY_DATA_URL = "http://data.astropy.org/" TIMEOUT = 10 def download_file(remote_url): with closing(urlopen(remote_url, timeout=TIMEOUT)) as remote: remote.read() @pytest.mark.remote_data def test_skip_remote_data(pytestconfig): # astropy.test() has remote_data=none or remote_data=astropy but we still # got here somehow, so fail with a helpful message if pytestconfig.getoption('remote_data') == 'none': pytest.fail('@remote_data was not skipped with remote_data=none') elif pytestconfig.getoption('remote_data') == 'astropy': pytest.fail('@remote_data was not skipped with remote_data=astropy') # Test Astropy URL download_file(ASTROPY_DATA_URL + 'galactic_center/gc_2mass_k.fits') # Test non-Astropy URL download_file('http://www.google.com') @pytest.mark.remote_data(source='astropy') def test_skip_remote_data_astropy(pytestconfig): # astropy.test() has remote_data=none but we still got here somehow, # so fail with a helpful message if pytestconfig.getoption('remote_data') == 'none': pytest.fail('@remote_data was not skipped with remote_data=none') # Test Astropy URL download_file(ASTROPY_DATA_URL + 'galactic_center/gc_2mass_k.fits') # Test non-Astropy URL if pytestconfig.getoption('remote_data') == 'astropy': with pytest.raises(Exception) as exc: download_file('http://www.google.com') assert "An attempt was made to connect to the internet" in str(exc.value) else: download_file('http://www.google.com') @pytest.mark.internet_off def test_internet_off_decorator(pytestconfig): # This test should only run when internet access has been disabled if pytestconfig.getoption('remote_data') != 'none': pytest.fail('@internet_off test ran when remote_data!=none') pytest-remotedata-0.2.0/tests/test_socketblocker.py0000644000224300020070000000460113201324756024740 0ustar ddavellaSTSCI\science00000000000000# Licensed under a 3-clause BSD style license - see LICENSE.rst import sys import time from threading import Thread from six.moves import BaseHTTPServer, SimpleHTTPServer from six.moves.urllib.request import urlopen import pytest from pytest_remotedata.disable_internet import no_internet def test_outgoing_fails(): with pytest.raises(IOError): with no_internet(): urlopen('http://www.python.org') class StoppableHTTPServer(BaseHTTPServer.HTTPServer, object): def __init__(self, *args): super(StoppableHTTPServer, self).__init__(*args) self.stop = False def handle_request(self): self.stop = True super(StoppableHTTPServer, self).handle_request() def serve_forever(self): """ Serve until stop set, which will happen if any request is handled """ while not self.stop: self.handle_request() @pytest.mark.parametrize(('localhost'), ('localhost', '127.0.0.1')) def test_localconnect_succeeds(localhost): """ Ensure that connections to localhost are allowed, since these are genuinely not remotedata. """ # port "0" means find open port # see http://stackoverflow.com/questions/1365265/on-localhost-how-to-pick-a-free-port-number httpd = StoppableHTTPServer(('localhost', 0), SimpleHTTPServer.SimpleHTTPRequestHandler) port = httpd.socket.getsockname()[1] server = Thread(target=httpd.serve_forever) server.setDaemon(True) server.start() time.sleep(0.1) urlopen('http://{localhost:s}:{port:d}'.format(localhost=localhost, port=port)).close() PY3_4 = sys.version_info[:2] >= (3, 4) # Used for the below test--inline functions aren't pickleable # by multiprocessing? def _square(x): return x ** 2 @pytest.mark.skipif('not PY3_4 or sys.platform == "win32" or sys.platform.startswith("gnu0")') def test_multiprocessing_forkserver(): """ Test that using multiprocessing with forkserver works. Perhaps a simpler more direct test would be to just open some local sockets and pass something through them. Regression test for https://github.com/astropy/astropy/pull/3713 """ import multiprocessing ctx = multiprocessing.get_context('forkserver') pool = ctx.Pool(1) result = pool.map(_square, [1, 2, 3, 4, 5]) pool.close() pool.join() assert result == [1, 4, 9, 16, 25] pytest-remotedata-0.2.0/tests/test_strict_check.py0000644000224300020070000000331513201341307024543 0ustar ddavellaSTSCI\science00000000000000# Licensed under a 3-clause BSD style license - see LICENSE.rst import os import pytest PYFILE_CONTENTS = """ import pytest from six.moves.urllib.request import urlopen def test_config_setting(pytestconfig): assert pytestconfig.getini('remote_data_strict') == {} {} def test_internet_access(): urlopen('http://astropy.org') """ def _write_config_file(testdir, entry): config = testdir.tmpdir.join('setup.cfg') config.write(""" [pytest] {} """.format(entry)) # Just a sanity check to make sure we actually write the config file assert os.path.exists(str(testdir.tmpdir.join('setup.cfg'))) def test_local_config(pytestconfig): assert pytestconfig.getini('remote_data_strict') == True def test_default_behavior(testdir): _write_config_file(testdir, '') testdir.makepyfile(PYFILE_CONTENTS.format('False', '')) result = testdir.runpytest_subprocess() result.assert_outcomes(passed=2) def test_strict_behavior(testdir): _write_config_file(testdir, 'remote_data_strict = true') testdir.makepyfile(PYFILE_CONTENTS.format('True', '')) result = testdir.runpytest_subprocess() result.assert_outcomes(passed=1, failed=1) @pytest.mark.parametrize('source', ['none', 'any']) def test_strict_with_decorator(testdir, source): _write_config_file(testdir, 'remote_data_strict = true') decorator = '@pytest.mark.remote_data' testdir.makepyfile(PYFILE_CONTENTS.format('True', decorator)) clarg = '--remote-data=' + source result = testdir.runpytest_subprocess(clarg) if source == 'none': outcomes = dict(passed=1, skipped=1) else: outcomes = dict(passed=2) result.assert_outcomes(**outcomes)