|
29 | 29 | # ---------------------------------------------------------------------------- |
30 | 30 | templated_files = common.py_library( |
31 | 31 | unit_test_python_versions=["3.6", "3.7", "3.8", "3.9"], |
32 | | - system_test_python_versions=["3.8"], |
33 | | - cov_level=50 |
| 32 | + system_test_python_versions=["3.8", "3.9"], |
| 33 | + cov_level=100 |
34 | 34 | ) |
35 | 35 | s.move(templated_files, excludes=[ |
36 | 36 | # pybigquery was originally licensed MIT |
|
41 | 41 | # Fixup files |
42 | 42 | # ---------------------------------------------------------------------------- |
43 | 43 |
|
| 44 | +s.replace( |
| 45 | + [".coveragerc"], |
| 46 | + "google/cloud/__init__.py", |
| 47 | + "pybigquery/requirements.py", |
| 48 | + ) |
| 49 | + |
44 | 50 | s.replace( |
45 | 51 | ["noxfile.py"], |
46 | 52 | r"[\"']google[\"']", |
|
51 | 57 | ["noxfile.py"], "google/cloud", "pybigquery", |
52 | 58 | ) |
53 | 59 |
|
| 60 | +def place_before(path, text, *before_text, escape=None): |
| 61 | + replacement = "\n".join(before_text) + "\n" + text |
| 62 | + if escape: |
| 63 | + for c in escape: |
| 64 | + text = text.replace(c, '\\' + c) |
| 65 | + s.replace([path], text, replacement) |
| 66 | + |
| 67 | +place_before( |
| 68 | + "noxfile.py", |
| 69 | + "SYSTEM_TEST_PYTHON_VERSIONS=", |
| 70 | + "", |
| 71 | + "# We're using two Python versions to test with sqlalchemy 1.3 and 1.4.", |
| 72 | +) |
| 73 | + |
| 74 | +place_before( |
| 75 | + "noxfile.py", |
| 76 | + "nox.options.error_on_missing_interpreters = True", |
| 77 | + "nox.options.stop_on_first_error = True", |
| 78 | +) |
| 79 | + |
| 80 | +install_alembic_for_python_38 = ''' |
| 81 | +def install_alembic_for_python_38(session, constraints_path): |
| 82 | + """ |
| 83 | + install alembic for Python 3.8 unit and system tests |
| 84 | +
|
| 85 | + We do not require alembic and most tests should run without it, however |
| 86 | +
|
| 87 | + - We run some unit tests (Python 3.8) to cover the alembic |
| 88 | + registration that happens when alembic is installed. |
| 89 | +
|
| 90 | + - We have a system test that demonstrates working with alembic and |
| 91 | + proves that the things we think should work do work. :) |
| 92 | + """ |
| 93 | + if session.python == "3.8": |
| 94 | + session.install("alembic", "-c", constraints_path) |
| 95 | +
|
| 96 | +
|
| 97 | +''' |
| 98 | + |
| 99 | +place_before( |
| 100 | + "noxfile.py", |
| 101 | + "def default", |
| 102 | + install_alembic_for_python_38, |
| 103 | + ) |
| 104 | + |
| 105 | +place_before( |
| 106 | + "noxfile.py", |
| 107 | + ' session.install("-e", ".", ', |
| 108 | + " install_alembic_for_python_38(session, constraints_path)", |
| 109 | + escape='(') |
| 110 | + |
| 111 | +old_sessions = ''' |
| 112 | + "unit", |
| 113 | + "system", |
| 114 | + "cover", |
| 115 | + "lint", |
| 116 | +''' |
| 117 | + |
| 118 | +new_sessions = ''' |
| 119 | + "lint", |
| 120 | + "unit", |
| 121 | + "cover", |
| 122 | + "system", |
| 123 | + "compliance", |
| 124 | +''' |
| 125 | + |
| 126 | +s.replace( ["noxfile.py"], old_sessions, new_sessions) |
| 127 | + |
| 128 | +compliance = ''' |
| 129 | +@nox.session(python=SYSTEM_TEST_PYTHON_VERSIONS) |
| 130 | +def compliance(session): |
| 131 | + """Run the SQLAlchemy dialect-compliance system tests""" |
| 132 | + constraints_path = str( |
| 133 | + CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt" |
| 134 | + ) |
| 135 | + system_test_folder_path = os.path.join("tests", "sqlalchemy_dialect_compliance") |
| 136 | +
|
| 137 | + if os.environ.get("RUN_COMPLIANCE_TESTS", "true") == "false": |
| 138 | + session.skip("RUN_COMPLIANCE_TESTS is set to false, skipping") |
| 139 | + if not os.environ.get("GOOGLE_APPLICATION_CREDENTIALS", ""): |
| 140 | + session.skip("Credentials must be set via environment variable") |
| 141 | + if os.environ.get("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") == "true": |
| 142 | + session.install("pyopenssl") |
| 143 | + if not os.path.exists(system_test_folder_path): |
| 144 | + session.skip("Compliance tests were not found") |
| 145 | +
|
| 146 | + session.install("--pre", "grpcio") |
| 147 | +
|
| 148 | + session.install( |
| 149 | + "mock", |
| 150 | + "pytest", |
| 151 | + "pytest-rerunfailures", |
| 152 | + "google-cloud-testutils", |
| 153 | + "-c", |
| 154 | + constraints_path, |
| 155 | + ) |
| 156 | + session.install("-e", ".", "-c", constraints_path) |
| 157 | +
|
| 158 | + session.run( |
| 159 | + "py.test", |
| 160 | + "-vv", |
| 161 | + f"--junitxml=compliance_{session.python}_sponge_log.xml", |
| 162 | + "--reruns=3", |
| 163 | + "--reruns-delay=60", |
| 164 | + "--only-rerun=403 Exceeded rate limits", |
| 165 | + "--only-rerun=409 Already Exists", |
| 166 | + "--only-rerun=404 Not found", |
| 167 | + "--only-rerun=400 Cannot execute DML over a non-existent table", |
| 168 | + system_test_folder_path, |
| 169 | + *session.posargs, |
| 170 | + ) |
| 171 | +
|
| 172 | +
|
| 173 | +''' |
| 174 | + |
| 175 | +place_before( |
| 176 | + "noxfile.py", |
| 177 | + "@nox.session(python=DEFAULT_PYTHON_VERSION)\n" |
| 178 | + "def cover(session):", |
| 179 | + compliance, |
| 180 | + escape="()", |
| 181 | + ) |
| 182 | + |
| 183 | + |
| 184 | + |
| 185 | + |
54 | 186 | # Add DB config for SQLAlchemy dialect test suite. |
55 | 187 | # https://github.com/sqlalchemy/sqlalchemy/blob/master/README.dialects.rst |
56 | 188 | # https://github.com/googleapis/python-bigquery-sqlalchemy/issues/89 |
|
61 | 193 |
|
62 | 194 | [sqla_testing] |
63 | 195 | requirement_cls=pybigquery.requirements:Requirements |
64 | | -profile_file=.profiles.txt |
| 196 | +profile_file=.sqlalchemy_dialect_compliance-profiles.txt |
65 | 197 |
|
66 | | -[db] |
67 | | -default=bigquery:// |
68 | | -bigquery=bigquery:// |
| 198 | +[tool:pytest] |
| 199 | +addopts= --tb native -v -r fxX -p no:warnings |
| 200 | +python_files=tests/*test_*.py |
69 | 201 | """ |
70 | 202 | ) |
71 | 203 |
|
|
0 commit comments