1# Copyright 2020 Google LLC
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#      http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15import os
16import nox
17import shutil
18
19test_dependencies = [
20    "django>=2.0.0",
21    "google-auth",
22    "google-auth-httplib2",
23    "mox",
24    "parameterized",
25    "pyopenssl",
26    "pytest",
27    "pytest-cov",
28    "webtest",
29    "coverage",
30    "mock",
31]
32
33
34@nox.session(python=["3.7"])
35def lint(session):
36    session.install("flake8")
37    session.run(
38        "flake8",
39        "googleapiclient",
40        "tests",
41        "--count",
42        "--select=E9,F63,F7,F82",
43        "--show-source",
44        "--statistics",
45    )
46
47
48@nox.session(python=["3.6", "3.7", "3.8", "3.9", "3.10"])
49@nox.parametrize(
50    "oauth2client",
51    [
52        "oauth2client<2dev",
53        "oauth2client>=2,<=3dev",
54        "oauth2client>=3,<=4dev",
55        "oauth2client>=4,<=5dev",
56    ],
57)
58def unit(session, oauth2client):
59    # Clean up dist and build folders
60    shutil.rmtree("dist", ignore_errors=True)
61    shutil.rmtree("build", ignore_errors=True)
62
63    session.install(*test_dependencies)
64    session.install(oauth2client)
65
66    # Create and install wheels
67    session.run("python3", "setup.py", "bdist_wheel")
68    session.install(os.path.join("dist", os.listdir("dist").pop()))
69
70    # Run tests from a different directory to test the package artifacts
71    root_dir = os.path.dirname(os.path.realpath(__file__))
72    temp_dir = session.create_tmp()
73    session.chdir(temp_dir)
74    shutil.copytree(os.path.join(root_dir, "tests"), "tests")
75
76    # Run py.test against the unit tests.
77    session.run(
78        "py.test",
79        "--quiet",
80        "--cov=googleapiclient",
81        "--cov=tests",
82        "--cov-append",
83        "--cov-config=.coveragerc",
84        "--cov-report=",
85        "--cov-fail-under=85",
86        "tests",
87        *session.posargs,
88    )
89
90
91@nox.session(python=["3.9"])
92def scripts(session):
93    session.install(*test_dependencies)
94    session.install("-e", ".")
95    session.install("-r", "scripts/requirements.txt")
96
97    # Run py.test against the unit tests.
98    session.run(
99        "py.test",
100        "--quiet",
101        "--cov=scripts",
102        "--cov-config=.coveragerc",
103        "--cov-report=",
104        "--cov-fail-under=91",
105        "scripts",
106        *session.posargs,
107    )
108