|
| 1 | +import fnmatch |
| 2 | +import os |
| 3 | + |
| 4 | +import nox |
| 5 | + |
| 6 | +REPO_TOOLS_REQ =\ |
| 7 | + 'git+https://github.com/GoogleCloudPlatform/python-repo-tools.git' |
| 8 | + |
| 9 | + |
| 10 | +def session_lint(session): |
| 11 | + session.install('flake8', 'flake8-import-order') |
| 12 | + session.run( |
| 13 | + 'flake8', '--builtin=gettext', '--max-complexity=10', |
| 14 | + '--import-order-style=google', |
| 15 | + '--exclude', |
| 16 | + 'container_engine/django_tutorial/polls/migrations/*,.nox,.cache,env', |
| 17 | + *(session.posargs or ['.'])) |
| 18 | + |
| 19 | + |
| 20 | +def list_files(folder, pattern): |
| 21 | + for root, folders, files in os.walk(folder): |
| 22 | + for filename in files: |
| 23 | + if fnmatch.fnmatch(filename, pattern): |
| 24 | + yield os.path.join(root, filename) |
| 25 | + |
| 26 | + |
| 27 | +def session_reqcheck(session): |
| 28 | + session.install(REPO_TOOLS_REQ) |
| 29 | + |
| 30 | + if 'update' in session.posargs: |
| 31 | + command = 'update-requirements' |
| 32 | + else: |
| 33 | + command = 'check-requirements' |
| 34 | + |
| 35 | + for reqfile in list_files('.', 'requirements*.txt'): |
| 36 | + session.run('gcprepotools', command, reqfile) |
| 37 | + |
| 38 | + |
| 39 | +COMMON_PYTEST_ARGS = [ |
| 40 | + '-x', '--no-success-flaky-report', '--cov', '--cov-config', |
| 41 | + '.coveragerc', '--cov-append', '--cov-report='] |
| 42 | + |
| 43 | +SAMPLES = [ |
| 44 | + 'bigquery/api', |
| 45 | + 'blog/introduction_to_data_models_in_cloud_datastore', |
| 46 | + 'cloud_logging/api', |
| 47 | + 'compute/api', |
| 48 | + 'compute/autoscaler/demo', |
| 49 | + 'datastore/api', |
| 50 | + 'managed_vms/cloudsql', |
| 51 | + 'managed_vms/datastore', |
| 52 | + 'managed_vms/disk', |
| 53 | + 'managed_vms/extending_runtime', |
| 54 | + 'managed_vms/hello_world', |
| 55 | + 'managed_vms/hello_world_compat', |
| 56 | + 'managed_vms/memcache', |
| 57 | + 'managed_vms/pubsub', |
| 58 | + 'managed_vms/static_files', |
| 59 | + 'managed_vms/storage', |
| 60 | + 'monitoring/api', |
| 61 | + 'storage/api', |
| 62 | +] |
| 63 | + |
| 64 | + |
| 65 | +@nox.parametrize('interpreter', ['python2.7', 'python3.4']) |
| 66 | +def session_tests(session, interpreter, extra_pytest_args=None): |
| 67 | + session.interpreter = interpreter |
| 68 | + session.install(REPO_TOOLS_REQ) |
| 69 | + session.install('-r', 'requirements-{}-dev.txt'.format(interpreter)) |
| 70 | + |
| 71 | + pytest_args = COMMON_PYTEST_ARGS + (extra_pytest_args or []) |
| 72 | + |
| 73 | + for sample in (session.posargs or SAMPLES): |
| 74 | + session.run( |
| 75 | + 'py.test', sample, |
| 76 | + *pytest_args, |
| 77 | + success_codes=[0, 5]) # Treat no test collected as success. |
| 78 | + |
| 79 | + |
| 80 | +def session_travis(session): |
| 81 | + """On travis, just run with python3.4 and don't run slow or flaky tests.""" |
| 82 | + session_tests( |
| 83 | + session, 'python3.4', extra_pytest_args=['-m not slow and not flaky']) |
0 commit comments