Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: require 100% unit test coverage (via synth) #359

Merged
merged 7 commits into from
Apr 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/header-checker-lint.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{"allowedCopyrightHolders": ["Google LLC"],
"allowedLicenses": ["Apache-2.0", "MIT", "BSD-3"],
"ignoreFiles": ["**/requirements.txt", "**/requirements-test.txt"],
"ignoreFiles": ["**/requirements.txt", "**/requirements-test.txt", "**/__init__.py", "samples/**/constraints.txt", "samples/**/constraints-test.txt"],
"sourceFileExtensions": [
"ts",
"js",
Expand Down
14 changes: 14 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright 2021 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
Expand Down
13 changes: 13 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
# -*- coding: utf-8 -*-
# Copyright 2021 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# google-cloud-pubsub documentation build configuration file
#
Expand Down
28 changes: 18 additions & 10 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

from __future__ import absolute_import
import os
import pathlib
import shutil

import nox
Expand All @@ -30,6 +31,8 @@
SYSTEM_TEST_PYTHON_VERSIONS = ["3.8"]
UNIT_TEST_PYTHON_VERSIONS = ["3.6", "3.7", "3.8", "3.9"]

CURRENT_DIRECTORY = pathlib.Path(__file__).parent.absolute()

# 'docfx' is excluded since it only needs to run in 'docs-presubmit'
nox.options.sessions = [
"unit",
Expand Down Expand Up @@ -84,13 +87,15 @@ def lint_setup_py(session):

def default(session):
# Install all test dependencies, then install this package in-place.
session.install("asyncmock", "pytest-asyncio")

session.install(
"mock", "pytest", "pytest-cov",
constraints_path = str(
CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt"
)
session.install("asyncmock", "pytest-asyncio", "-c", constraints_path)

session.install("-e", ".")
session.install("mock", "pytest", "pytest-cov", "-c", constraints_path)

session.install("-e", ".", "-c", constraints_path)

# Run py.test against the unit tests.
session.run(
Expand All @@ -117,6 +122,9 @@ def unit(session):
@nox.session(python=SYSTEM_TEST_PYTHON_VERSIONS)
def system(session):
"""Run the system test suite."""
constraints_path = str(
CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt"
)
system_test_path = os.path.join("tests", "system.py")
system_test_folder_path = os.path.join("tests", "system")

Expand All @@ -141,8 +149,10 @@ def system(session):

# Install all test dependencies, then install this package into the
# virtualenv's dist-packages.
session.install("mock", "pytest", "google-cloud-testutils", "psutil")
session.install("-e", ".")
session.install(
"mock", "pytest", "google-cloud-testutils", "psutil", "-c", constraints_path
)
session.install("-e", ".", "-c", constraints_path)

# Run py.test against the system tests.
if system_test_exists:
Expand Down Expand Up @@ -171,7 +181,7 @@ def cover(session):
test runs (not system test runs), and then erases coverage data.
"""
session.install("coverage", "pytest-cov")
session.run("coverage", "report", "--show-missing", "--fail-under=99")
session.run("coverage", "report", "--show-missing", "--fail-under=100")

session.run("coverage", "erase")

Expand Down Expand Up @@ -203,9 +213,7 @@ def docfx(session):
"""Build the docfx yaml files for this library."""

session.install("-e", ".")
# sphinx-docfx-yaml supports up to sphinx version 1.5.5.
# https://github.com/docascode/sphinx-docfx-yaml/issues/97
session.install("sphinx==1.5.5", "alabaster", "recommonmark", "sphinx-docfx-yaml")
session.install("sphinx", "alabaster", "recommonmark", "gcp-sphinx-docfx-yaml")

shutil.rmtree(os.path.join("docs", "_build"), ignore_errors=True)
session.run(
Expand Down
5 changes: 4 additions & 1 deletion renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@
"extends": [
"config:base", ":preserveSemverRanges"
],
"ignorePaths": [".pre-commit-config.yaml"]
"ignorePaths": [".pre-commit-config.yaml"],
"pip_requirements": {
"fileMatch": ["requirements-test.txt", "samples/[\\S/]*constraints.txt", "samples/[\\S/]*constraints-test.txt"]
}
}
10 changes: 8 additions & 2 deletions samples/snippets/noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,16 @@ def blacken(session: nox.sessions.Session) -> None:
def _session_tests(session: nox.sessions.Session, post_install: Callable = None) -> None:
"""Runs py.test for a particular project."""
if os.path.exists("requirements.txt"):
session.install("-r", "requirements.txt")
if os.path.exists("constraints.txt"):
session.install("-r", "requirements.txt", "-c", "constraints.txt")
else:
session.install("-r", "requirements.txt")

if os.path.exists("requirements-test.txt"):
session.install("-r", "requirements-test.txt")
if os.path.exists("constraints-test.txt"):
session.install("-r", "requirements-test.txt", "-c", "constraints-test.txt")
else:
session.install("-r", "requirements-test.txt")

if INSTALL_LIBRARY_FROM_SOURCE:
session.install("-e", _get_repo_root())
Expand Down
126 changes: 121 additions & 5 deletions synth.metadata
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
{
"git": {
"name": ".",
"remote": "git@github.com:plamut/python-pubsub.git",
"sha": "0a662a6daad0517fb0e01732c9dd7f9d1852924c"
"remote": "https://github.com/googleapis/python-pubsub.git",
"sha": "9f451a1fe0ac5cb2fb13d72b0436e0b521a4fecb"
}
},
{
Expand All @@ -19,21 +19,21 @@
"git": {
"name": "synthtool",
"remote": "https://github.com/googleapis/synthtool.git",
"sha": "c84c8f156e09702e1c8946bfb9746e6f5892cf27"
"sha": "0a071b3460344886297a304253bf924aa68ddb7e"
}
},
{
"git": {
"name": "synthtool",
"remote": "https://github.com/googleapis/synthtool.git",
"sha": "c84c8f156e09702e1c8946bfb9746e6f5892cf27"
"sha": "0a071b3460344886297a304253bf924aa68ddb7e"
}
},
{
"git": {
"name": "synthtool",
"remote": "https://github.com/googleapis/synthtool.git",
"sha": "c84c8f156e09702e1c8946bfb9746e6f5892cf27"
"sha": "0a071b3460344886297a304253bf924aa68ddb7e"
}
}
],
Expand All @@ -47,5 +47,121 @@
"generator": "bazel"
}
}
],
"generatedFiles": [
".coveragerc",
".flake8",
".github/CONTRIBUTING.md",
".github/ISSUE_TEMPLATE/bug_report.md",
".github/ISSUE_TEMPLATE/feature_request.md",
".github/ISSUE_TEMPLATE/support_request.md",
".github/PULL_REQUEST_TEMPLATE.md",
".github/header-checker-lint.yml",
".github/release-please.yml",
".github/snippet-bot.yml",
".gitignore",
".kokoro/build.sh",
".kokoro/continuous/common.cfg",
".kokoro/continuous/continuous.cfg",
".kokoro/docker/docs/Dockerfile",
".kokoro/docker/docs/fetch_gpg_keys.sh",
".kokoro/docs/common.cfg",
".kokoro/docs/docs-presubmit.cfg",
".kokoro/docs/docs.cfg",
".kokoro/populate-secrets.sh",
".kokoro/presubmit/common.cfg",
".kokoro/presubmit/presubmit.cfg",
".kokoro/publish-docs.sh",
".kokoro/release.sh",
".kokoro/release/common.cfg",
".kokoro/release/release.cfg",
".kokoro/samples/lint/common.cfg",
".kokoro/samples/lint/continuous.cfg",
".kokoro/samples/lint/periodic.cfg",
".kokoro/samples/lint/presubmit.cfg",
".kokoro/samples/python3.6/common.cfg",
".kokoro/samples/python3.6/continuous.cfg",
".kokoro/samples/python3.6/periodic-head.cfg",
".kokoro/samples/python3.6/periodic.cfg",
".kokoro/samples/python3.6/presubmit.cfg",
".kokoro/samples/python3.7/common.cfg",
".kokoro/samples/python3.7/continuous.cfg",
".kokoro/samples/python3.7/periodic-head.cfg",
".kokoro/samples/python3.7/periodic.cfg",
".kokoro/samples/python3.7/presubmit.cfg",
".kokoro/samples/python3.8/common.cfg",
".kokoro/samples/python3.8/continuous.cfg",
".kokoro/samples/python3.8/periodic-head.cfg",
".kokoro/samples/python3.8/periodic.cfg",
".kokoro/samples/python3.8/presubmit.cfg",
".kokoro/test-samples-against-head.sh",
".kokoro/test-samples-impl.sh",
".kokoro/test-samples.sh",
".kokoro/trampoline.sh",
".kokoro/trampoline_v2.sh",
".pre-commit-config.yaml",
".trampolinerc",
"CODE_OF_CONDUCT.md",
"CONTRIBUTING.rst",
"LICENSE",
"MANIFEST.in",
"docs/_static/custom.css",
"docs/_templates/layout.html",
"docs/conf.py",
"docs/multiprocessing.rst",
"google/cloud/pubsub_v1/proto/pubsub.proto",
"google/cloud/pubsub_v1/proto/schema.proto",
"google/pubsub/__init__.py",
"google/pubsub/py.typed",
"google/pubsub_v1/__init__.py",
"google/pubsub_v1/py.typed",
"google/pubsub_v1/services/__init__.py",
"google/pubsub_v1/services/publisher/__init__.py",
"google/pubsub_v1/services/publisher/async_client.py",
"google/pubsub_v1/services/publisher/client.py",
"google/pubsub_v1/services/publisher/pagers.py",
"google/pubsub_v1/services/publisher/transports/__init__.py",
"google/pubsub_v1/services/publisher/transports/base.py",
"google/pubsub_v1/services/publisher/transports/grpc.py",
"google/pubsub_v1/services/publisher/transports/grpc_asyncio.py",
"google/pubsub_v1/services/schema_service/__init__.py",
"google/pubsub_v1/services/schema_service/async_client.py",
"google/pubsub_v1/services/schema_service/client.py",
"google/pubsub_v1/services/schema_service/pagers.py",
"google/pubsub_v1/services/schema_service/transports/__init__.py",
"google/pubsub_v1/services/schema_service/transports/base.py",
"google/pubsub_v1/services/schema_service/transports/grpc.py",
"google/pubsub_v1/services/schema_service/transports/grpc_asyncio.py",
"google/pubsub_v1/services/subscriber/__init__.py",
"google/pubsub_v1/services/subscriber/async_client.py",
"google/pubsub_v1/services/subscriber/client.py",
"google/pubsub_v1/services/subscriber/pagers.py",
"google/pubsub_v1/services/subscriber/transports/__init__.py",
"google/pubsub_v1/services/subscriber/transports/base.py",
"google/pubsub_v1/services/subscriber/transports/grpc.py",
"google/pubsub_v1/services/subscriber/transports/grpc_asyncio.py",
"google/pubsub_v1/types/__init__.py",
"google/pubsub_v1/types/pubsub.py",
"google/pubsub_v1/types/schema.py",
"mypy.ini",
"noxfile.py",
"renovate.json",
"samples/AUTHORING_GUIDE.md",
"samples/CONTRIBUTING.md",
"samples/snippets/noxfile.py",
"scripts/decrypt-secrets.sh",
"scripts/fixup_pubsub_v1_keywords.py",
"scripts/readme-gen/readme_gen.py",
"scripts/readme-gen/templates/README.tmpl.rst",
"scripts/readme-gen/templates/auth.tmpl.rst",
"scripts/readme-gen/templates/auth_api_key.tmpl.rst",
"scripts/readme-gen/templates/install_deps.tmpl.rst",
"scripts/readme-gen/templates/install_portaudio.tmpl.rst",
"setup.cfg",
"testing/.gitignore",
"tests/unit/gapic/pubsub_v1/__init__.py",
"tests/unit/gapic/pubsub_v1/test_publisher.py",
"tests/unit/gapic/pubsub_v1/test_schema_service.py",
"tests/unit/gapic/pubsub_v1/test_subscriber.py"
]
}