blob: 6e2cadc3b36396958f9d65b1f05c9972d1f21fd6 [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",
30 "unittest2",
31 "mock",
32]
33
34
35@nox.session(python=["3.7"])
36def lint(session):
37 session.install("flake8")
38 session.run(
39 "flake8",
40 "googleapiclient",
41 "tests",
42 "--count",
43 "--select=E9,F63,F7,F82",
44 "--show-source",
45 "--statistics",
46 )
47
48
Bu Sun Kim8325d242020-12-09 12:04:05 -070049@nox.session(python=["3.6", "3.7", "3.8", "3.9"])
Bu Sun Kimf706cfd2020-04-20 14:05:05 -070050@nox.parametrize(
51 "oauth2client",
52 [
53 "oauth2client<2dev",
54 "oauth2client>=2,<=3dev",
55 "oauth2client>=3,<=4dev",
56 "oauth2client>=4,<=5dev",
57 ],
58)
Bu Sun Kimf706cfd2020-04-20 14:05:05 -070059def unit(session, oauth2client):
Anthonios Partheniouff1e9362021-04-20 11:02:03 -040060 # Clean up dist and build folders
arfy slowyd35c9122021-07-15 00:16:31 +070061 shutil.rmtree("dist", ignore_errors=True)
62 shutil.rmtree("build", ignore_errors=True)
Anthonios Partheniouff1e9362021-04-20 11:02:03 -040063
Bu Sun Kimf706cfd2020-04-20 14:05:05 -070064 session.install(*test_dependencies)
65 session.install(oauth2client)
Anthonios Partheniouff1e9362021-04-20 11:02:03 -040066
67 # Create and install wheels
arfy slowyd35c9122021-07-15 00:16:31 +070068 session.run("python3", "setup.py", "bdist_wheel")
69 session.install(os.path.join("dist", os.listdir("dist").pop()))
Anthonios Partheniouff1e9362021-04-20 11:02:03 -040070
71 # Run tests from a different directory to test the package artifacts
72 root_dir = os.path.dirname(os.path.realpath(__file__))
73 temp_dir = session.create_tmp()
74 session.chdir(temp_dir)
arfy slowyd35c9122021-07-15 00:16:31 +070075 shutil.copytree(os.path.join(root_dir, "tests"), "tests")
Bu Sun Kimf706cfd2020-04-20 14:05:05 -070076
77 # Run py.test against the unit tests.
78 session.run(
79 "py.test",
80 "--quiet",
81 "--cov=googleapiclient",
82 "--cov=tests",
83 "--cov-append",
84 "--cov-config=.coveragerc",
85 "--cov-report=",
86 "--cov-fail-under=85",
87 "tests",
88 *session.posargs,
arithmetic1728981eadf2020-06-02 10:20:10 -070089 )
Anthonios Partheniouaff037a2021-04-21 11:00:09 -040090
arfy slowyd35c9122021-07-15 00:16:31 +070091
Anthonios Partheniouaff037a2021-04-21 11:00:09 -040092@nox.session(python=["3.9"])
93def scripts(session):
94 session.install(*test_dependencies)
95 session.install("-e", ".")
96 session.install("-r", "scripts/requirements.txt")
97
98 # Run py.test against the unit tests.
99 session.run(
100 "py.test",
101 "--quiet",
102 "--cov=scripts",
103 "--cov-config=.coveragerc",
104 "--cov-report=",
Anthonios Partheniou6a884222021-05-10 22:14:57 -0400105 "--cov-fail-under=91",
Anthonios Partheniouaff037a2021-04-21 11:00:09 -0400106 "scripts",
107 *session.posargs,
108 )