Skip to content
This repository has been archived by the owner on Sep 5, 2023. It is now read-only.

Commit

Permalink
chore(samples): move samples and use standard templates for testing (#41
Browse files Browse the repository at this point in the history
)
  • Loading branch information
busunkim96 committed Jul 14, 2020
1 parent 1b3058f commit 1c7c210
Show file tree
Hide file tree
Showing 22 changed files with 2,091 additions and 115 deletions.
8 changes: 8 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Code owners file.
# This file controls who is tagged for review for any given pull request.
#
# For syntax help see:
# https://help.github.com/en/github/creating-cloning-and-archiving-repositories/about-code-owners#codeowners-syntax


/samples/ @tdh911 @googleapis/python-samples-owners
117 changes: 38 additions & 79 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,33 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# Generated by synthtool. DO NOT EDIT!

from __future__ import absolute_import
import os
import shutil
import shutil

import nox


BLACK_VERSION = "black==19.10b0"
BLACK_PATHS = ["docs", "google", "tests", "noxfile.py", "setup.py"]

DEFAULT_PYTHON_VERSION = "3.8"
SYSTEM_TEST_PYTHON_VERSIONS = ["2.7", "3.8"]
UNIT_TEST_PYTHON_VERSIONS = ["2.7", "3.5", "3.6", "3.7", "3.8"]


@nox.session(python="3.7")
@nox.session(python=DEFAULT_PYTHON_VERSION)
def lint(session):
"""Run linters.
Returns a failure if the linters find linting errors or sufficiently
serious code quality issues.
"""
session.install("flake8", "black")
session.install("flake8", BLACK_VERSION)
session.run(
"black",
"--check",
"google",
"tests",
"docs",
"black", "--check", *BLACK_PATHS,
)
session.run("flake8", "google", "tests")

Expand All @@ -45,21 +50,18 @@ def blacken(session):
"""Run black.
Format code to uniform standard.
This currently uses Python 3.6 due to the automated Kokoro run of synthtool.
That run uses an image that doesn't have 3.6 installed. Before updating this
check the state of the `gcp_ubuntu_config` we use for that Kokoro run.
"""
session.install("black")
session.install(BLACK_VERSION)
session.run(
"black",
"google",
"tests",
"docs",
"black", *BLACK_PATHS,
)


@nox.session(python="3.7")
@nox.session(python=DEFAULT_PYTHON_VERSION)
def lint_setup_py(session):
"""Verify that setup.py is valid (including RST check)."""
session.install("docutils", "pygments")
Expand All @@ -75,6 +77,7 @@ def default(session):
session.run(
"py.test",
"--quiet",
"--cov=google.cloud.securitycenter",
"--cov=google.cloud",
"--cov=tests.unit",
"--cov-append",
Expand All @@ -86,13 +89,13 @@ def default(session):
)


@nox.session(python=["2.7", "3.5", "3.6", "3.7", "3.8"])
@nox.session(python=UNIT_TEST_PYTHON_VERSIONS)
def unit(session):
"""Run the unit test suite."""
default(session)


@nox.session(python=["2.7", "3.7"])
@nox.session(python=SYSTEM_TEST_PYTHON_VERSIONS)
def system(session):
"""Run the system test suite."""
system_test_path = os.path.join("tests", "system.py")
Expand All @@ -112,7 +115,9 @@ def system(session):

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

# Run py.test against the system tests.
Expand All @@ -122,7 +127,7 @@ def system(session):
session.run("py.test", "--quiet", system_test_folder_path, *session.posargs)


@nox.session(python="3.7")
@nox.session(python=DEFAULT_PYTHON_VERSION)
def cover(session):
"""Run the final coverage report.
Expand All @@ -135,69 +140,23 @@ def cover(session):
session.run("coverage", "erase")


@nox.session(python=["2.7", "3.5", "3.6", "3.7"])
def snippets(session):
"""Run the documentation example snippets."""
# Sanity check: Only run snippets system tests if the environment variable
# is set.
if not os.environ.get('GOOGLE_APPLICATION_CREDENTIALS', ''):
session.skip('Credentials must be set via environment variable.')
if not os.environ.get('GCLOUD_ORGANIZATION', ''):
if 'KOKORO_GFILE_DIR' in os.environ:
session.env['GCLOUD_ORGANIZATION'] = '1081635000895'
else:
session.skip('Credentials must be set via environment variable.')
if not os.environ.get('GCLOUD_PROJECT', ''):
if 'KOKORO_GFILE_DIR' in os.environ:
session.env['GCLOUD_PROJECT'] = 'project-a-id'
else:
session.skip('Credentials must be set via environment variable.')
if not os.environ.get('GCLOUD_PUBSUB_TOPIC', ''):
if 'KOKORO_GFILE_DIR' in os.environ:
session.env['GCLOUD_PUBSUB_TOPIC'] = 'projects/project-a-id/topics/notifications-sample-topic'
else:
session.skip('Credentials must be set via environment variable.')
if not os.environ.get('GCLOUD_PUBSUB_SUBSCRIPTION', ''):
if 'KOKORO_GFILE_DIR' in os.environ:
session.env['GCLOUD_PUBSUB_SUBSCRIPTION'] = 'notification_sample_subscription'
else:
session.skip('Credentials must be set via environment variable.')


# Install all test dependencies, then install local packages in place.
session.install('mock', 'pytest')
session.install("-r", "docs/requirements.txt")
session.install('-e', '.')
session.run(
'py.test',
'--quiet',
os.path.join('docs', 'snippets_list_assets.py'),
os.path.join('docs', 'snippets_security_marks.py'),
os.path.join('docs', 'snippets_orgs.py'),
os.path.join('docs', 'snippets_findings.py'),
os.path.join('docs', 'snippets_security_marks.py'),
os.path.join('docs', 'snippets_notification_test.py'),


*session.posargs
)


@nox.session(python="3.7")
@nox.session(python=DEFAULT_PYTHON_VERSION)
def docs(session):
"""Build the docs for this library."""

session.install('-e', '.')
session.install('sphinx<3.0.0', 'alabaster', 'recommonmark')
session.install("-e", ".")
session.install("sphinx<3.0.0", "alabaster", "recommonmark")

shutil.rmtree(os.path.join('docs', '_build'), ignore_errors=True)
shutil.rmtree(os.path.join("docs", "_build"), ignore_errors=True)
session.run(
'sphinx-build',
'-W', # warnings as errors
'-T', # show full traceback on exception
'-N', # no colors
'-b', 'html',
'-d', os.path.join('docs', '_build', 'doctrees', ''),
os.path.join('docs', ''),
os.path.join('docs', '_build', 'html', ''),
"sphinx-build",
"-W", # warnings as errors
"-T", # show full traceback on exception
"-N", # no colors
"-b",
"html",
"-d",
os.path.join("docs", "_build", "doctrees", ""),
os.path.join("docs", ""),
os.path.join("docs", "_build", "html", ""),
)
1 change: 1 addition & 0 deletions samples/AUTHORING_GUIDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
See https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/AUTHORING_GUIDE.md
1 change: 1 addition & 0 deletions samples/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
See https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/CONTRIBUTING.md

0 comments on commit 1c7c210

Please sign in to comment.