forked from GoogleCloudPlatform/data-migration-tool
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnoxfile.py
More file actions
129 lines (106 loc) · 3.69 KB
/
noxfile.py
File metadata and controls
129 lines (106 loc) · 3.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# Copyright 2023 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Configuration for test sessions.
This is a configuration file for use with `nox <https://nox.thea.codes/>`__.
This configuration is modelled after the one for the `google-cloud-biguery
<https://github.com/googleapis/python-bigquery/blob/master/noxfile.py>`__
package.
"""
import os
import nox
# Python version used for linting.
DEFAULT_PYTHON_VERSION = "3.8"
# Python versions used for testing.
PYTHON_VERSIONS = ["3.7", "3.8", "3.9", "3.10"]
LINT_PACKAGES = ["flake8", "black==22.3.0", "isort"]
def _setup_session_requirements(session, extra_packages=[]):
"""Install requirements for nox tests."""
session.install(
"--upgrade", "pip", "pytest", "pytest-mock", "wheel", "testfixtures"
)
if extra_packages:
session.install(*extra_packages)
@nox.session(python=DEFAULT_PYTHON_VERSION, venv_backend="venv")
def lint(session):
"""Run linters.
Returns a failure if the linters find linting errors or sufficiently
serious code quality issues.
"""
_setup_session_requirements(session, extra_packages=LINT_PACKAGES)
session.run("flake8", ".")
session.run("isort", "--check", "--profile=black", ".")
session.run("black", "--check", ".")
@nox.session(python=DEFAULT_PYTHON_VERSION, venv_backend="venv")
def format_all(session):
"""Run black and isort.
Format code to uniform standard.
"""
# Pin a specific version of black, so that the linter doesn't conflict with
# contributors.
_setup_session_requirements(session, extra_packages=LINT_PACKAGES)
session.run("black", ".")
session.run("isort", "--profile=black", ".")
@nox.session(python=DEFAULT_PYTHON_VERSION, venv_backend="venv")
def unit(session):
_setup_session_requirements(session)
test_paths = [os.path.join("src")]
session.install(
"--upgrade",
"-r",
os.path.join(
"src",
"tests",
"requirements-test.txt",
),
)
# Run pytest against the unit tests in all test paths assigned above.
for test_path in test_paths:
session.run(
"pytest",
"--quiet",
test_path,
)
@nox.session(python=DEFAULT_PYTHON_VERSION, venv_backend="venv")
def integration(session):
_setup_session_requirements(session)
pr_no = os.environ.get("PR_NUMBER")
print(pr_no)
print(os.environ.get("BUILD_ID"))
if pr_no != "":
session.install(
"--upgrade",
"-r",
os.path.join(
"src",
"tests",
"requirements-test.txt",
),
)
test_path = "src/tests/end_to_end/end_to_end.py"
expected_env_vars = [
"PROJECT_ID",
"TERADATA_IP",
"TERADATA_UNAME",
"TERADATA_SCHEMA",
"ORACLE_IP",
"ORACLE_UNAME",
"ORACLE_SCHEMA",
"ORACLE_DATABASE",
]
for env_var in expected_env_vars:
if not os.environ.get(env_var, ""):
raise Exception("Expected Env Var: %s" % env_var)
session.run("python3", test_path)
else:
print("Trigger build is not for PR")