Skip to content

Commit b0d4747

Browse files
committed
nox unittest updates
1 parent 6275537 commit b0d4747

File tree

3 files changed

+161
-32
lines changed

3 files changed

+161
-32
lines changed

bigquery_datatransfer/nox.py

Lines changed: 51 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,54 @@
1313
# limitations under the License.
1414

1515
from __future__ import absolute_import
16+
1617
import os
1718

1819
import nox
1920

2021

22+
LOCAL_DEPS = (
23+
os.path.join('..', 'api_core'),
24+
os.path.join('..', 'core'),
25+
)
26+
27+
2128
@nox.session
22-
@nox.parametrize('python_version', ['2.7', '3.4', '3.5', '3.6'])
23-
def unit_tests(session, python_version):
24-
"""Run the unit test suite."""
29+
def default(session):
30+
"""Default unit test session.
31+
32+
This is intended to be run **without** an interpreter set, so
33+
that the current ``python`` (on the ``PATH``) or the version of
34+
Python corresponding to the ``nox`` binary the ``PATH`` can
35+
run the tests.
36+
"""
37+
# Install all test dependencies, then install this package in-place.
38+
session.install('mock', 'pytest', 'pytest-cov', *LOCAL_DEPS)
39+
session.install('-e', '.')
2540

26-
session.interpreter = 'python{}'.format(python_version)
41+
# Run py.test against the unit tests.
42+
session.run(
43+
'py.test',
44+
'--quiet',
45+
'--cov=google.cloud.bigquery_datatransfer',
46+
'--cov=google.cloud.bigquery_datatransfer_v1',
47+
'--cov=tests.unit',
48+
'--cov-append',
49+
'--cov-config=.coveragerc',
50+
'--cov-report=',
51+
os.path.join('tests', 'unit', 'gapic', 'v1'),
52+
*session.posargs
53+
)
2754

28-
session.virtualenv_dirname = 'unit-' + python_version
2955

30-
session.install('pytest')
31-
session.install('-e', '.')
56+
@nox.session
57+
@nox.parametrize('py', ['2.7', '3.4', '3.5', '3.6'])
58+
def unit(session, py):
59+
"""Run the unit test suite."""
3260

33-
session.run('py.test', '--quiet', os.path.join('tests', 'unit'))
61+
session.interpreter = 'python{}'.format(py)
62+
session.virtualenv_dirname = 'unit-' + py
63+
default(session)
3464

3565

3666
@nox.session
@@ -65,3 +95,16 @@ def system(session, py):
6595

6696
# Run py.test against the system tests.
6797
session.run('py.test', '--quiet', 'tests/system/')
98+
99+
100+
@nox.session
101+
def cover(session):
102+
"""Run the final coverage report.
103+
104+
This outputs the coverage report aggregating coverage from the unit
105+
test runs (not system test runs), and then erases coverage data.
106+
"""
107+
session.interpreter = 'python3.6'
108+
session.install('coverage', 'pytest-cov')
109+
session.run('coverage', 'report', '--show-missing', '--fail-under=70')
110+
session.run('coverage', 'erase')

container/nox.py

Lines changed: 55 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,40 +13,70 @@
1313
# limitations under the License.
1414

1515
from __future__ import absolute_import
16+
1617
import os
1718

1819
import nox
1920

2021

22+
LOCAL_DEPS = (
23+
os.path.join('..', 'api_core'),
24+
os.path.join('..', 'core'),
25+
)
26+
27+
2128
@nox.session
22-
@nox.parametrize('python_version', ['2.7', '3.4', '3.5', '3.6'])
23-
def unit_tests(session, python_version):
24-
"""Run the unit test suite."""
29+
def default(session):
30+
"""Default unit test session.
31+
32+
This is intended to be run **without** an interpreter set, so
33+
that the current ``python`` (on the ``PATH``) or the version of
34+
Python corresponding to the ``nox`` binary the ``PATH`` can
35+
run the tests.
36+
"""
37+
# Install all test dependencies, then install this package in-place.
38+
session.install('mock', 'pytest', 'pytest-cov', *LOCAL_DEPS)
39+
session.install('-e', '.')
2540

26-
session.interpreter = 'python{}'.format(python_version)
41+
# Run py.test against the unit tests.
42+
session.run(
43+
'py.test',
44+
'--quiet',
45+
'--cov=google.cloud.container',
46+
'--cov=google.cloud.container_v1',
47+
'--cov=tests.unit',
48+
'--cov-append',
49+
'--cov-config=.coveragerc',
50+
'--cov-report=',
51+
os.path.join('tests', 'unit'),
52+
*session.posargs
53+
)
2754

28-
session.virtualenv_dirname = 'unit-' + python_version
2955

30-
session.install('pytest')
31-
session.install('-e', '.')
56+
@nox.session
57+
@nox.parametrize('py', ['2.7', '3.4', '3.5', '3.6'])
58+
def unit(session, py):
59+
"""Run the unit test suite."""
3260

33-
session.run('py.test', '--quiet', os.path.join('tests', 'unit'))
61+
session.interpreter = 'python{}'.format(py)
62+
session.virtualenv_dirname = 'unit-' + py
63+
default(session)
3464

3565

3666
@nox.session
37-
@nox.parametrize('python_version', ['2.7', '3.6'])
38-
def system_tests(session, python_version):
67+
@nox.parametrize('py', ['2.7', '3.6'])
68+
def system(session, py):
3969
"""Run the system test suite."""
4070

4171
# Sanity check: Only run system tests if the environment variable is set.
4272
if not os.environ.get('GOOGLE_APPLICATION_CREDENTIALS', ''):
4373
session.skip('Credentials must be set via environment variable.')
4474

4575
# Run the system tests against latest Python 2 and Python 3 only.
46-
session.interpreter = 'python{}'.format(python_version)
76+
session.interpreter = 'python{}'.format(py)
4777

4878
# Set the virtualenv dirname.
49-
session.virtualenv_dirname = 'sys-' + python_version
79+
session.virtualenv_dirname = 'sys-' + py
5080

5181
# Install all test dependencies, then install this package into the
5282
# virtualenv's dist-packages.
@@ -65,3 +95,16 @@ def lint_setup_py(session):
6595
session.install('docutils', 'pygments')
6696
session.run('python', 'setup.py', 'check', '--restructuredtext',
6797
'--strict')
98+
99+
100+
@nox.session
101+
def cover(session):
102+
"""Run the final coverage report.
103+
104+
This outputs the coverage report aggregating coverage from the unit
105+
test runs (not system test runs), and then erases coverage data.
106+
"""
107+
session.interpreter = 'python3.6'
108+
session.install('coverage', 'pytest-cov')
109+
session.run('coverage', 'report', '--show-missing', '--fail-under=60')
110+
session.run('coverage', 'erase')

dataproc/nox.py

Lines changed: 55 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,37 +13,67 @@
1313
# limitations under the License.
1414

1515
from __future__ import absolute_import
16+
1617
import os
1718

1819
import nox
1920

2021

22+
LOCAL_DEPS = (
23+
os.path.join('..', 'api_core'),
24+
os.path.join('..', 'core'),
25+
)
26+
27+
2128
@nox.session
22-
@nox.parametrize('python_version', ['2.7', '3.4', '3.5', '3.6'])
23-
def unit_tests(session, python_version):
24-
"""Run the unit test suite."""
29+
def default(session):
30+
"""Default unit test session.
31+
32+
This is intended to be run **without** an interpreter set, so
33+
that the current ``python`` (on the ``PATH``) or the version of
34+
Python corresponding to the ``nox`` binary the ``PATH`` can
35+
run the tests.
36+
"""
37+
# Install all test dependencies, then install this package in-place.
38+
session.install('mock', 'pytest', 'pytest-cov', *LOCAL_DEPS)
39+
session.install('-e', '.')
2540

26-
session.interpreter = 'python{}'.format(python_version)
41+
# Run py.test against the unit tests.
42+
session.run(
43+
'py.test',
44+
'--quiet',
45+
'--cov=google.cloud.dataproc',
46+
'--cov=google.cloud.dataproc_v1',
47+
'--cov=tests.unit',
48+
'--cov-append',
49+
'--cov-config=.coveragerc',
50+
'--cov-report=',
51+
os.path.join('tests', 'unit'),
52+
*session.posargs
53+
)
2754

28-
session.virtualenv_dirname = 'unit-' + python_version
2955

30-
session.install('pytest')
31-
session.install('-e', '.')
56+
@nox.session
57+
@nox.parametrize('py', ['2.7', '3.4', '3.5', '3.6'])
58+
def unit(session, py):
59+
"""Run the unit test suite."""
3260

33-
session.run('py.test', '--quiet', os.path.join('tests', 'unit'))
61+
session.interpreter = 'python{}'.format(py)
62+
session.virtualenv_dirname = 'unit-' + py
63+
default(session)
3464

3565

3666
@nox.session
37-
@nox.parametrize('python_version', ['2.7', '3.6'])
38-
def system_tests(session, python_version):
67+
@nox.parametrize('py', ['2.7', '3.6'])
68+
def system(session, py):
3969
"""Run the system test suite."""
4070

4171
if not os.environ.get('GOOGLE_APPLICATION_CREDENTIALS', ''):
4272
session.skip('Credentials must be set via environment variable.')
4373

44-
session.interpreter = 'python{}'.format(python_version)
74+
session.interpreter = 'python{}'.format(py)
4575

46-
session.virtualenv_dirname = 'sys-' + python_version
76+
session.virtualenv_dirname = 'sys-' + py
4777

4878
session.install('pytest')
4979
session.install('-e', '.')
@@ -59,3 +89,16 @@ def lint_setup_py(session):
5989
session.install('docutils', 'pygments')
6090
session.run('python', 'setup.py', 'check', '--restructuredtext',
6191
'--strict')
92+
93+
94+
@nox.session
95+
def cover(session):
96+
"""Run the final coverage report.
97+
98+
This outputs the coverage report aggregating coverage from the unit
99+
test runs (not system test runs), and then erases coverage data.
100+
"""
101+
session.interpreter = 'python3.6'
102+
session.install('coverage', 'pytest-cov')
103+
session.run('coverage', 'report', '--show-missing', '--fail-under=80')
104+
session.run('coverage', 'erase')

0 commit comments

Comments
 (0)