Bu Sun Kim | f706cfd | 2020-04-20 14:05:05 -0700 | [diff] [blame] | 1 | |
| 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 Partheniou | aff037a | 2021-04-21 11:00:09 -0400 | [diff] [blame] | 16 | import os |
Bu Sun Kim | 673ec5c | 2020-11-16 11:05:03 -0700 | [diff] [blame] | 17 | import sys |
| 18 | |
Bu Sun Kim | f706cfd | 2020-04-20 14:05:05 -0700 | [diff] [blame] | 19 | import nox |
Anthonios Partheniou | ff1e936 | 2021-04-20 11:02:03 -0400 | [diff] [blame] | 20 | import os |
| 21 | import shutil |
Bu Sun Kim | f706cfd | 2020-04-20 14:05:05 -0700 | [diff] [blame] | 22 | |
| 23 | test_dependencies = [ |
Bu Sun Kim | 8325d24 | 2020-12-09 12:04:05 -0700 | [diff] [blame] | 24 | "django>=2.0.0", |
Bu Sun Kim | f706cfd | 2020-04-20 14:05:05 -0700 | [diff] [blame] | 25 | "google-auth", |
| 26 | "google-auth-httplib2", |
| 27 | "mox", |
arithmetic1728 | 981eadf | 2020-06-02 10:20:10 -0700 | [diff] [blame] | 28 | "parameterized", |
Bu Sun Kim | f706cfd | 2020-04-20 14:05:05 -0700 | [diff] [blame] | 29 | "pyopenssl", |
| 30 | "pytest", |
| 31 | "pytest-cov", |
| 32 | "webtest", |
| 33 | "coverage", |
| 34 | "unittest2", |
| 35 | "mock", |
| 36 | ] |
| 37 | |
| 38 | |
| 39 | @nox.session(python=["3.7"]) |
| 40 | def 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 Kim | 8325d24 | 2020-12-09 12:04:05 -0700 | [diff] [blame] | 53 | @nox.session(python=["3.6", "3.7", "3.8", "3.9"]) |
Bu Sun Kim | f706cfd | 2020-04-20 14:05:05 -0700 | [diff] [blame] | 54 | @nox.parametrize( |
| 55 | "oauth2client", |
| 56 | [ |
| 57 | "oauth2client<2dev", |
| 58 | "oauth2client>=2,<=3dev", |
| 59 | "oauth2client>=3,<=4dev", |
| 60 | "oauth2client>=4,<=5dev", |
| 61 | ], |
| 62 | ) |
Bu Sun Kim | f706cfd | 2020-04-20 14:05:05 -0700 | [diff] [blame] | 63 | def unit(session, oauth2client): |
Anthonios Partheniou | ff1e936 | 2021-04-20 11:02:03 -0400 | [diff] [blame] | 64 | # Clean up dist and build folders |
| 65 | shutil.rmtree('dist', ignore_errors=True) |
| 66 | shutil.rmtree('build', ignore_errors=True) |
| 67 | |
Bu Sun Kim | f706cfd | 2020-04-20 14:05:05 -0700 | [diff] [blame] | 68 | session.install(*test_dependencies) |
| 69 | session.install(oauth2client) |
Anthonios Partheniou | ff1e936 | 2021-04-20 11:02:03 -0400 | [diff] [blame] | 70 | |
| 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 Kim | f706cfd | 2020-04-20 14:05:05 -0700 | [diff] [blame] | 80 | |
| 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, |
arithmetic1728 | 981eadf | 2020-06-02 10:20:10 -0700 | [diff] [blame] | 93 | ) |
Anthonios Partheniou | aff037a | 2021-04-21 11:00:09 -0400 | [diff] [blame] | 94 | |
| 95 | @nox.session(python=["3.9"]) |
| 96 | def 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 Partheniou | 6a88422 | 2021-05-10 22:14:57 -0400 | [diff] [blame^] | 108 | "--cov-fail-under=91", |
Anthonios Partheniou | aff037a | 2021-04-21 11:00:09 -0400 | [diff] [blame] | 109 | "scripts", |
| 110 | *session.posargs, |
| 111 | ) |