Skip to content

Commit fefac75

Browse files
authored
dlp nox default style (googleapis#4997)
1 parent ac535cf commit fefac75

File tree

5 files changed

+97
-14
lines changed

5 files changed

+97
-14
lines changed

dlp/.coveragerc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[run]
2+
branch = True
3+
omit =
4+
*/gapic/*
5+
*/proto/*
6+
7+
[report]
8+
fail_under = 100
9+
show_missing = True
10+
exclude_lines =
11+
# Re-enable the standard pragma
12+
pragma: NO COVER
13+
# Ignore debug-only repr
14+
def __repr__
15+
omit =
16+
*/gapic/*
17+
*/proto/*

dlp/.flake8

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[flake8]
2+
exclude =
3+
# Exclude generated code.
4+
**/proto/**
5+
**/gapic/**
6+
*_pb2.py
7+
8+
# Standard linting exemptions.
9+
__pycache__,
10+
.git,
11+
*.pyc,
12+
conf.py

dlp/google/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
pkg_resources.declare_namespace(__name__)
44
except ImportError:
55
import pkgutil
6-
__path__ = pkgutil.extend_path(__path__, __name__)
6+
__path__ = pkgutil.extend_path(__path__, __name__)

dlp/google/cloud/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
pkg_resources.declare_namespace(__name__)
44
except ImportError:
55
import pkgutil
6-
__path__ = pkgutil.extend_path(__path__, __name__)
6+
__path__ = pkgutil.extend_path(__path__, __name__)

dlp/nox.py

Lines changed: 66 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,32 +18,59 @@
1818
import nox
1919

2020

21+
LOCAL_DEPS = (
22+
os.path.join('..', 'api_core'),
23+
os.path.join('..', 'core'),
24+
)
2125
@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."""
26+
def default(session):
27+
"""Run the unit test suite.
28+
29+
This is intended to be run **without** an interpreter set, so
30+
that the current ``python`` (on the ``PATH``) or the version of
31+
Python corresponding to the ``nox`` binary the ``PATH`` can
32+
run the tests.
33+
"""
34+
session.install('mock', 'pytest', 'pytest-cov', *LOCAL_DEPS)
35+
session.install('-e', '.')
2536

26-
session.interpreter = 'python{}'.format(python_version)
37+
session.run(
38+
'py.test',
39+
'--quiet',
40+
'--cov=google.cloud.dlp_v2beta1',
41+
'--cov-append',
42+
'--cov-config=.coveragerc',
43+
'--cov-report=',
44+
'--cov-fail-under=97',
45+
os.path.join('tests', 'unit'),
46+
*session.posargs
47+
)
48+
49+
@nox.session
50+
@nox.parametrize('py', ['2.7', '3.4', '3.5', '3.6'])
51+
def unit(session, py):
52+
"""Run the unit test suite."""
2753

28-
session.virtualenv_dirname = 'unit-' + python_version
54+
# Run unit tests against all supported versions of Python.
55+
session.interpreter = 'python{}'.format(py)
2956

30-
session.install('pytest')
31-
session.install('-e', '.')
57+
# Set the virtualenv dirname.
58+
session.virtualenv_dirname = 'unit-' + py
3259

33-
session.run('py.test', '--quiet', os.path.join('tests', 'unit'))
60+
default(session)
3461

3562

3663
@nox.session
37-
@nox.parametrize('python_version', ['2.7', '3.6'])
38-
def system_tests(session, python_version):
64+
@nox.parametrize('py', ['2.7', '3.6'])
65+
def system(session, py):
3966
"""Run the system test suite."""
4067

4168
if not os.environ.get('GOOGLE_APPLICATION_CREDENTIALS', ''):
4269
session.skip('Credentials must be set via environment variable.')
4370

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

46-
session.virtualenv_dirname = 'sys-' + python_version
73+
session.virtualenv_dirname = 'sys-' + py
4774

4875
session.install('pytest')
4976
session.install('-e', '.')
@@ -52,10 +79,37 @@ def system_tests(session, python_version):
5279
os.path.join('tests', 'system'), *session.posargs)
5380

5481

82+
@nox.session
83+
def lint(session):
84+
"""Run linters.
85+
86+
Returns a failure if the linters find linting errors or sufficiently
87+
serious code quality issues.
88+
"""
89+
session.interpreter = 'python3.6'
90+
session.install('flake8', *LOCAL_DEPS)
91+
session.install('.')
92+
session.run('flake8', 'google', 'tests')
93+
94+
5595
@nox.session
5696
def lint_setup_py(session):
5797
"""Verify that setup.py is valid (including RST check)."""
5898
session.interpreter = 'python3.6'
5999
session.install('docutils', 'pygments')
60100
session.run('python', 'setup.py', 'check', '--restructuredtext',
61101
'--strict')
102+
103+
104+
@nox.session
105+
def cover(session):
106+
"""Run the final coverage report.
107+
108+
This outputs the coverage report aggregating coverage from the unit
109+
test runs (not system test runs), and then erases coverage data.
110+
"""
111+
session.interpreter = 'python3.6'
112+
session.chdir(os.path.dirname(__file__))
113+
session.install('coverage', 'pytest-cov')
114+
session.run('coverage', 'report', '--show-missing', '--fail-under=100')
115+
session.run('coverage', 'erase')

0 commit comments

Comments
 (0)