Commit 86883c2b authored by Jason Madden's avatar Jason Madden

Enable test.support.is_resource_enabled for monkey-patched tests

Using the standard library resource names. Currently this must be set
with the environment variable GEVENTTEST_USE_RESOURCES (e.g.,
GEVENTTEST_USE_RESOURCES=all,-network to disable stdlib network
tests).

Still to do:

- Documents and change note
- Command line argument in testrunner
- Enable from gevent tests
parent 55cd5af5
......@@ -22,6 +22,7 @@ from .sysinfo import RUNNING_ON_APPVEYOR
from .sysinfo import PY37
from .patched_tests_setup import disable_tests_in_source
from . import support
from . import resources
if RUNNING_ON_APPVEYOR and PY37:
# 3.7 added a stricter mode for thread cleanup.
......@@ -37,6 +38,8 @@ if RUNNING_ON_APPVEYOR and PY37:
yield
support.wait_threads_exit = wait_threads_exit
# Configure allowed resources
resources.setup_resources()
__file__ = os.path.join(os.getcwd(), test_filename)
......
# -*- coding: utf-8 -*-
# Copyright (c) 2018 gevent community
#
# 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.
"""
Test environment setup.
This establishes the resources that are available for use,
which are tested with `support.is_resource_enabled`.
"""
from __future__ import absolute_import, division, print_function
import os
from . import support
def _get_ALL_RESOURCES():
# RESOURCE_NAMES is the list of all known resources, including those that
# shouldn't be enabled by default or when asking for "all" resources.
# ALL_RESOURCES is the list of resources enabled by default or with "all" resources.
try:
# 3.6 and 3.7
from test.libregrtest import ALL_RESOURCES
except ImportError:
# 2.7 through 3.5
# Don't do this:
## from test.regrtest import ALL_RESOURCES
# On Python 2.7 to 3.5, importing regrtest iterates
# sys.modules and does modifications. That doesn't work well
# when it's imported from another module at module scope.
# Also, it makes some assumptions about module __file__ that
# may not hold true (at least on 2.7), especially when six or
# other module proxy objects are involved.
# So we hardcode the list. This is from 2.7, which is a superset
# of the defined resources through 3.5.
ALL_RESOURCES = (
'audio', 'curses', 'largefile', 'network', 'bsddb',
'decimal', 'cpu', 'subprocess', 'urlfetch', 'gui',
'xpickle'
)
return list(ALL_RESOURCES)
def parse_resources(resource_str):
# str -> Sequence[str]
# Parse it like libregrtest.cmdline documents:
# -u is used to specify which special resource intensive tests to run,
# such as those requiring large file support or network connectivity.
# The argument is a comma-separated list of words indicating the
# resources to test. Currently only the following are defined:
# all - Enable all special resources.
#
# none - Disable all special resources (this is the default).
# <snip>
# network - It is okay to run tests that use external network
# resource, e.g. testing SSL support for sockets.
# <snip>
#
# subprocess Run all tests for the subprocess module.
# <snip>
#
# To enable all resources except one, use '-uall,-<resource>'. For
# example, to run all the tests except for the gui tests, give the
# option '-uall,-gui'.
# We make a change though: we default to 'all' resources, instead of
# 'none'. Encountering either of those later in the string resets
# it, for ease of working with appending to environment variables.
resources = _get_ALL_RESOURCES()
if not resource_str:
return resources
requested_resources = resource_str.split(',')
for requested_resource in requested_resources:
# empty strings are ignored; this can happen when working with
# the environment variable if not already set:
# ENV=$ENV,-network
if not requested_resource:
continue
if requested_resource == 'all':
resources = list(_get_ALL_RESOURCES())
elif requested_resource == 'none':
resources = []
elif requested_resource.startswith('-'):
if requested_resource[1:] in resources:
resources.remove(requested_resource[1:])
else:
resources.append(requested_resource)
return resources
def setup_resources(resources=None):
if resources is None:
resources = parse_resources(os.environ.get('GEVENTTEST_USE_RESOURCES'))
support.use_resources = list(resources)
return resources
if __name__ == '__main__':
print(setup_resources())
......@@ -407,14 +407,14 @@ def report(total, failed, passed, exit=True, took=None,
if failed_unexpected:
util.log('\n%s/%s unexpected failures', len(failed_unexpected), total, color='error')
print_list(failed_unexpected)
else:
util.log(
'\nRan %s tests%s in %s files%s',
total_cases,
util._colorize('skipped', " (skipped=%d)" % total_skipped) if total_skipped else '',
total,
took,
)
util.log(
'\nRan %s tests%s in %s files%s',
total_cases,
util._colorize('skipped', " (skipped=%d)" % total_skipped) if total_skipped else '',
total,
took,
)
if exit:
if failed_unexpected:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment