Skip to content

Commit ffa44ab

Browse files
committed
Adding support for passing a subset of packages to run_unit_tests.
Also - Adding instruction to `CONTRIBUTING` about how to run a subset of tests for packages of your choosing - Moving the "Adding Features" section to the top of the `CONTRIBUTING` doc - Making tiny edits to `CONTRIBUTING` doc, e.g. using a "repo" hyperlink for the repository and updating the link to the `tox` docs
1 parent 67dc93c commit ffa44ab

File tree

3 files changed

+94
-32
lines changed

3 files changed

+94
-32
lines changed

CONTRIBUTING.rst

Lines changed: 46 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,29 @@ Contributing
88

99
Here are some guidelines for hacking on ``google-cloud-python``.
1010

11+
Adding Features
12+
---------------
13+
14+
In order to add a feature to ``google-cloud-python``:
15+
16+
- The feature must be documented in both the API and narrative
17+
documentation (in ``docs/``).
18+
19+
- The feature must work fully on the following CPython versions: 2.7,
20+
3.4, and 3.5 on both UNIX and Windows.
21+
22+
- The feature must not add unnecessary dependencies (where
23+
"unnecessary" is of course subjective, but new dependencies should
24+
be discussed).
25+
1126
Using a Development Checkout
1227
----------------------------
1328

14-
You'll have to create a development environment to hack on ``google-cloud-python``,
15-
using a Git checkout:
29+
You'll have to create a development environment to hack on
30+
``google-cloud-python``, using a Git checkout:
1631

17-
- While logged into your GitHub account, navigate to the ``google-cloud-python`` repo
18-
on GitHub.
19-
20-
https://github.com/GoogleCloudPlatform/google-cloud-python
32+
- While logged into your GitHub account, navigate to the
33+
``google-cloud-python`` `repo`_ on GitHub.
2134

2235
- Fork and clone the ``google-cloud-python`` repository to your GitHub account by
2336
clicking the "Fork" button.
@@ -42,6 +55,8 @@ repo, from which you can submit a pull request.
4255
To work on the codebase and run the tests, we recommend using ``tox``,
4356
but you can also use a ``virtualenv`` of your own creation.
4457

58+
.. _repo: https://github.com/GoogleCloudPlatform/google-cloud-python
59+
4560
Using a custom ``virtualenv``
4661
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4762

@@ -96,6 +111,19 @@ Using ``tox``
96111
by the ``tox`` environment, so if you make changes, you'll need
97112
to again ``--recreate`` the environment.
98113

114+
- To run unit tests on a restricted set of packages::
115+
116+
$ tox -e py27 -- core datastore
117+
118+
Alternatively, you can just navigate directly to the package you are
119+
currently developing and run tests there::
120+
121+
$ export GIT_ROOT=$(pwd)
122+
$ cd ${GIT_ROOT}/core/
123+
$ tox -e py27
124+
$ cd ${GIT_ROOT}/datastore/
125+
$ tox -e py27
126+
99127
Note on Editable Installs / Develop Mode
100128
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
101129

@@ -124,21 +152,6 @@ On Debian/Ubuntu::
124152

125153
$ sudo apt-get install python-dev
126154

127-
Adding Features
128-
---------------
129-
130-
In order to add a feature to ``google-cloud-python``:
131-
132-
- The feature must be documented in both the API and narrative
133-
documentation (in ``docs/``).
134-
135-
- The feature must work fully on the following CPython versions: 2.7,
136-
3.4, and 3.5 on both UNIX and Windows.
137-
138-
- The feature must not add unnecessary dependencies (where
139-
"unnecessary" is of course subjective, but new dependencies should
140-
be discussed).
141-
142155
Coding Style
143156
------------
144157

@@ -170,21 +183,25 @@ Running Tests
170183

171184
- To run all tests for ``google-cloud-python`` on a single Python version, run
172185
``py.test`` from your development virtualenv (See
173-
*Using a Development Checkout* above).
186+
`Using a Development Checkout`_ above).
187+
188+
.. _Using a Development Checkout: #using-a-development-checkout
174189

175190
- To run the full set of ``google-cloud-python`` tests on all platforms, install
176-
``tox`` (https://testrun.org/tox/) into a system Python. The ``tox`` console
177-
script will be installed into the scripts location for that Python. While
178-
``cd``'ed to the ``google-cloud-python`` checkout root directory (it contains
179-
``tox.ini``), invoke the ``tox`` console script. This will read the
180-
``tox.ini`` file and execute the tests on multiple Python versions and
181-
platforms; while it runs, it creates a virtualenv for each version/platform
182-
combination. For example::
191+
``tox`` (https://tox.readthedocs.io/en/latest/) into a system Python. The
192+
``tox`` console script will be installed into the scripts location for that
193+
Python. While ``cd``'-ed to the ``google-cloud-python`` checkout root
194+
directory (it contains ``tox.ini``), invoke the ``tox`` console script.
195+
This will read the ``tox.ini`` file and execute the tests on multiple
196+
Python versions and platforms; while it runs, it creates a ``virtualenv`` for
197+
each version/platform combination. For example::
183198

184199
$ sudo --set-home /usr/bin/pip install tox
185200
$ cd ${HOME}/hack-on-google-cloud-python/
186201
$ /usr/bin/tox
187202

203+
.. _Using a Development Checkout: #using-a-development-checkout
204+
188205
Running System Tests
189206
--------------------
190207

scripts/run_unit_tests.py

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
(3, 4): 'py34',
4242
(3, 5): 'py35',
4343
}
44+
UNSET_SENTINEL = object() # Sentinel for argparser
4445

4546

4647
def check_output(*args):
@@ -82,6 +83,46 @@ def get_package_directories():
8283
return result
8384

8485

86+
def verify_packages(subset, all_packages):
87+
"""Verify that a subset of packages are among all packages.
88+
89+
:type subset: list
90+
:param subset: List of a subset of package names.
91+
92+
:type all_packages: list
93+
:param all_packages: List of all package names.
94+
95+
:raises: :class:`~exceptions.ValueError` if there are unknown packages
96+
in ``subset``
97+
"""
98+
left_out = set(subset) - set(all_packages)
99+
if left_out:
100+
raise ValueError('Unknown packages',
101+
sorted(left_out))
102+
103+
def get_test_packages():
104+
"""Get a list of packages which need tests run.
105+
106+
Filters the package list in the following order:
107+
108+
* Check command line for packages passed in as positional arguments
109+
* Just use all packages
110+
111+
:rtype: list
112+
:returns: A list of all package directories where tests
113+
need be run.
114+
"""
115+
all_packages = get_package_directories()
116+
117+
parser = get_parser()
118+
args = parser.parse_args()
119+
if args.packages is not UNSET_SENTINEL:
120+
verify_packages(args.packages, all_packages)
121+
return sorted(args.packages)
122+
else:
123+
return all_packages
124+
125+
85126
def run_package(package, tox_env):
86127
"""Run tox environment for a given package.
87128
@@ -116,6 +157,9 @@ def get_parser():
116157
parser.add_argument(
117158
'--tox-env', dest='tox_env',
118159
help='The tox environment(s) to run in sub-packages.')
160+
packages_help = 'Optional list of sub-packages to be tested.'
161+
parser.add_argument('packages', nargs='*',
162+
default=UNSET_SENTINEL, help=packages_help)
119163
return parser
120164

121165

@@ -164,7 +208,7 @@ def get_tox_env():
164208

165209
def main():
166210
"""Run all the unit tests that need to be run."""
167-
packages_to_run = get_package_directories()
211+
packages_to_run = get_test_packages()
168212
if not packages_to_run:
169213
print('No tests to run.')
170214
return

tox.ini

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ covercmd =
114114

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

125125
[testenv:isolated-cover]
126-
commands = {[testenv]commands} --tox-env cover
126+
commands =
127+
python {toxinidir}/scripts/run_unit_tests.py {posargs} --tox-env cover
127128

128129
[testenv:py27-pandas]
129130
basepython =

0 commit comments

Comments
 (0)