Skip to content

Commit 230b60f

Browse files
committed
Adding flexibility to how run_unit_tests determines what to run.
- Upgrading the `get_tox_env()` helper to support the `TOXENV` env. var. and the current system Python - Ditching tox on Travis for py27, py34 and isolated-cover, this is because those tox environments just farm out the work to tox environments for each subpackage, so it isn't worth waiting for the extra tox env. setup time - Changing back from --tox-env-dir to --tox-env flag in run_unit_tests.py script - Adding py27,py34,py35 back to the `tox` env. list - Letting tox -e py27, etc. allow the current Python to determine their tox env. value
1 parent c36daf2 commit 230b60f

File tree

3 files changed

+45
-13
lines changed

3 files changed

+45
-13
lines changed

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ install:
55
- pip install --upgrade pip tox
66

77
script:
8-
- tox -e py27
9-
- tox -e py34
8+
- python2.7 scripts/run_unit_tests.py
9+
- python3.4 scripts/run_unit_tests.py
1010
- tox -e lint
1111
- tox -e cover
12-
- tox -e isolated-cover
12+
- python scripts/run_unit_tests.py --tox-env cover
1313
- tox -e system-tests
1414
- tox -e system-tests3
1515
- scripts/update_docs.sh

scripts/run_unit_tests.py

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,11 @@
3535
'scripts',
3636
'system_tests',
3737
)
38-
ENV_REMAP = {
39-
'isolated-cover': 'cover',
38+
TOX_ENV_VAR = 'TOXENV'
39+
ACCEPTED_VERSIONS = {
40+
(2, 7): 'py27',
41+
(3, 4): 'py34',
42+
(3, 5): 'py35',
4043
}
4144

4245

@@ -111,22 +114,51 @@ def get_parser():
111114
description = 'Run tox environment(s) in all sub-packages.'
112115
parser = argparse.ArgumentParser(description=description)
113116
parser.add_argument(
114-
'--tox-env-dir', dest='tox_env_dir',
115-
help='The current tox environment directory.')
117+
'--tox-env', dest='tox_env',
118+
help='The tox environment(s) to run in sub-packages.')
116119
return parser
117120

118121

122+
def get_tox_env_from_version():
123+
"""Get ``tox`` environment from the current Python version.
124+
125+
:rtype: str
126+
:returns: The current ``tox`` environment to be used, e.g. ``"py27"``.
127+
:raises: :class:`EnvironmentError` if the first two options
128+
don't yield any value and the current version of
129+
Python is not in ``ACCEPTED_VERSIONS``.
130+
"""
131+
version_info = sys.version_info[:2]
132+
try:
133+
return ACCEPTED_VERSIONS[version_info]
134+
except KeyError:
135+
raise EnvironmentError(
136+
'Invalid Python version', version_info,
137+
'Accepted versions are',
138+
sorted(ACCEPTED_VERSIONS.keys()))
139+
140+
119141
def get_tox_env():
120142
"""Get the environment to be used with ``tox``.
121143
144+
Tries to infer the ``tox`` environment in the following order
145+
146+
* From the ``--tox-env`` command line flag
147+
* From the ``TOXENV`` environment variable
148+
* From the version of the current running Python
149+
122150
:rtype: str
123151
:returns: The current ``tox`` environment to be used, e.g. ``"py27"``.
124152
"""
125153
parser = get_parser()
126154
args = parser.parse_args()
127-
env_dir = args.tox_env_dir
128-
_, tox_env = os.path.split(env_dir)
129-
tox_env = ENV_REMAP.get(tox_env, tox_env)
155+
if args.tox_env is not None:
156+
tox_env = args.tox_env
157+
elif TOX_ENV_VAR in os.environ:
158+
tox_env = os.environ[TOX_ENV_VAR]
159+
else:
160+
tox_env = get_tox_env_from_version()
161+
130162
return tox_env
131163

132164

tox.ini

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tox]
22
envlist =
3-
cover,docs,lint
3+
py27,py34,py35,cover,docs,lint
44

55
[testing]
66
deps =
@@ -114,7 +114,7 @@ covercmd =
114114

115115
[testenv]
116116
commands =
117-
python {toxinidir}/scripts/run_unit_tests.py --tox-env-dir {envdir}
117+
python {toxinidir}/scripts/run_unit_tests.py
118118
deps =
119119
skip_install =
120120
py27: True
@@ -123,7 +123,7 @@ skip_install =
123123
isolated-cover: True
124124

125125
[testenv:isolated-cover]
126-
commands = {[testenv]commands}
126+
commands = {[testenv]commands} --tox-env cover
127127

128128
[testenv:py27-pandas]
129129
basepython =

0 commit comments

Comments
 (0)