blob: 3e23830ce36706f89c204ba3f48adc01be3bbde0 [file] [log] [blame]
Bu Sun Kimf706cfd2020-04-20 14:05:05 -07001# 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
Anthonios Partheniouaff037a2021-04-21 11:00:09 -040015import os
Bu Sun Kimf706cfd2020-04-20 14:05:05 -070016import nox
Anthonios Partheniouff1e9362021-04-20 11:02:03 -040017import shutil
Bu Sun Kimf706cfd2020-04-20 14:05:05 -070018
19test_dependencies = [
Bu Sun Kim8325d242020-12-09 12:04:05 -070020 "django>=2.0.0",
Bu Sun Kimf706cfd2020-04-20 14:05:05 -070021 "google-auth",
22 "google-auth-httplib2",
23 "mox",
arithmetic1728981eadf2020-06-02 10:20:10 -070024 "parameterized",
Bu Sun Kimf706cfd2020-04-20 14:05:05 -070025 "pyopenssl",
26 "pytest",
27 "pytest-cov",
28 "webtest",
29 "coverage",
Bu Sun Kimf706cfd2020-04-20 14:05:05 -070030 "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
Anthonios Parthenioubcc507f2021-10-12 12:49:54 -040048@nox.session(python=["3.6", "3.7", "3.8", "3.9", "3.10"])
Bu Sun Kimf706cfd2020-04-20 14:05:05 -070049@nox.parametrize(
50 "oauth2client",
51 [
52 "oauth2client<2dev",
53 "oauth2client>=2,<=3dev",
54 "oauth2client>=3,<=4dev",
55 "oauth2client>=4,<=5dev",
56 ],
57)
Bu Sun Kimf706cfd2020-04-20 14:05:05 -070058def unit(session, oauth2client):
Anthonios Partheniouff1e9362021-04-20 11:02:03 -040059 # Clean up dist and build folders
arfy slowyd35c9122021-07-15 00:16:31 +070060 shutil.rmtree("dist", ignore_errors=True)
61 shutil.rmtree("build", ignore_errors=True)
Anthonios Partheniouff1e9362021-04-20 11:02:03 -040062
Bu Sun Kimf706cfd2020-04-20 14:05:05 -070063 session.install(*test_dependencies)
64 session.install(oauth2client)
Anthonios Partheniouff1e9362021-04-20 11:02:03 -040065
66 # Create and install wheels
arfy slowyd35c9122021-07-15 00:16:31 +070067 session.run("python3", "setup.py", "bdist_wheel")
68 session.install(os.path.join("dist", os.listdir("dist").pop()))
Anthonios Partheniouff1e9362021-04-20 11:02:03 -040069
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)
arfy slowyd35c9122021-07-15 00:16:31 +070074 shutil.copytree(os.path.join(root_dir, "tests"), "tests")
Bu Sun Kimf706cfd2020-04-20 14:05:05 -070075
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,
arithmetic1728981eadf2020-06-02 10:20:10 -070088 )
Anthonios Partheniouaff037a2021-04-21 11:00:09 -040089
arfy slowyd35c9122021-07-15 00:16:31 +070090
Anthonios Partheniouaff037a2021-04-21 11:00:09 -040091@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=",
Anthonios Partheniou6a884222021-05-10 22:14:57 -0400104 "--cov-fail-under=91",
Anthonios Partheniouaff037a2021-04-21 11:00:09 -0400105 "scripts",
106 *session.posargs,
107 )