From 96f2223e3389a0922e0f1db44df72c698cfa5263 Mon Sep 17 00:00:00 2001 From: MF2199 <38331387+mf2199@users.noreply.github.com> Date: Tue, 25 Aug 2020 19:59:59 -0400 Subject: [PATCH] feat: [WIP] The first stage of `nox` implementation (#468) --- .gitignore | 16 ++++++++++++---- .kokoro/build.sh | 19 +++++++++++++------ noxfile.py | 33 +++++++++++++++++++++++++++++++++ runtests.py | 30 ------------------------------ tox.ini | 24 ------------------------ 5 files changed, 58 insertions(+), 64 deletions(-) create mode 100644 noxfile.py delete mode 100644 runtests.py delete mode 100644 tox.ini diff --git a/.gitignore b/.gitignore index 10e8061ef3..863e1d3d77 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,16 @@ -*.egg-info *.py[co] -build/ *.sw[op] -.tox/ + +# Packages +*.egg-info +build MANIFEST -dist/ +dist django_tests + +# Unit test / coverage reports +.coverage +.nox + +# JetBrains +.idea diff --git a/.kokoro/build.sh b/.kokoro/build.sh index 077b737c5b..8d7113079a 100755 --- a/.kokoro/build.sh +++ b/.kokoro/build.sh @@ -29,13 +29,20 @@ export GOOGLE_APPLICATION_CREDENTIALS=${KOKORO_GFILE_DIR}/service-account.json # Setup project id. export PROJECT_ID=$(cat "${KOKORO_GFILE_DIR}/project-id.json") -# Install tox -python3.6 -m pip install --upgrade --quiet tox flake8 isort -python3.6 -m tox --version +# Remove old nox +python3.6 -m pip uninstall --yes --quiet nox-automation -python3.6 -m tox -python3.6 -m isort --recursive --check-only --diff -python3.6 -m flake8 +# Install nox +python3.6 -m pip install --upgrade --quiet nox +python3.6 -m nox --version + +# If NOX_SESSION is set, it only runs the specified session, +# otherwise run all the sessions. +if [[ -n "${NOX_SESSION:-}" ]]; then + python3.6 -m nox -s "${NOX_SESSION:-}" +else + python3.6 -m nox +fi # Export essential environment variables for Django tests. export RUNNING_SPANNER_BACKEND_TESTS=1 diff --git a/noxfile.py b/noxfile.py new file mode 100644 index 0000000000..1f6b4df1e5 --- /dev/null +++ b/noxfile.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- +# +# Copyright 2020 Google LLC +# +# Use of this source code is governed by a BSD-style +# license that can be found in the LICENSE file or at +# https://developers.google.com/open-source/licenses/bsd + + +from __future__ import absolute_import + +import nox +import os + + +def default(session): + # Install all test dependencies, then install this package in-place. + session.install("mock", "pytest", "pytest-cov") + session.install("-e", ".") + + # Run py.test against the unit tests. + session.run( + "py.test", + "--quiet", + os.path.join("tests", "spanner_dbapi"), + *session.posargs, + ) + + +@nox.session(python=["3.5", "3.6", "3.7", "3.8"]) +def unit(session): + """Run the unit test suite.""" + default(session) diff --git a/runtests.py b/runtests.py deleted file mode 100644 index c0ae9c3121..0000000000 --- a/runtests.py +++ /dev/null @@ -1,30 +0,0 @@ -# Copyright 2020 Google LLC -# -# Use of this source code is governed by a BSD-style -# license that can be found in the LICENSE file or at -# https://developers.google.com/open-source/licenses/bsd - -import sys -import unittest - - -def run_unittests(module): - test_suite = unittest.TestLoader().discover(module) - result = unittest.TextTestRunner(verbosity=1).run(test_suite) - sys.exit(any(result.failures or result.errors)) - - -def run_parse_util_tests(): - pass - - -def run_django_tests(): - raise Exception('Unimplemented') - - -def main(): - run_unittests('tests.spanner_dbapi') - - -if __name__ == '__main__': - main() diff --git a/tox.ini b/tox.ini deleted file mode 100644 index 94d9bbe241..0000000000 --- a/tox.ini +++ /dev/null @@ -1,24 +0,0 @@ -[tox] -envlist = - py3{7}-django{22} - flake8 - -[testenv] -setenv = - PYTHONDONTWRITEBYTECODE = 1 - PYTHONWARNINGS = all -deps = - django21: Django>=2.1,<2.2 - django22: Django>=2.2,<3.0 - six -commands = - python runtests.py - -[testenv:flake8] -skip_install = True -deps = - flake8 - isort -commands = - flake8 - isort --recursive --check-only --diff