Bu Sun Kim | f706cfd | 2020-04-20 14:05:05 -0700 | [diff] [blame] | 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 | |
Anthonios Partheniou | aff037a | 2021-04-21 11:00:09 -0400 | [diff] [blame] | 15 | import os |
Bu Sun Kim | f706cfd | 2020-04-20 14:05:05 -0700 | [diff] [blame] | 16 | import nox |
Anthonios Partheniou | ff1e936 | 2021-04-20 11:02:03 -0400 | [diff] [blame] | 17 | import shutil |
Bu Sun Kim | f706cfd | 2020-04-20 14:05:05 -0700 | [diff] [blame] | 18 | |
| 19 | test_dependencies = [ |
Bu Sun Kim | 8325d24 | 2020-12-09 12:04:05 -0700 | [diff] [blame] | 20 | "django>=2.0.0", |
Bu Sun Kim | f706cfd | 2020-04-20 14:05:05 -0700 | [diff] [blame] | 21 | "google-auth", |
| 22 | "google-auth-httplib2", |
| 23 | "mox", |
arithmetic1728 | 981eadf | 2020-06-02 10:20:10 -0700 | [diff] [blame] | 24 | "parameterized", |
Bu Sun Kim | f706cfd | 2020-04-20 14:05:05 -0700 | [diff] [blame] | 25 | "pyopenssl", |
| 26 | "pytest", |
| 27 | "pytest-cov", |
| 28 | "webtest", |
| 29 | "coverage", |
Bu Sun Kim | f706cfd | 2020-04-20 14:05:05 -0700 | [diff] [blame] | 30 | "mock", |
| 31 | ] |
| 32 | |
| 33 | |
| 34 | @nox.session(python=["3.7"]) |
| 35 | def 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 Partheniou | bcc507f | 2021-10-12 12:49:54 -0400 | [diff] [blame] | 48 | @nox.session(python=["3.6", "3.7", "3.8", "3.9", "3.10"]) |
Bu Sun Kim | f706cfd | 2020-04-20 14:05:05 -0700 | [diff] [blame] | 49 | @nox.parametrize( |
| 50 | "oauth2client", |
| 51 | [ |
| 52 | "oauth2client<2dev", |
| 53 | "oauth2client>=2,<=3dev", |
| 54 | "oauth2client>=3,<=4dev", |
| 55 | "oauth2client>=4,<=5dev", |
| 56 | ], |
| 57 | ) |
Bu Sun Kim | f706cfd | 2020-04-20 14:05:05 -0700 | [diff] [blame] | 58 | def unit(session, oauth2client): |
Anthonios Partheniou | ff1e936 | 2021-04-20 11:02:03 -0400 | [diff] [blame] | 59 | # Clean up dist and build folders |
arfy slowy | d35c912 | 2021-07-15 00:16:31 +0700 | [diff] [blame] | 60 | shutil.rmtree("dist", ignore_errors=True) |
| 61 | shutil.rmtree("build", ignore_errors=True) |
Anthonios Partheniou | ff1e936 | 2021-04-20 11:02:03 -0400 | [diff] [blame] | 62 | |
Bu Sun Kim | f706cfd | 2020-04-20 14:05:05 -0700 | [diff] [blame] | 63 | session.install(*test_dependencies) |
| 64 | session.install(oauth2client) |
Anthonios Partheniou | ff1e936 | 2021-04-20 11:02:03 -0400 | [diff] [blame] | 65 | |
| 66 | # Create and install wheels |
arfy slowy | d35c912 | 2021-07-15 00:16:31 +0700 | [diff] [blame] | 67 | session.run("python3", "setup.py", "bdist_wheel") |
| 68 | session.install(os.path.join("dist", os.listdir("dist").pop())) |
Anthonios Partheniou | ff1e936 | 2021-04-20 11:02:03 -0400 | [diff] [blame] | 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) |
arfy slowy | d35c912 | 2021-07-15 00:16:31 +0700 | [diff] [blame] | 74 | shutil.copytree(os.path.join(root_dir, "tests"), "tests") |
Bu Sun Kim | f706cfd | 2020-04-20 14:05:05 -0700 | [diff] [blame] | 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, |
arithmetic1728 | 981eadf | 2020-06-02 10:20:10 -0700 | [diff] [blame] | 88 | ) |
Anthonios Partheniou | aff037a | 2021-04-21 11:00:09 -0400 | [diff] [blame] | 89 | |
arfy slowy | d35c912 | 2021-07-15 00:16:31 +0700 | [diff] [blame] | 90 | |
Anthonios Partheniou | aff037a | 2021-04-21 11:00:09 -0400 | [diff] [blame] | 91 | @nox.session(python=["3.9"]) |
| 92 | def 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 Partheniou | 6a88422 | 2021-05-10 22:14:57 -0400 | [diff] [blame] | 104 | "--cov-fail-under=91", |
Anthonios Partheniou | aff037a | 2021-04-21 11:00:09 -0400 | [diff] [blame] | 105 | "scripts", |
| 106 | *session.posargs, |
| 107 | ) |