18
18
import nox
19
19
20
20
21
+ LOCAL_DEPS = (
22
+ os .path .join ('..' , 'api_core' ),
23
+ os .path .join ('..' , 'core' ),
24
+ )
21
25
@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' , '.' )
25
36
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."""
27
53
28
- session .virtualenv_dirname = 'unit-' + python_version
54
+ # Run unit tests against all supported versions of Python.
55
+ session .interpreter = 'python{}' .format (py )
29
56
30
- session . install ( 'pytest' )
31
- session .install ( '-e' , '.' )
57
+ # Set the virtualenv dirname.
58
+ session .virtualenv_dirname = 'unit-' + py
32
59
33
- session . run ( 'py.test' , '--quiet' , os . path . join ( 'tests' , 'unit' ) )
60
+ default ( session )
34
61
35
62
36
63
@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 ):
39
66
"""Run the system test suite."""
40
67
41
68
if not os .environ .get ('GOOGLE_APPLICATION_CREDENTIALS' , '' ):
42
69
session .skip ('Credentials must be set via environment variable.' )
43
70
44
- session .interpreter = 'python{}' .format (python_version )
71
+ session .interpreter = 'python{}' .format (py )
45
72
46
- session .virtualenv_dirname = 'sys-' + python_version
73
+ session .virtualenv_dirname = 'sys-' + py
47
74
48
75
session .install ('pytest' )
49
76
session .install ('-e' , '.' )
@@ -52,10 +79,37 @@ def system_tests(session, python_version):
52
79
os .path .join ('tests' , 'system' ), * session .posargs )
53
80
54
81
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
+
55
95
@nox .session
56
96
def lint_setup_py (session ):
57
97
"""Verify that setup.py is valid (including RST check)."""
58
98
session .interpreter = 'python3.6'
59
99
session .install ('docutils' , 'pygments' )
60
100
session .run ('python' , 'setup.py' , 'check' , '--restructuredtext' ,
61
101
'--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