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