diff --git a/packages/google-crc32c/.coveragerc b/packages/google-crc32c/.coveragerc index ab4a10fdea4b..75185c2e7aa1 100644 --- a/packages/google-crc32c/.coveragerc +++ b/packages/google-crc32c/.coveragerc @@ -17,12 +17,14 @@ # Generated by synthtool. DO NOT EDIT! [run] branch = True +source = + src/google_crc32c omit = google/__init__.py google/cloud/__init__.py [report] -fail_under = 0 +fail_under = 100 show_missing = True exclude_lines = # Re-enable the standard pragma diff --git a/packages/google-crc32c/noxfile.py b/packages/google-crc32c/noxfile.py index 3c238ff62f8f..0f392385a3c1 100644 --- a/packages/google-crc32c/noxfile.py +++ b/packages/google-crc32c/noxfile.py @@ -40,6 +40,7 @@ "blacken", "format", "lint_setup_py", + "cover", "mypy", "prerelease_deps", "core_deps_from_source", @@ -66,11 +67,13 @@ def build_libcrc32c(session): @nox.session(python=UNIT_TEST_PYTHON_VERSIONS) def check(session): - session.install("pytest") + session.install("pytest", "pytest-cov") session.install("--no-index", f"--find-links={HERE}/wheels", "google-crc32c") # Run py.test against the unit tests. - session.run("py.test", "tests") + session.run( + "pytest", "--cov=google_crc32c", "--cov=tests", "tests", *session.posargs + ) session.run("python", f"{HERE}/scripts/check_crc32c_extension.py", *session.posargs) @@ -174,9 +177,9 @@ def lint_setup_py(session): @nox.session(python=DEFAULT_PYTHON_VERSION) def prerelease_deps(session): """Run all tests with prerelease versions of dependencies installed.""" - # TODO(https://github.com/googleapis/google-cloud-python/issues/16014): - # Add prerelease deps tests - session.skip("prerelease deps tests are not yet supported") + session.skip( + "prerelease_deps session is not applicable as google-crc32c has no runtime dependencies" + ) @nox.session(python=DEFAULT_PYTHON_VERSION) @@ -184,15 +187,32 @@ def core_deps_from_source(session): """Run all tests with core dependencies installed from source rather than pulling the dependencies from PyPI. """ - # TODO(https://github.com/googleapis/google-cloud-python/issues/16014): - # Add core deps from source tests - session.skip("Core deps from source tests are not yet supported") + session.skip( + "core_deps_from_source session is not applicable as google-crc32c has no core dependencies" + ) -@nox.session(python=ALL_PYTHON) +@nox.session(python=UNIT_TEST_PYTHON_VERSIONS) def unit(session): """Run all unit tests.""" - session.skip("Unit tests are not supported") + session.env["CRC32C_PURE_PYTHON"] = "1" + session.install("pytest", "pytest-cov") + session.install("-e", ".") + session.run( + "pytest", "--cov=google_crc32c", "--cov=tests", "tests", *session.posargs + ) + + +@nox.session(python=DEFAULT_PYTHON_VERSION) +def cover(session): + """Run the final coverage report. + + This outputs the coverage report aggregating coverage from the unit + test runs (not system test runs), and then erases coverage data. + """ + session.install("coverage", "pytest-cov") + session.run("coverage", "report", "--show-missing", "--fail-under=100") + session.run("coverage", "erase") @nox.session(python="3.10") diff --git a/packages/google-crc32c/src/google_crc32c/cext.py b/packages/google-crc32c/src/google_crc32c/cext.py index 53e58f6321f1..ec22abec5c1c 100644 --- a/packages/google-crc32c/src/google_crc32c/cext.py +++ b/packages/google-crc32c/src/google_crc32c/cext.py @@ -17,8 +17,8 @@ import google_crc32c.__config__ # noqa: F401 from google_crc32c._checksum import CommonChecksum from google_crc32c._crc32c import ( # type: ignore - extend, # type: ignore - value, # type: ignore + extend, + value, ) diff --git a/packages/google-crc32c/tests/test___init__.py b/packages/google-crc32c/tests/test___init__.py index 68bed918ffa4..aca1254fde43 100644 --- a/packages/google-crc32c/tests/test___init__.py +++ b/packages/google-crc32c/tests/test___init__.py @@ -206,10 +206,13 @@ def _crc32c(request): return python elif request.param == "cext": - from google_crc32c import cext + try: + from google_crc32c import cext - return cext - else: + return cext # pragma: NO COVER + except ImportError: # pragma: NO COVER + pytest.skip("C extension not compiled") # pragma: NO COVER + else: # pragma: NO COVER raise ValueError("invalid internal test config")