GeezerVison is showing github.com — chore(samples): Add check for tests in directory (#949) · kthytang/python-aiplatform@4bfa11b
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboard +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | docker: | 2 | 2 | image: gcr.io/cloud-devrel-public-resources/owlbot-python:latest | 3 | | - digest: sha256:0e18b9475fbeb12d9ad4302283171edebb6baf2dfca1bd215ee3b34ed79d95d7 | | 3 | + digest: sha256:36a95b8f494e4674dc9eee9af98961293b51b86b3649942aac800ae6c1f796d4 |
Collapse file Copy file name to clipboardExpand all lines: samples/model-builder/noxfile.py +39-31Lines changed: 39 additions & 31 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 14 | 14 |
| 15 | 15 | from __future__ import print_function | 16 | 16 |
| | 17 | +import glob | 17 | 18 | import os | 18 | 19 | from pathlib import Path | 19 | 20 | import sys | @@ -184,37 +185,44 @@ def blacken(session: nox.sessions.Session) -> None: | 184 | 185 | def _session_tests( | 185 | 186 | session: nox.sessions.Session, post_install: Callable = None | 186 | 187 | ) -> None: | 187 | | - if TEST_CONFIG["pip_version_override"]: | 188 | | - pip_version = TEST_CONFIG["pip_version_override"] | 189 | | - session.install(f"pip=={pip_version}") | 190 | | - """Runs py.test for a particular project.""" | 191 | | - if os.path.exists("requirements.txt"): | 192 | | - if os.path.exists("constraints.txt"): | 193 | | - session.install("-r", "requirements.txt", "-c", "constraints.txt") | 194 | | - else: | 195 | | - session.install("-r", "requirements.txt") | 196 | | - | 197 | | - if os.path.exists("requirements-test.txt"): | 198 | | - if os.path.exists("constraints-test.txt"): | 199 | | - session.install("-r", "requirements-test.txt", "-c", "constraints-test.txt") | 200 | | - else: | 201 | | - session.install("-r", "requirements-test.txt") | 202 | | - | 203 | | - if INSTALL_LIBRARY_FROM_SOURCE: | 204 | | - session.install("-e", _get_repo_root()) | 205 | | - | 206 | | - if post_install: | 207 | | - post_install(session) | 208 | | - | 209 | | - session.run( | 210 | | - "pytest", | 211 | | - *(PYTEST_COMMON_ARGS + session.posargs), | 212 | | - # Pytest will return 5 when no tests are collected. This can happen | 213 | | - # on travis where slow and flaky tests are excluded. | 214 | | - # See http://doc.pytest.org/en/latest/_modules/_pytest/main.html | 215 | | - success_codes=[0, 5], | 216 | | - env=get_pytest_env_vars(), | 217 | | - ) | | 188 | + # check for presence of tests | | 189 | + test_list = glob.glob("*_test.py") + glob.glob("test_*.py") | | 190 | + if len(test_list) == 0: | | 191 | + print("No tests found, skipping directory.") | | 192 | + else: | | 193 | + if TEST_CONFIG["pip_version_override"]: | | 194 | + pip_version = TEST_CONFIG["pip_version_override"] | | 195 | + session.install(f"pip=={pip_version}") | | 196 | + """Runs py.test for a particular project.""" | | 197 | + if os.path.exists("requirements.txt"): | | 198 | + if os.path.exists("constraints.txt"): | | 199 | + session.install("-r", "requirements.txt", "-c", "constraints.txt") | | 200 | + else: | | 201 | + session.install("-r", "requirements.txt") | | 202 | + | | 203 | + if os.path.exists("requirements-test.txt"): | | 204 | + if os.path.exists("constraints-test.txt"): | | 205 | + session.install( | | 206 | + "-r", "requirements-test.txt", "-c", "constraints-test.txt" | | 207 | + ) | | 208 | + else: | | 209 | + session.install("-r", "requirements-test.txt") | | 210 | + | | 211 | + if INSTALL_LIBRARY_FROM_SOURCE: | | 212 | + session.install("-e", _get_repo_root()) | | 213 | + | | 214 | + if post_install: | | 215 | + post_install(session) | | 216 | + | | 217 | + session.run( | | 218 | + "pytest", | | 219 | + *(PYTEST_COMMON_ARGS + session.posargs), | | 220 | + # Pytest will return 5 when no tests are collected. This can happen | | 221 | + # on travis where slow and flaky tests are excluded. | | 222 | + # See http://doc.pytest.org/en/latest/_modules/_pytest/main.html | | 223 | + success_codes=[0, 5], | | 224 | + env=get_pytest_env_vars(), | | 225 | + ) | 218 | 226 |
| 219 | 227 |
| 220 | 228 | @nox.session(python=ALL_VERSIONS) | |
Collapse file Copy file name to clipboardExpand all lines: samples/snippets/noxfile.py +39-31Lines changed: 39 additions & 31 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 14 | 14 |
| 15 | 15 | from __future__ import print_function | 16 | 16 |
| | 17 | +import glob | 17 | 18 | import os | 18 | 19 | from pathlib import Path | 19 | 20 | import sys | @@ -184,37 +185,44 @@ def blacken(session: nox.sessions.Session) -> None: | 184 | 185 | def _session_tests( | 185 | 186 | session: nox.sessions.Session, post_install: Callable = None | 186 | 187 | ) -> None: | 187 | | - if TEST_CONFIG["pip_version_override"]: | 188 | | - pip_version = TEST_CONFIG["pip_version_override"] | 189 | | - session.install(f"pip=={pip_version}") | 190 | | - """Runs py.test for a particular project.""" | 191 | | - if os.path.exists("requirements.txt"): | 192 | | - if os.path.exists("constraints.txt"): | 193 | | - session.install("-r", "requirements.txt", "-c", "constraints.txt") | 194 | | - else: | 195 | | - session.install("-r", "requirements.txt") | 196 | | - | 197 | | - if os.path.exists("requirements-test.txt"): | 198 | | - if os.path.exists("constraints-test.txt"): | 199 | | - session.install("-r", "requirements-test.txt", "-c", "constraints-test.txt") | 200 | | - else: | 201 | | - session.install("-r", "requirements-test.txt") | 202 | | - | 203 | | - if INSTALL_LIBRARY_FROM_SOURCE: | 204 | | - session.install("-e", _get_repo_root()) | 205 | | - | 206 | | - if post_install: | 207 | | - post_install(session) | 208 | | - | 209 | | - session.run( | 210 | | - "pytest", | 211 | | - *(PYTEST_COMMON_ARGS + session.posargs), | 212 | | - # Pytest will return 5 when no tests are collected. This can happen | 213 | | - # on travis where slow and flaky tests are excluded. | 214 | | - # See http://doc.pytest.org/en/latest/_modules/_pytest/main.html | 215 | | - success_codes=[0, 5], | 216 | | - env=get_pytest_env_vars(), | 217 | | - ) | | 188 | + # check for presence of tests | | 189 | + test_list = glob.glob("*_test.py") + glob.glob("test_*.py") | | 190 | + if len(test_list) == 0: | | 191 | + print("No tests found, skipping directory.") | | 192 | + else: | | 193 | + if TEST_CONFIG["pip_version_override"]: | | 194 | + pip_version = TEST_CONFIG["pip_version_override"] | | 195 | + session.install(f"pip=={pip_version}") | | 196 | + """Runs py.test for a particular project.""" | | 197 | + if os.path.exists("requirements.txt"): | | 198 | + if os.path.exists("constraints.txt"): | | 199 | + session.install("-r", "requirements.txt", "-c", "constraints.txt") | | 200 | + else: | | 201 | + session.install("-r", "requirements.txt") | | 202 | + | | 203 | + if os.path.exists("requirements-test.txt"): | | 204 | + if os.path.exists("constraints-test.txt"): | | 205 | + session.install( | | 206 | + "-r", "requirements-test.txt", "-c", "constraints-test.txt" | | 207 | + ) | | 208 | + else: | | 209 | + session.install("-r", "requirements-test.txt") | | 210 | + | | 211 | + if INSTALL_LIBRARY_FROM_SOURCE: | | 212 | + session.install("-e", _get_repo_root()) | | 213 | + | | 214 | + if post_install: | | 215 | + post_install(session) | | 216 | + | | 217 | + session.run( | | 218 | + "pytest", | | 219 | + *(PYTEST_COMMON_ARGS + session.posargs), | | 220 | + # Pytest will return 5 when no tests are collected. This can happen | | 221 | + # on travis where slow and flaky tests are excluded. | | 222 | + # See http://doc.pytest.org/en/latest/_modules/_pytest/main.html | | 223 | + success_codes=[0, 5], | | 224 | + env=get_pytest_env_vars(), | | 225 | + ) | 218 | 226 |
| 219 | 227 |
| 220 | 228 | @nox.session(python=ALL_VERSIONS) | |
|