From 508d53d2cd020d6f2c66c31befdca0f43d65659d Mon Sep 17 00:00:00 2001 From: ohmayr Date: Tue, 27 Jan 2026 22:47:47 +0000 Subject: [PATCH 1/2] chore: replace isort and black with ruff --- docs/conf.py | 4 +- gapic/cli/generate.py | 2 +- gapic/generator/generator.py | 4 +- gapic/samplegen_utils/snippet_index.py | 4 +- gapic/samplegen_utils/yaml.py | 4 +- gapic/schema/api.py | 9 +- gapic/schema/metadata.py | 2 +- gapic/schema/naming.py | 2 +- gapic/schema/wrappers.py | 2 +- gapic/templates/noxfile.py.j2 | 49 ++++++----- noxfile.py | 83 +++++++++++++++---- tests/integration/goldens/asset/noxfile.py | 48 ++++++----- .../goldens/credentials/noxfile.py | 48 ++++++----- tests/integration/goldens/eventarc/noxfile.py | 48 ++++++----- tests/integration/goldens/logging/noxfile.py | 48 ++++++----- .../goldens/logging_internal/noxfile.py | 48 ++++++----- tests/integration/goldens/redis/noxfile.py | 48 ++++++----- .../goldens/redis_selective/noxfile.py | 48 ++++++----- tests/system/test_lro.py | 1 - tests/unit/common_types.py | 2 +- tests/unit/generator/test_formatter.py | 65 ++++++--------- tests/unit/generator/test_generator.py | 4 +- tests/unit/generator/test_options.py | 2 +- tests/unit/schema/test_api.py | 36 ++++---- tests/unit/schema/wrappers/test_field.py | 12 +-- tests/unit/schema/wrappers/test_method.py | 3 +- 26 files changed, 345 insertions(+), 281 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index cb605ff6a1..b7fce71c3d 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -32,9 +32,7 @@ # Replace |version| in the docs with the actual version string. rst_epilog = """ .. |version| replace:: {version} -""".format( - version=version -) +""".format(version=version) # -- General configuration --------------------------------------------------- diff --git a/gapic/cli/generate.py b/gapic/cli/generate.py index e8eee1f034..e3b0a902ed 100644 --- a/gapic/cli/generate.py +++ b/gapic/cli/generate.py @@ -38,7 +38,7 @@ "--output", type=click.File("wb"), default=sys.stdout.buffer, - help="Where to output the `CodeGeneratorResponse`. " "Defaults to stdout.", + help="Where to output the `CodeGeneratorResponse`. Defaults to stdout.", ) def generate(request: typing.BinaryIO, output: typing.BinaryIO) -> None: """Generate a full API client description.""" diff --git a/gapic/generator/generator.py b/gapic/generator/generator.py index f42e40655e..e9e006e748 100644 --- a/gapic/generator/generator.py +++ b/gapic/generator/generator.py @@ -131,9 +131,7 @@ def get_response(self, api_schema: api.API, opts: Options) -> CodeGeneratorRespo ) # Return the CodeGeneratorResponse output. - res = CodeGeneratorResponse( - file=[i for i in output_files.values()] - ) # type: ignore + res = CodeGeneratorResponse(file=[i for i in output_files.values()]) # type: ignore res.supported_features |= CodeGeneratorResponse.Feature.FEATURE_PROTO3_OPTIONAL # type: ignore return res diff --git a/gapic/samplegen_utils/snippet_index.py b/gapic/samplegen_utils/snippet_index.py index 945b43e61f..4cb2fc8a69 100644 --- a/gapic/samplegen_utils/snippet_index.py +++ b/gapic/samplegen_utils/snippet_index.py @@ -117,7 +117,9 @@ def __init__(self, api_schema: api.API): self.metadata_index.client_library.name = ( api_schema.naming.warehouse_package_name ) - self.metadata_index.client_library.language = snippet_metadata_pb2.Language.PYTHON # type: ignore + self.metadata_index.client_library.language = ( + snippet_metadata_pb2.Language.PYTHON + ) # type: ignore self.metadata_index.client_library.version = api_schema.gapic_version diff --git a/gapic/samplegen_utils/yaml.py b/gapic/samplegen_utils/yaml.py index bb558cb269..0d004254be 100644 --- a/gapic/samplegen_utils/yaml.py +++ b/gapic/samplegen_utils/yaml.py @@ -116,7 +116,9 @@ def get(self, key, default=None): return next( iter( [ - e.val for e in self.elements if e.key == key # type: ignore + e.val + for e in self.elements + if e.key == key # type: ignore ] # type: ignore ), default, diff --git a/gapic/schema/api.py b/gapic/schema/api.py index b05f6b6dec..4ee478a643 100644 --- a/gapic/schema/api.py +++ b/gapic/schema/api.py @@ -941,11 +941,7 @@ def enforce_valid_library_settings( selective_gapic_errors = {} # TODO(https://github.com/googleapis/gapic-generator-python/issues/2446): # Workaround issue in Python 3.14 related to code coverage by adding `# pragma: no branch` - for ( - method_name - ) in ( - library_settings.python_settings.common.selective_gapic_generation.methods - ): # pragma: no branch + for method_name in library_settings.python_settings.common.selective_gapic_generation.methods: # pragma: no branch if method_name not in self.all_methods: selective_gapic_errors[method_name] = "Method does not exist." elif not method_name.startswith(library_settings.version): @@ -1180,8 +1176,7 @@ def __init__( object.__setattr__(field, "enum", maybe_enum_type) else: raise TypeError( - f"Unknown type referenced in " - f"{self.file_descriptor.name}: '{key}'" + f"Unknown type referenced in {self.file_descriptor.name}: '{key}'" ) # Only generate the service if this is a target file to be generated. diff --git a/gapic/schema/metadata.py b/gapic/schema/metadata.py index 7df8d0291f..9fc6e43c30 100644 --- a/gapic/schema/metadata.py +++ b/gapic/schema/metadata.py @@ -356,7 +356,7 @@ def resolve(self, selector: str) -> str: str: An absolute selector. """ if "." not in selector: - return f'{".".join(self.package)}.{selector}' + return f"{'.'.join(self.package)}.{selector}" return selector def with_context(self, *, collisions: Set[str]) -> "Address": diff --git a/gapic/schema/naming.py b/gapic/schema/naming.py index ebf650944f..96b029664f 100644 --- a/gapic/schema/naming.py +++ b/gapic/schema/naming.py @@ -86,7 +86,7 @@ def build( "The protos provided do not share a common root package. " "Ensure that all explicitly-specified protos are for a " "single API. " - f'The packages we got are: {", ".join(proto_packages)}' + f"The packages we got are: {', '.join(proto_packages)}" ) # Define the valid regex to split the package. diff --git a/gapic/schema/wrappers.py b/gapic/schema/wrappers.py index 17a7832756..f228256742 100644 --- a/gapic/schema/wrappers.py +++ b/gapic/schema/wrappers.py @@ -797,7 +797,7 @@ def get_field( # Quick check: If this cursor has no message, there is a problem. if not cursor.message: raise KeyError( - f'Field {".".join(field_path)} could not be resolved from ' + f"Field {'.'.join(field_path)} could not be resolved from " f"{cursor.name}.", ) diff --git a/gapic/templates/noxfile.py.j2 b/gapic/templates/noxfile.py.j2 index 274ca368e0..3c07c9b6a8 100644 --- a/gapic/templates/noxfile.py.j2 +++ b/gapic/templates/noxfile.py.j2 @@ -12,8 +12,7 @@ import warnings import nox -BLACK_VERSION = "black[jupyter]==23.7.0" -ISORT_VERSION = "isort==5.11.0" +RUFF_VERSION = "ruff==0.14.14" {% if api.naming.module_namespace %} LINT_PATHS = ["docs", "{{ api.naming.module_namespace[0] }}", "tests", "noxfile.py", "setup.py"] @@ -147,12 +146,11 @@ def lint(session): Returns a failure if the linters find linting errors or sufficiently serious code quality issues. """ - session.install("flake8", BLACK_VERSION) - session.run( - "black", - "--check", - *LINT_PATHS, - ) + session.install("flake8", RUFF_VERSION) + + # 2. Check formatting + session.run("ruff", "format", "--check", "--line-length=88", *LINT_PATHS) + {% if api.naming.module_namespace %} session.run("flake8", "{{ api.naming.module_namespace[0] }}", "tests") @@ -163,30 +161,37 @@ def lint(session): @nox.session(python=DEFAULT_PYTHON_VERSION) def blacken(session): - """Run black. Format code to uniform standard.""" - session.install(BLACK_VERSION) - session.run( - "black", - *LINT_PATHS, - ) + """(Deprecated) Legacy session. Please use 'nox -s format'.""" + session.log("WARNING: The 'blacken' session is deprecated and will be removed in the next release. Please use 'nox -s format' in the future.") + + # Just run the ruff formatter (keeping legacy behavior of only formatting, not sorting imports) + session.install(RUFF_VERSION) + session.run("ruff", "format", "--line-length=88", *LINT_PATHS) @nox.session(python=DEFAULT_PYTHON_VERSION) def format(session): """ - Run isort to sort imports. Then run black - to format code to uniform standard. + Run ruff to sort imports and format code. """ - session.install(BLACK_VERSION, ISORT_VERSION) - # Use the --fss option to sort imports using strict alphabetical order. - # See https://pycqa.github.io/isort/docs/configuration/options.html#force-sort-within-sections + # 1. Install ruff (skipped automatically if you run with --no-venv) + session.install(RUFF_VERSION) + + # 2. Run Ruff to fix imports + # check --select I: Enables strict import sorting + # --fix: Applies the changes automatically session.run( - "isort", - "--fss", + "ruff", "check", + "--select", "I", + "--fix", + "--line-length=88", # Standard Black line length *LINT_PATHS, ) + + # 3. Run Ruff to format code session.run( - "black", + "ruff", "format", + "--line-length=88", # Standard Black line length *LINT_PATHS, ) diff --git a/noxfile.py b/noxfile.py index e99bfad597..214a9e6df0 100644 --- a/noxfile.py +++ b/noxfile.py @@ -31,10 +31,12 @@ showcase_version = os.environ.get("SHOWCASE_VERSION", "0.35.0") ADS_TEMPLATES = path.join(path.dirname(__file__), "gapic", "ads-templates") -BLACK_VERSION = "black==25.1.0" -BLACK_PATHS = ["docs", "gapic", "tests", "test_utils", "noxfile.py", "setup.py"] -# exclude golden files and generated protobuf code -BLACK_EXCLUDES = "|".join([".*golden.*", ".*pb2.py"]) +RUFF_VERSION = "ruff==0.14.14" +LINT_PATHS = ["docs", "gapic", "tests", "test_utils", "noxfile.py", "setup.py"] +# Ruff uses globs for excludes (different from Black's regex) +# .*golden.* -> *golden* +# .*pb2.py -> *pb2.py +RUFF_EXCLUDES = "*golden*,*pb2.py,*pb2.pyi" ALL_PYTHON = ( "3.7", @@ -80,6 +82,7 @@ def unit(session): path.join("tests", "unit"), ] ), + external=True, ) @@ -294,7 +297,7 @@ def showcase_library( } ] update_service_yaml = _add_python_settings(tmp_dir, python_settings) - session.run("python", "-c" f"{update_service_yaml}") + session.run("python", f"-c{update_service_yaml}") # END TODO section to remove. if retry_config: session.run( @@ -755,14 +758,19 @@ def lint(session): Returns a failure if the linters find linting errors or sufficiently serious code quality issues. """ - session.install("flake8", BLACK_VERSION) + session.install("flake8", RUFF_VERSION) + + # 2. Check formatting session.run( - "black", + "ruff", + "format", "--check", - *BLACK_PATHS, - "--extend-exclude", - BLACK_EXCLUDES, + *LINT_PATHS, + "--exclude", + RUFF_EXCLUDES, ) + + # 3. Run Flake8 session.run( "flake8", "gapic", @@ -772,11 +780,54 @@ def lint(session): @nox.session(python="3.10") def blacken(session): - """Run black. Format code to uniform standard.""" - session.install(BLACK_VERSION) + """Run ruff format. + + DEPRECATED: This session now uses Ruff instead of Black. + It formats code style only (indentation, quotes, etc). + """ + session.log( + "WARNING: The 'blacken' session is deprecated and will be removed in the next release. Please use 'nox -s format' in the future." + ) + + session.install(RUFF_VERSION) + + # 1. Format Code (Replaces black) + # We do NOT run 'ruff check --select I' here, preserving strict parity. + session.run( + "ruff", + "format", + "--line-length=88", # Standard Black line length + *LINT_PATHS, + "--exclude", + RUFF_EXCLUDES, + ) + + +@nox.session(python=NEWEST_PYTHON) +def format(session): + """ + Run ruff to sort imports and format code. + """ + # 1. Install ruff (skipped automatically if you run with --no-venv) + session.install(RUFF_VERSION) + + # 2. Run Ruff to fix imports + # check --select I: Enables strict import sorting + # --fix: Applies the changes automatically + session.run( + "ruff", + "check", + "--select", + "I", + "--fix", + "--line-length=88", # Standard Black line length + *LINT_PATHS, + ) + + # 3. Run Ruff to format code session.run( - "black", - *BLACK_PATHS, - "--extend-exclude", - BLACK_EXCLUDES, + "ruff", + "format", + "--line-length=88", # Standard Black line length + *LINT_PATHS, ) diff --git a/tests/integration/goldens/asset/noxfile.py b/tests/integration/goldens/asset/noxfile.py index 4ab620d505..396d6dd96e 100755 --- a/tests/integration/goldens/asset/noxfile.py +++ b/tests/integration/goldens/asset/noxfile.py @@ -22,8 +22,7 @@ import nox -BLACK_VERSION = "black[jupyter]==23.7.0" -ISORT_VERSION = "isort==5.11.0" +RUFF_VERSION = "ruff==0.14.14" LINT_PATHS = ["docs", "google", "tests", "noxfile.py", "setup.py"] @@ -149,42 +148,47 @@ def lint(session): Returns a failure if the linters find linting errors or sufficiently serious code quality issues. """ - session.install("flake8", BLACK_VERSION) - session.run( - "black", - "--check", - *LINT_PATHS, - ) + session.install("flake8", RUFF_VERSION) + + # 2. Check formatting + session.run("ruff", "format", "--check", "--line-length=88", *LINT_PATHS) session.run("flake8", "google", "tests") @nox.session(python=DEFAULT_PYTHON_VERSION) def blacken(session): - """Run black. Format code to uniform standard.""" - session.install(BLACK_VERSION) - session.run( - "black", - *LINT_PATHS, - ) + """(Deprecated) Legacy session. Please use 'nox -s format'.""" + session.log("WARNING: The 'blacken' session is deprecated and will be removed in the next release. Please use 'nox -s format' in the future.") + + # Just run the ruff formatter (keeping legacy behavior of only formatting, not sorting imports) + session.install(RUFF_VERSION) + session.run("ruff", "format", "--line-length=88", *LINT_PATHS) @nox.session(python=DEFAULT_PYTHON_VERSION) def format(session): """ - Run isort to sort imports. Then run black - to format code to uniform standard. + Run ruff to sort imports and format code. """ - session.install(BLACK_VERSION, ISORT_VERSION) - # Use the --fss option to sort imports using strict alphabetical order. - # See https://pycqa.github.io/isort/docs/configuration/options.html#force-sort-within-sections + # 1. Install ruff (skipped automatically if you run with --no-venv) + session.install(RUFF_VERSION) + + # 2. Run Ruff to fix imports + # check --select I: Enables strict import sorting + # --fix: Applies the changes automatically session.run( - "isort", - "--fss", + "ruff", "check", + "--select", "I", + "--fix", + "--line-length=88", # Standard Black line length *LINT_PATHS, ) + + # 3. Run Ruff to format code session.run( - "black", + "ruff", "format", + "--line-length=88", # Standard Black line length *LINT_PATHS, ) diff --git a/tests/integration/goldens/credentials/noxfile.py b/tests/integration/goldens/credentials/noxfile.py index af4ba3e285..462cce9248 100755 --- a/tests/integration/goldens/credentials/noxfile.py +++ b/tests/integration/goldens/credentials/noxfile.py @@ -23,8 +23,7 @@ import nox -BLACK_VERSION = "black[jupyter]==23.7.0" -ISORT_VERSION = "isort==5.11.0" +RUFF_VERSION = "ruff==0.14.14" LINT_PATHS = ["docs", "google", "tests", "noxfile.py", "setup.py"] @@ -150,42 +149,47 @@ def lint(session): Returns a failure if the linters find linting errors or sufficiently serious code quality issues. """ - session.install("flake8", BLACK_VERSION) - session.run( - "black", - "--check", - *LINT_PATHS, - ) + session.install("flake8", RUFF_VERSION) + + # 2. Check formatting + session.run("ruff", "format", "--check", "--line-length=88", *LINT_PATHS) session.run("flake8", "google", "tests") @nox.session(python=DEFAULT_PYTHON_VERSION) def blacken(session): - """Run black. Format code to uniform standard.""" - session.install(BLACK_VERSION) - session.run( - "black", - *LINT_PATHS, - ) + """(Deprecated) Legacy session. Please use 'nox -s format'.""" + session.log("WARNING: The 'blacken' session is deprecated and will be removed in the next release. Please use 'nox -s format' in the future.") + + # Just run the ruff formatter (keeping legacy behavior of only formatting, not sorting imports) + session.install(RUFF_VERSION) + session.run("ruff", "format", "--line-length=88", *LINT_PATHS) @nox.session(python=DEFAULT_PYTHON_VERSION) def format(session): """ - Run isort to sort imports. Then run black - to format code to uniform standard. + Run ruff to sort imports and format code. """ - session.install(BLACK_VERSION, ISORT_VERSION) - # Use the --fss option to sort imports using strict alphabetical order. - # See https://pycqa.github.io/isort/docs/configuration/options.html#force-sort-within-sections + # 1. Install ruff (skipped automatically if you run with --no-venv) + session.install(RUFF_VERSION) + + # 2. Run Ruff to fix imports + # check --select I: Enables strict import sorting + # --fix: Applies the changes automatically session.run( - "isort", - "--fss", + "ruff", "check", + "--select", "I", + "--fix", + "--line-length=88", # Standard Black line length *LINT_PATHS, ) + + # 3. Run Ruff to format code session.run( - "black", + "ruff", "format", + "--line-length=88", # Standard Black line length *LINT_PATHS, ) diff --git a/tests/integration/goldens/eventarc/noxfile.py b/tests/integration/goldens/eventarc/noxfile.py index c718640903..cd7b4f82fe 100755 --- a/tests/integration/goldens/eventarc/noxfile.py +++ b/tests/integration/goldens/eventarc/noxfile.py @@ -23,8 +23,7 @@ import nox -BLACK_VERSION = "black[jupyter]==23.7.0" -ISORT_VERSION = "isort==5.11.0" +RUFF_VERSION = "ruff==0.14.14" LINT_PATHS = ["docs", "google", "tests", "noxfile.py", "setup.py"] @@ -150,42 +149,47 @@ def lint(session): Returns a failure if the linters find linting errors or sufficiently serious code quality issues. """ - session.install("flake8", BLACK_VERSION) - session.run( - "black", - "--check", - *LINT_PATHS, - ) + session.install("flake8", RUFF_VERSION) + + # 2. Check formatting + session.run("ruff", "format", "--check", "--line-length=88", *LINT_PATHS) session.run("flake8", "google", "tests") @nox.session(python=DEFAULT_PYTHON_VERSION) def blacken(session): - """Run black. Format code to uniform standard.""" - session.install(BLACK_VERSION) - session.run( - "black", - *LINT_PATHS, - ) + """(Deprecated) Legacy session. Please use 'nox -s format'.""" + session.log("WARNING: The 'blacken' session is deprecated and will be removed in the next release. Please use 'nox -s format' in the future.") + + # Just run the ruff formatter (keeping legacy behavior of only formatting, not sorting imports) + session.install(RUFF_VERSION) + session.run("ruff", "format", "--line-length=88", *LINT_PATHS) @nox.session(python=DEFAULT_PYTHON_VERSION) def format(session): """ - Run isort to sort imports. Then run black - to format code to uniform standard. + Run ruff to sort imports and format code. """ - session.install(BLACK_VERSION, ISORT_VERSION) - # Use the --fss option to sort imports using strict alphabetical order. - # See https://pycqa.github.io/isort/docs/configuration/options.html#force-sort-within-sections + # 1. Install ruff (skipped automatically if you run with --no-venv) + session.install(RUFF_VERSION) + + # 2. Run Ruff to fix imports + # check --select I: Enables strict import sorting + # --fix: Applies the changes automatically session.run( - "isort", - "--fss", + "ruff", "check", + "--select", "I", + "--fix", + "--line-length=88", # Standard Black line length *LINT_PATHS, ) + + # 3. Run Ruff to format code session.run( - "black", + "ruff", "format", + "--line-length=88", # Standard Black line length *LINT_PATHS, ) diff --git a/tests/integration/goldens/logging/noxfile.py b/tests/integration/goldens/logging/noxfile.py index 8bf90a69f4..e43fa5b2fb 100755 --- a/tests/integration/goldens/logging/noxfile.py +++ b/tests/integration/goldens/logging/noxfile.py @@ -23,8 +23,7 @@ import nox -BLACK_VERSION = "black[jupyter]==23.7.0" -ISORT_VERSION = "isort==5.11.0" +RUFF_VERSION = "ruff==0.14.14" LINT_PATHS = ["docs", "google", "tests", "noxfile.py", "setup.py"] @@ -150,42 +149,47 @@ def lint(session): Returns a failure if the linters find linting errors or sufficiently serious code quality issues. """ - session.install("flake8", BLACK_VERSION) - session.run( - "black", - "--check", - *LINT_PATHS, - ) + session.install("flake8", RUFF_VERSION) + + # 2. Check formatting + session.run("ruff", "format", "--check", "--line-length=88", *LINT_PATHS) session.run("flake8", "google", "tests") @nox.session(python=DEFAULT_PYTHON_VERSION) def blacken(session): - """Run black. Format code to uniform standard.""" - session.install(BLACK_VERSION) - session.run( - "black", - *LINT_PATHS, - ) + """(Deprecated) Legacy session. Please use 'nox -s format'.""" + session.log("WARNING: The 'blacken' session is deprecated and will be removed in the next release. Please use 'nox -s format' in the future.") + + # Just run the ruff formatter (keeping legacy behavior of only formatting, not sorting imports) + session.install(RUFF_VERSION) + session.run("ruff", "format", "--line-length=88", *LINT_PATHS) @nox.session(python=DEFAULT_PYTHON_VERSION) def format(session): """ - Run isort to sort imports. Then run black - to format code to uniform standard. + Run ruff to sort imports and format code. """ - session.install(BLACK_VERSION, ISORT_VERSION) - # Use the --fss option to sort imports using strict alphabetical order. - # See https://pycqa.github.io/isort/docs/configuration/options.html#force-sort-within-sections + # 1. Install ruff (skipped automatically if you run with --no-venv) + session.install(RUFF_VERSION) + + # 2. Run Ruff to fix imports + # check --select I: Enables strict import sorting + # --fix: Applies the changes automatically session.run( - "isort", - "--fss", + "ruff", "check", + "--select", "I", + "--fix", + "--line-length=88", # Standard Black line length *LINT_PATHS, ) + + # 3. Run Ruff to format code session.run( - "black", + "ruff", "format", + "--line-length=88", # Standard Black line length *LINT_PATHS, ) diff --git a/tests/integration/goldens/logging_internal/noxfile.py b/tests/integration/goldens/logging_internal/noxfile.py index 8bf90a69f4..e43fa5b2fb 100755 --- a/tests/integration/goldens/logging_internal/noxfile.py +++ b/tests/integration/goldens/logging_internal/noxfile.py @@ -23,8 +23,7 @@ import nox -BLACK_VERSION = "black[jupyter]==23.7.0" -ISORT_VERSION = "isort==5.11.0" +RUFF_VERSION = "ruff==0.14.14" LINT_PATHS = ["docs", "google", "tests", "noxfile.py", "setup.py"] @@ -150,42 +149,47 @@ def lint(session): Returns a failure if the linters find linting errors or sufficiently serious code quality issues. """ - session.install("flake8", BLACK_VERSION) - session.run( - "black", - "--check", - *LINT_PATHS, - ) + session.install("flake8", RUFF_VERSION) + + # 2. Check formatting + session.run("ruff", "format", "--check", "--line-length=88", *LINT_PATHS) session.run("flake8", "google", "tests") @nox.session(python=DEFAULT_PYTHON_VERSION) def blacken(session): - """Run black. Format code to uniform standard.""" - session.install(BLACK_VERSION) - session.run( - "black", - *LINT_PATHS, - ) + """(Deprecated) Legacy session. Please use 'nox -s format'.""" + session.log("WARNING: The 'blacken' session is deprecated and will be removed in the next release. Please use 'nox -s format' in the future.") + + # Just run the ruff formatter (keeping legacy behavior of only formatting, not sorting imports) + session.install(RUFF_VERSION) + session.run("ruff", "format", "--line-length=88", *LINT_PATHS) @nox.session(python=DEFAULT_PYTHON_VERSION) def format(session): """ - Run isort to sort imports. Then run black - to format code to uniform standard. + Run ruff to sort imports and format code. """ - session.install(BLACK_VERSION, ISORT_VERSION) - # Use the --fss option to sort imports using strict alphabetical order. - # See https://pycqa.github.io/isort/docs/configuration/options.html#force-sort-within-sections + # 1. Install ruff (skipped automatically if you run with --no-venv) + session.install(RUFF_VERSION) + + # 2. Run Ruff to fix imports + # check --select I: Enables strict import sorting + # --fix: Applies the changes automatically session.run( - "isort", - "--fss", + "ruff", "check", + "--select", "I", + "--fix", + "--line-length=88", # Standard Black line length *LINT_PATHS, ) + + # 3. Run Ruff to format code session.run( - "black", + "ruff", "format", + "--line-length=88", # Standard Black line length *LINT_PATHS, ) diff --git a/tests/integration/goldens/redis/noxfile.py b/tests/integration/goldens/redis/noxfile.py index 4349f5147d..25a3ec57da 100755 --- a/tests/integration/goldens/redis/noxfile.py +++ b/tests/integration/goldens/redis/noxfile.py @@ -23,8 +23,7 @@ import nox -BLACK_VERSION = "black[jupyter]==23.7.0" -ISORT_VERSION = "isort==5.11.0" +RUFF_VERSION = "ruff==0.14.14" LINT_PATHS = ["docs", "google", "tests", "noxfile.py", "setup.py"] @@ -150,42 +149,47 @@ def lint(session): Returns a failure if the linters find linting errors or sufficiently serious code quality issues. """ - session.install("flake8", BLACK_VERSION) - session.run( - "black", - "--check", - *LINT_PATHS, - ) + session.install("flake8", RUFF_VERSION) + + # 2. Check formatting + session.run("ruff", "format", "--check", "--line-length=88", *LINT_PATHS) session.run("flake8", "google", "tests") @nox.session(python=DEFAULT_PYTHON_VERSION) def blacken(session): - """Run black. Format code to uniform standard.""" - session.install(BLACK_VERSION) - session.run( - "black", - *LINT_PATHS, - ) + """(Deprecated) Legacy session. Please use 'nox -s format'.""" + session.log("WARNING: The 'blacken' session is deprecated and will be removed in the next release. Please use 'nox -s format' in the future.") + + # Just run the ruff formatter (keeping legacy behavior of only formatting, not sorting imports) + session.install(RUFF_VERSION) + session.run("ruff", "format", "--line-length=88", *LINT_PATHS) @nox.session(python=DEFAULT_PYTHON_VERSION) def format(session): """ - Run isort to sort imports. Then run black - to format code to uniform standard. + Run ruff to sort imports and format code. """ - session.install(BLACK_VERSION, ISORT_VERSION) - # Use the --fss option to sort imports using strict alphabetical order. - # See https://pycqa.github.io/isort/docs/configuration/options.html#force-sort-within-sections + # 1. Install ruff (skipped automatically if you run with --no-venv) + session.install(RUFF_VERSION) + + # 2. Run Ruff to fix imports + # check --select I: Enables strict import sorting + # --fix: Applies the changes automatically session.run( - "isort", - "--fss", + "ruff", "check", + "--select", "I", + "--fix", + "--line-length=88", # Standard Black line length *LINT_PATHS, ) + + # 3. Run Ruff to format code session.run( - "black", + "ruff", "format", + "--line-length=88", # Standard Black line length *LINT_PATHS, ) diff --git a/tests/integration/goldens/redis_selective/noxfile.py b/tests/integration/goldens/redis_selective/noxfile.py index 4349f5147d..25a3ec57da 100755 --- a/tests/integration/goldens/redis_selective/noxfile.py +++ b/tests/integration/goldens/redis_selective/noxfile.py @@ -23,8 +23,7 @@ import nox -BLACK_VERSION = "black[jupyter]==23.7.0" -ISORT_VERSION = "isort==5.11.0" +RUFF_VERSION = "ruff==0.14.14" LINT_PATHS = ["docs", "google", "tests", "noxfile.py", "setup.py"] @@ -150,42 +149,47 @@ def lint(session): Returns a failure if the linters find linting errors or sufficiently serious code quality issues. """ - session.install("flake8", BLACK_VERSION) - session.run( - "black", - "--check", - *LINT_PATHS, - ) + session.install("flake8", RUFF_VERSION) + + # 2. Check formatting + session.run("ruff", "format", "--check", "--line-length=88", *LINT_PATHS) session.run("flake8", "google", "tests") @nox.session(python=DEFAULT_PYTHON_VERSION) def blacken(session): - """Run black. Format code to uniform standard.""" - session.install(BLACK_VERSION) - session.run( - "black", - *LINT_PATHS, - ) + """(Deprecated) Legacy session. Please use 'nox -s format'.""" + session.log("WARNING: The 'blacken' session is deprecated and will be removed in the next release. Please use 'nox -s format' in the future.") + + # Just run the ruff formatter (keeping legacy behavior of only formatting, not sorting imports) + session.install(RUFF_VERSION) + session.run("ruff", "format", "--line-length=88", *LINT_PATHS) @nox.session(python=DEFAULT_PYTHON_VERSION) def format(session): """ - Run isort to sort imports. Then run black - to format code to uniform standard. + Run ruff to sort imports and format code. """ - session.install(BLACK_VERSION, ISORT_VERSION) - # Use the --fss option to sort imports using strict alphabetical order. - # See https://pycqa.github.io/isort/docs/configuration/options.html#force-sort-within-sections + # 1. Install ruff (skipped automatically if you run with --no-venv) + session.install(RUFF_VERSION) + + # 2. Run Ruff to fix imports + # check --select I: Enables strict import sorting + # --fix: Applies the changes automatically session.run( - "isort", - "--fss", + "ruff", "check", + "--select", "I", + "--fix", + "--line-length=88", # Standard Black line length *LINT_PATHS, ) + + # 3. Run Ruff to format code session.run( - "black", + "ruff", "format", + "--line-length=88", # Standard Black line length *LINT_PATHS, ) diff --git a/tests/system/test_lro.py b/tests/system/test_lro.py index ba7241c2de..c5722ed27d 100644 --- a/tests/system/test_lro.py +++ b/tests/system/test_lro.py @@ -37,7 +37,6 @@ def test_lro(echo): @pytest.mark.asyncio async def test_lro_async(async_echo): - future = await async_echo.wait( { "end_time": datetime.now(tz=timezone.utc) + timedelta(seconds=1), diff --git a/tests/unit/common_types.py b/tests/unit/common_types.py index d8f8375499..4ea17c6429 100644 --- a/tests/unit/common_types.py +++ b/tests/unit/common_types.py @@ -94,7 +94,7 @@ def __init__( options=False, ident=False, resource_path=False, - meta=None + meta=None, ): self.fields = fields self.type = type diff --git a/tests/unit/generator/test_formatter.py b/tests/unit/generator/test_formatter.py index 9d613c2b31..5a5e24d68e 100644 --- a/tests/unit/generator/test_formatter.py +++ b/tests/unit/generator/test_formatter.py @@ -18,10 +18,9 @@ def test_fix_whitespace_top_level(): - assert ( - formatter.fix_whitespace( - textwrap.dedent( - """\ + assert formatter.fix_whitespace( + textwrap.dedent( + """\ import something @@ -36,10 +35,9 @@ class TooFarDown: class TooClose: # remains too close pass """ - ) ) - == textwrap.dedent( - """\ + ) == textwrap.dedent( + """\ import something @@ -53,15 +51,13 @@ class TooFarDown: class TooClose: # remains too close pass """ - ) ) def test_fix_whitespace_nested(): - assert ( - formatter.fix_whitespace( - textwrap.dedent( - """\ + assert formatter.fix_whitespace( + textwrap.dedent( + """\ class JustAClass: def foo(self): pass @@ -70,10 +66,9 @@ def foo(self): def too_far_down(self): pass """ - ) ) - == textwrap.dedent( - """\ + ) == textwrap.dedent( + """\ class JustAClass: def foo(self): pass @@ -81,15 +76,13 @@ def foo(self): def too_far_down(self): pass """ - ) ) def test_fix_whitespace_decorators(): - assert ( - formatter.fix_whitespace( - textwrap.dedent( - """\ + assert formatter.fix_whitespace( + textwrap.dedent( + """\ class JustAClass: def foo(self): pass @@ -99,10 +92,9 @@ def foo(self): def too_far_down(self): return 42 """ - ) ) - == textwrap.dedent( - """\ + ) == textwrap.dedent( + """\ class JustAClass: def foo(self): pass @@ -111,15 +103,13 @@ def foo(self): def too_far_down(self): return 42 """ - ) ) def test_fix_whitespace_intermediate_whitespace(): - assert ( - formatter.fix_whitespace( - textwrap.dedent( - """\ + assert formatter.fix_whitespace( + textwrap.dedent( + """\ class JustAClass: def foo(self): pass @@ -130,10 +120,9 @@ def foo(self): def too_far_down(self): return 42 """ - ) ) - == textwrap.dedent( - """\ + ) == textwrap.dedent( + """\ class JustAClass: def foo(self): pass @@ -142,15 +131,13 @@ def foo(self): def too_far_down(self): return 42 """ - ) ) def test_fix_whitespace_comment(): - assert ( - formatter.fix_whitespace( - textwrap.dedent( - """\ + assert formatter.fix_whitespace( + textwrap.dedent( + """\ def do_something(): do_first_thing() @@ -158,17 +145,15 @@ def do_something(): # Something something something. do_second_thing() """ - ) ) - == textwrap.dedent( - """\ + ) == textwrap.dedent( + """\ def do_something(): do_first_thing() # Something something something. do_second_thing() """ - ) ) diff --git a/tests/unit/generator/test_generator.py b/tests/unit/generator/test_generator.py index 1e4578b516..9d8545c419 100644 --- a/tests/unit/generator/test_generator.py +++ b/tests/unit/generator/test_generator.py @@ -861,13 +861,13 @@ def make_api( *protos, naming: naming.Naming = None, service_yaml_config: service_pb2.Service = None, - **kwargs + **kwargs, ) -> api.API: return api.API( naming=naming or make_naming(), service_yaml_config=service_yaml_config or service_pb2.Service(), all_protos={i.name: i for i in protos}, - **kwargs + **kwargs, ) diff --git a/tests/unit/generator/test_options.py b/tests/unit/generator/test_options.py index 49ae6e216d..8b17aae911 100644 --- a/tests/unit/generator/test_options.py +++ b/tests/unit/generator/test_options.py @@ -161,7 +161,7 @@ def test_options_service_yaml_config(fs): service_yaml_fpath = "testapi_v2.yaml" fs.create_file( service_yaml_fpath, - contents=("config_version: 3\n" "name: testapi.googleapis.com\n"), + contents=("config_version: 3\nname: testapi.googleapis.com\n"), ) opt_string = f"service-yaml={service_yaml_fpath}" opts = Options.build(opt_string) diff --git a/tests/unit/schema/test_api.py b/tests/unit/schema/test_api.py index 300e8cab89..9d2dab2ec6 100644 --- a/tests/unit/schema/test_api.py +++ b/tests/unit/schema/test_api.py @@ -2611,16 +2611,16 @@ def test_mixin_api_methods_locations(): assert len(ms) == 2 m1 = ms["ListLocations"] m1.options.ClearExtension(annotations_pb2.http) - m1.options.Extensions[annotations_pb2.http].selector = ( - "google.cloud.location.Locations.ListLocations" - ) + m1.options.Extensions[ + annotations_pb2.http + ].selector = "google.cloud.location.Locations.ListLocations" m1.options.Extensions[annotations_pb2.http].get = "/v1/{name=examples/*}/*" m1.options.Extensions[annotations_pb2.http].body = "*" m2 = ms["GetLocation"] m2.options.ClearExtension(annotations_pb2.http) - m2.options.Extensions[annotations_pb2.http].selector = ( - "google.cloud.location.Locations.GetLocation" - ) + m2.options.Extensions[ + annotations_pb2.http + ].selector = "google.cloud.location.Locations.GetLocation" m2.options.Extensions[annotations_pb2.http].get = "/v1/{name=examples/*}/*" m2.options.Extensions[annotations_pb2.http].body = "*" api_schema = api.API.build(fd, "google.example.v1", opts=opts) @@ -3032,9 +3032,9 @@ def get_file_descriptor_proto_for_tests( """ field_options = descriptor_pb2.FieldOptions() - field_options.Extensions[field_info_pb2.field_info].format = ( - field_info_pb2.FieldInfo.Format.Value("UUID4") - ) + field_options.Extensions[ + field_info_pb2.field_info + ].format = field_info_pb2.FieldInfo.Format.Value("UUID4") fd = ( make_file_pb2( @@ -4213,9 +4213,9 @@ def test_read_method_settings_from_service_yaml(): } cli_options = Options(service_yaml_config=service_yaml_config) field_options = descriptor_pb2.FieldOptions() - field_options.Extensions[field_info_pb2.field_info].format = ( - field_info_pb2.FieldInfo.Format.Value("UUID4") - ) + field_options.Extensions[ + field_info_pb2.field_info + ].format = field_info_pb2.FieldInfo.Format.Value("UUID4") squid = make_field_pb2( name="squid", type="TYPE_STRING", options=field_options, number=1 @@ -4430,9 +4430,9 @@ def test_method_settings_unsupported_auto_populated_field_field_info_format_rais the format of the field is `IPV4`. """ field_options = descriptor_pb2.FieldOptions() - field_options.Extensions[field_info_pb2.field_info].format = ( - field_info_pb2.FieldInfo.Format.Value("IPV4") - ) + field_options.Extensions[ + field_info_pb2.field_info + ].format = field_info_pb2.FieldInfo.Format.Value("IPV4") squid = make_field_pb2( name="squid", type="TYPE_STRING", options=field_options, number=1 ) @@ -4461,9 +4461,9 @@ def test_method_settings_invalid_multiple_issues(): # - Not annotated with google.api.field_info.format = UUID4 # - Not of type string # - Required field - field_options.Extensions[field_info_pb2.field_info].format = ( - field_info_pb2.FieldInfo.Format.Value("IPV4") - ) + field_options.Extensions[ + field_info_pb2.field_info + ].format = field_info_pb2.FieldInfo.Format.Value("IPV4") squid = make_field_pb2( name="squid", type="TYPE_INT32", options=field_options, number=1 ) diff --git a/tests/unit/schema/wrappers/test_field.py b/tests/unit/schema/wrappers/test_field.py index dd8367c2ef..69f243ede8 100644 --- a/tests/unit/schema/wrappers/test_field.py +++ b/tests/unit/schema/wrappers/test_field.py @@ -143,9 +143,9 @@ def test_not_required(): def test_uuid4(): field = make_field() - field.options.Extensions[field_info_pb2.field_info].format = ( - field_info_pb2.FieldInfo.Format.Value("UUID4") - ) + field.options.Extensions[ + field_info_pb2.field_info + ].format = field_info_pb2.FieldInfo.Format.Value("UUID4") assert field.uuid4 @@ -186,9 +186,9 @@ def test_ident_sphinx_map(): def test_resource_reference(): field = make_field(type="TYPE_STRING") - field.options.Extensions[resource_pb2.resource_reference].type = ( - "translate.googleapis.com/Glossary" - ) + field.options.Extensions[ + resource_pb2.resource_reference + ].type = "translate.googleapis.com/Glossary" assert field.resource_reference == "translate.googleapis.com/Glossary" diff --git a/tests/unit/schema/wrappers/test_method.py b/tests/unit/schema/wrappers/test_method.py index 088958e06b..87eb959cb8 100644 --- a/tests/unit/schema/wrappers/test_method.py +++ b/tests/unit/schema/wrappers/test_method.py @@ -180,7 +180,8 @@ def test_method_paged_result_field_no_page_field(): method = make_method( name="Foo", input_message=make_message( - name="FooRequest", fields=(make_field(name="page_token", type=9),) # str + name="FooRequest", + fields=(make_field(name="page_token", type=9),), # str ), output_message=make_message( name="FooResponse", From efb7a7d3452cf5bcd1340868ca9720fc3718176c Mon Sep 17 00:00:00 2001 From: ohmayr Date: Wed, 28 Jan 2026 00:40:56 +0000 Subject: [PATCH 2/2] forma nox session with ruff --- .../asset/google/cloud/asset_v1/__init__.py | 83 ++ .../services/asset_service/async_client.py | 24 +- .../asset_v1/services/asset_service/client.py | 33 +- .../asset_v1/services/asset_service/pagers.py | 28 +- .../services/asset_service/transports/base.py | 4 +- .../services/asset_service/transports/grpc.py | 56 +- .../asset_service/transports/grpc_asyncio.py | 54 +- .../services/asset_service/transports/rest.py | 82 +- .../asset_service/transports/rest_base.py | 6 +- .../cloud/asset_v1/types/asset_service.py | 54 +- .../google/cloud/asset_v1/types/assets.py | 78 +- tests/integration/goldens/asset/noxfile.py | 17 +- .../unit/gapic/asset_v1/test_asset_service.py | 859 ++++++++++-------- 13 files changed, 791 insertions(+), 587 deletions(-) diff --git a/tests/integration/goldens/asset/google/cloud/asset_v1/__init__.py b/tests/integration/goldens/asset/google/cloud/asset_v1/__init__.py index 1f156e9cba..5709092325 100755 --- a/tests/integration/goldens/asset/google/cloud/asset_v1/__init__.py +++ b/tests/integration/goldens/asset/google/cloud/asset_v1/__init__.py @@ -111,6 +111,89 @@ VersionedResource, ) +from .services.asset_service import AssetServiceAsyncClient, AssetServiceClient +from .types.asset_service import ( + AnalyzeIamPolicyLongrunningMetadata, + AnalyzeIamPolicyLongrunningRequest, + AnalyzeIamPolicyLongrunningResponse, + AnalyzeIamPolicyRequest, + AnalyzeIamPolicyResponse, + AnalyzeMoveRequest, + AnalyzeMoveResponse, + AnalyzeOrgPoliciesRequest, + AnalyzeOrgPoliciesResponse, + AnalyzeOrgPolicyGovernedAssetsRequest, + AnalyzeOrgPolicyGovernedAssetsResponse, + AnalyzeOrgPolicyGovernedContainersRequest, + AnalyzeOrgPolicyGovernedContainersResponse, + AnalyzerOrgPolicy, + AnalyzerOrgPolicyConstraint, + BatchGetAssetsHistoryRequest, + BatchGetAssetsHistoryResponse, + BatchGetEffectiveIamPoliciesRequest, + BatchGetEffectiveIamPoliciesResponse, + BigQueryDestination, + ContentType, + CreateFeedRequest, + CreateSavedQueryRequest, + DeleteFeedRequest, + DeleteSavedQueryRequest, + ExportAssetsRequest, + ExportAssetsResponse, + Feed, + FeedOutputConfig, + GcsDestination, + GcsOutputResult, + GetFeedRequest, + GetSavedQueryRequest, + IamPolicyAnalysisOutputConfig, + IamPolicyAnalysisQuery, + ListAssetsRequest, + ListAssetsResponse, + ListFeedsRequest, + ListFeedsResponse, + ListSavedQueriesRequest, + ListSavedQueriesResponse, + MoveAnalysis, + MoveAnalysisResult, + MoveImpact, + OutputConfig, + OutputResult, + PartitionSpec, + PubsubDestination, + QueryAssetsOutputConfig, + QueryAssetsRequest, + QueryAssetsResponse, + QueryResult, + SavedQuery, + SearchAllIamPoliciesRequest, + SearchAllIamPoliciesResponse, + SearchAllResourcesRequest, + SearchAllResourcesResponse, + TableFieldSchema, + TableSchema, + UpdateFeedRequest, + UpdateSavedQueryRequest, +) +from .types.assets import ( + Asset, + AttachedResource, + ConditionEvaluation, + IamPolicyAnalysisResult, + IamPolicyAnalysisState, + IamPolicySearchResult, + RelatedAsset, + RelatedAssets, + RelatedResource, + RelatedResources, + RelationshipAttributes, + Resource, + ResourceSearchResult, + TemporalAsset, + TimeWindow, + VersionedResource, +) + if hasattr(api_core, "check_python_version") and hasattr( api_core, "check_dependency_versions" ): # pragma: NO COVER diff --git a/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/async_client.py b/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/async_client.py index 819a925f12..f62834884b 100755 --- a/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/async_client.py +++ b/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/async_client.py @@ -13,9 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # -from collections import OrderedDict import logging as std_logging import re +from collections import OrderedDict from typing import ( Callable, Dict, @@ -29,13 +29,13 @@ Union, ) +import google.protobuf from google.api_core import exceptions as core_exceptions from google.api_core import gapic_v1 from google.api_core import retry_async as retries from google.api_core.client_options import ClientOptions from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore -import google.protobuf from google.cloud.asset_v1 import gapic_version as package_version @@ -44,11 +44,15 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.AsyncRetry, object, None] # type: ignore -from google.api_core import operation # type: ignore -from google.api_core import operation_async # type: ignore +from google.api_core import ( + operation, # type: ignore + operation_async, # type: ignore +) from google.longrunning import operations_pb2 # type: ignore -from google.protobuf import field_mask_pb2 # type: ignore -from google.protobuf import timestamp_pb2 # type: ignore +from google.protobuf import ( + field_mask_pb2, # type: ignore + timestamp_pb2, # type: ignore +) from google.rpc import status_pb2 # type: ignore from google.type import expr_pb2 # type: ignore @@ -131,7 +135,9 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): Returns: AssetServiceAsyncClient: The constructed client. """ - return AssetServiceClient.from_service_account_info.__func__(AssetServiceAsyncClient, info, *args, **kwargs) # type: ignore + return AssetServiceClient.from_service_account_info.__func__( + AssetServiceAsyncClient, info, *args, **kwargs + ) # type: ignore @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): @@ -147,7 +153,9 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): Returns: AssetServiceAsyncClient: The constructed client. """ - return AssetServiceClient.from_service_account_file.__func__(AssetServiceAsyncClient, filename, *args, **kwargs) # type: ignore + return AssetServiceClient.from_service_account_file.__func__( + AssetServiceAsyncClient, filename, *args, **kwargs + ) # type: ignore from_service_account_json = from_service_account_file diff --git a/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/client.py b/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/client.py index ebb4538e18..e26a752f51 100755 --- a/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/client.py +++ b/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/client.py @@ -13,12 +13,13 @@ # See the License for the specific language governing permissions and # limitations under the License. # -from collections import OrderedDict -from http import HTTPStatus import json import logging as std_logging import os import re +import warnings +from collections import OrderedDict +from http import HTTPStatus from typing import ( Callable, Dict, @@ -32,8 +33,8 @@ Union, cast, ) -import warnings +import google.protobuf from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions from google.api_core import gapic_v1 @@ -43,7 +44,8 @@ from google.auth.transport import mtls # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore from google.oauth2 import service_account # type: ignore -import google.protobuf + +from google.cloud.asset_v1 import gapic_version as package_version from google.cloud.asset_v1 import gapic_version as package_version @@ -61,11 +63,15 @@ _LOGGER = std_logging.getLogger(__name__) -from google.api_core import operation # type: ignore -from google.api_core import operation_async # type: ignore +from google.api_core import ( + operation, # type: ignore + operation_async, # type: ignore +) from google.longrunning import operations_pb2 # type: ignore -from google.protobuf import field_mask_pb2 # type: ignore -from google.protobuf import timestamp_pb2 # type: ignore +from google.protobuf import ( + field_mask_pb2, # type: ignore + timestamp_pb2, # type: ignore +) from google.rpc import status_pb2 # type: ignore from google.type import expr_pb2 # type: ignore @@ -731,11 +737,9 @@ def __init__( universe_domain_opt = getattr(self._client_options, "universe_domain", None) - ( - self._use_client_cert, - self._use_mtls_endpoint, - self._universe_domain_env, - ) = AssetServiceClient._read_environment_variables() + self._use_client_cert, self._use_mtls_endpoint, self._universe_domain_env = ( + AssetServiceClient._read_environment_variables() + ) self._client_cert_source = AssetServiceClient._get_client_cert_source( self._client_options.client_cert_source, self._use_client_cert ) @@ -770,8 +774,7 @@ def __init__( ) if self._client_options.scopes: raise ValueError( - "When providing a transport instance, provide its scopes " - "directly." + "When providing a transport instance, provide its scopes directly." ) self._transport = cast(AssetServiceTransport, transport) self._api_endpoint = self._transport.host diff --git a/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/pagers.py b/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/pagers.py index 11261a60e0..64466fe118 100755 --- a/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/pagers.py +++ b/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/pagers.py @@ -67,7 +67,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, Union[str, bytes]]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ): """Instantiate the pager. @@ -143,7 +143,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, Union[str, bytes]]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ): """Instantiates the pager. @@ -223,7 +223,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, Union[str, bytes]]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ): """Instantiate the pager. @@ -299,7 +299,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, Union[str, bytes]]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ): """Instantiates the pager. @@ -379,7 +379,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, Union[str, bytes]]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ): """Instantiate the pager. @@ -455,7 +455,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, Union[str, bytes]]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ): """Instantiates the pager. @@ -535,7 +535,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, Union[str, bytes]]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ): """Instantiate the pager. @@ -611,7 +611,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, Union[str, bytes]]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ): """Instantiates the pager. @@ -691,7 +691,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, Union[str, bytes]]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ): """Instantiate the pager. @@ -769,7 +769,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, Union[str, bytes]]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ): """Instantiates the pager. @@ -851,7 +851,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, Union[str, bytes]]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ): """Instantiate the pager. @@ -935,7 +935,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, Union[str, bytes]]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ): """Instantiates the pager. @@ -1021,7 +1021,7 @@ def __init__( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, Union[str, bytes]]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ): """Instantiate the pager. @@ -1101,7 +1101,7 @@ def __init__( *, retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, Union[str, bytes]]] = () + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ): """Instantiates the pager. diff --git a/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/transports/base.py b/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/transports/base.py index 9c1609c99c..c81bb3be15 100755 --- a/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/transports/base.py +++ b/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/transports/base.py @@ -17,14 +17,14 @@ from typing import Awaitable, Callable, Dict, Optional, Sequence, Union import google.api_core +import google.auth # type: ignore +import google.protobuf from google.api_core import exceptions as core_exceptions from google.api_core import gapic_v1, operations_v1 from google.api_core import retry as retries -import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.longrunning import operations_pb2 # type: ignore from google.oauth2 import service_account # type: ignore -import google.protobuf from google.protobuf import empty_pb2 # type: ignore from google.cloud.asset_v1 import gapic_version as package_version diff --git a/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/transports/grpc.py b/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/transports/grpc.py index 7dea734c1f..cc68e3d629 100755 --- a/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/transports/grpc.py +++ b/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/transports/grpc.py @@ -19,16 +19,16 @@ from typing import Callable, Dict, Optional, Sequence, Tuple, Union import warnings -from google.api_core import gapic_v1, grpc_helpers, operations_v1 import google.auth # type: ignore +import google.protobuf.message +import grpc # type: ignore +import proto # type: ignore +from google.api_core import gapic_v1, grpc_helpers, operations_v1 from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore from google.longrunning import operations_pb2 # type: ignore from google.protobuf import empty_pb2 # type: ignore from google.protobuf.json_format import MessageToJson -import google.protobuf.message -import grpc # type: ignore -import proto # type: ignore from google.cloud.asset_v1.types import asset_service @@ -696,12 +696,12 @@ def analyze_iam_policy_longrunning( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "analyze_iam_policy_longrunning" not in self._stubs: - self._stubs[ - "analyze_iam_policy_longrunning" - ] = self._logged_channel.unary_unary( - "/google.cloud.asset.v1.AssetService/AnalyzeIamPolicyLongrunning", - request_serializer=asset_service.AnalyzeIamPolicyLongrunningRequest.serialize, - response_deserializer=operations_pb2.Operation.FromString, + self._stubs["analyze_iam_policy_longrunning"] = ( + self._logged_channel.unary_unary( + "/google.cloud.asset.v1.AssetService/AnalyzeIamPolicyLongrunning", + request_serializer=asset_service.AnalyzeIamPolicyLongrunningRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) ) return self._stubs["analyze_iam_policy_longrunning"] @@ -939,12 +939,12 @@ def batch_get_effective_iam_policies( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "batch_get_effective_iam_policies" not in self._stubs: - self._stubs[ - "batch_get_effective_iam_policies" - ] = self._logged_channel.unary_unary( - "/google.cloud.asset.v1.AssetService/BatchGetEffectiveIamPolicies", - request_serializer=asset_service.BatchGetEffectiveIamPoliciesRequest.serialize, - response_deserializer=asset_service.BatchGetEffectiveIamPoliciesResponse.deserialize, + self._stubs["batch_get_effective_iam_policies"] = ( + self._logged_channel.unary_unary( + "/google.cloud.asset.v1.AssetService/BatchGetEffectiveIamPolicies", + request_serializer=asset_service.BatchGetEffectiveIamPoliciesRequest.serialize, + response_deserializer=asset_service.BatchGetEffectiveIamPoliciesResponse.deserialize, + ) ) return self._stubs["batch_get_effective_iam_policies"] @@ -1001,12 +1001,12 @@ def analyze_org_policy_governed_containers( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "analyze_org_policy_governed_containers" not in self._stubs: - self._stubs[ - "analyze_org_policy_governed_containers" - ] = self._logged_channel.unary_unary( - "/google.cloud.asset.v1.AssetService/AnalyzeOrgPolicyGovernedContainers", - request_serializer=asset_service.AnalyzeOrgPolicyGovernedContainersRequest.serialize, - response_deserializer=asset_service.AnalyzeOrgPolicyGovernedContainersResponse.deserialize, + self._stubs["analyze_org_policy_governed_containers"] = ( + self._logged_channel.unary_unary( + "/google.cloud.asset.v1.AssetService/AnalyzeOrgPolicyGovernedContainers", + request_serializer=asset_service.AnalyzeOrgPolicyGovernedContainersRequest.serialize, + response_deserializer=asset_service.AnalyzeOrgPolicyGovernedContainersResponse.deserialize, + ) ) return self._stubs["analyze_org_policy_governed_containers"] @@ -1051,12 +1051,12 @@ def analyze_org_policy_governed_assets( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "analyze_org_policy_governed_assets" not in self._stubs: - self._stubs[ - "analyze_org_policy_governed_assets" - ] = self._logged_channel.unary_unary( - "/google.cloud.asset.v1.AssetService/AnalyzeOrgPolicyGovernedAssets", - request_serializer=asset_service.AnalyzeOrgPolicyGovernedAssetsRequest.serialize, - response_deserializer=asset_service.AnalyzeOrgPolicyGovernedAssetsResponse.deserialize, + self._stubs["analyze_org_policy_governed_assets"] = ( + self._logged_channel.unary_unary( + "/google.cloud.asset.v1.AssetService/AnalyzeOrgPolicyGovernedAssets", + request_serializer=asset_service.AnalyzeOrgPolicyGovernedAssetsRequest.serialize, + response_deserializer=asset_service.AnalyzeOrgPolicyGovernedAssetsResponse.deserialize, + ) ) return self._stubs["analyze_org_policy_governed_assets"] diff --git a/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/transports/grpc_asyncio.py b/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/transports/grpc_asyncio.py index 9b20dc81a9..c3fe86e889 100755 --- a/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/transports/grpc_asyncio.py +++ b/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/transports/grpc_asyncio.py @@ -17,9 +17,13 @@ import json import logging as std_logging import pickle +import warnings from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union import warnings +import google.protobuf.message +import grpc # type: ignore +import proto # type: ignore from google.api_core import exceptions as core_exceptions from google.api_core import gapic_v1, grpc_helpers_async, operations_v1 from google.api_core import retry_async as retries @@ -28,8 +32,6 @@ from google.longrunning import operations_pb2 # type: ignore from google.protobuf import empty_pb2 # type: ignore from google.protobuf.json_format import MessageToJson -import google.protobuf.message -import grpc # type: ignore from grpc.experimental import aio # type: ignore import proto # type: ignore @@ -714,12 +716,12 @@ def analyze_iam_policy_longrunning( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "analyze_iam_policy_longrunning" not in self._stubs: - self._stubs[ - "analyze_iam_policy_longrunning" - ] = self._logged_channel.unary_unary( - "/google.cloud.asset.v1.AssetService/AnalyzeIamPolicyLongrunning", - request_serializer=asset_service.AnalyzeIamPolicyLongrunningRequest.serialize, - response_deserializer=operations_pb2.Operation.FromString, + self._stubs["analyze_iam_policy_longrunning"] = ( + self._logged_channel.unary_unary( + "/google.cloud.asset.v1.AssetService/AnalyzeIamPolicyLongrunning", + request_serializer=asset_service.AnalyzeIamPolicyLongrunningRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) ) return self._stubs["analyze_iam_policy_longrunning"] @@ -964,12 +966,12 @@ def batch_get_effective_iam_policies( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "batch_get_effective_iam_policies" not in self._stubs: - self._stubs[ - "batch_get_effective_iam_policies" - ] = self._logged_channel.unary_unary( - "/google.cloud.asset.v1.AssetService/BatchGetEffectiveIamPolicies", - request_serializer=asset_service.BatchGetEffectiveIamPoliciesRequest.serialize, - response_deserializer=asset_service.BatchGetEffectiveIamPoliciesResponse.deserialize, + self._stubs["batch_get_effective_iam_policies"] = ( + self._logged_channel.unary_unary( + "/google.cloud.asset.v1.AssetService/BatchGetEffectiveIamPolicies", + request_serializer=asset_service.BatchGetEffectiveIamPoliciesRequest.serialize, + response_deserializer=asset_service.BatchGetEffectiveIamPoliciesResponse.deserialize, + ) ) return self._stubs["batch_get_effective_iam_policies"] @@ -1026,12 +1028,12 @@ def analyze_org_policy_governed_containers( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "analyze_org_policy_governed_containers" not in self._stubs: - self._stubs[ - "analyze_org_policy_governed_containers" - ] = self._logged_channel.unary_unary( - "/google.cloud.asset.v1.AssetService/AnalyzeOrgPolicyGovernedContainers", - request_serializer=asset_service.AnalyzeOrgPolicyGovernedContainersRequest.serialize, - response_deserializer=asset_service.AnalyzeOrgPolicyGovernedContainersResponse.deserialize, + self._stubs["analyze_org_policy_governed_containers"] = ( + self._logged_channel.unary_unary( + "/google.cloud.asset.v1.AssetService/AnalyzeOrgPolicyGovernedContainers", + request_serializer=asset_service.AnalyzeOrgPolicyGovernedContainersRequest.serialize, + response_deserializer=asset_service.AnalyzeOrgPolicyGovernedContainersResponse.deserialize, + ) ) return self._stubs["analyze_org_policy_governed_containers"] @@ -1076,12 +1078,12 @@ def analyze_org_policy_governed_assets( # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. if "analyze_org_policy_governed_assets" not in self._stubs: - self._stubs[ - "analyze_org_policy_governed_assets" - ] = self._logged_channel.unary_unary( - "/google.cloud.asset.v1.AssetService/AnalyzeOrgPolicyGovernedAssets", - request_serializer=asset_service.AnalyzeOrgPolicyGovernedAssetsRequest.serialize, - response_deserializer=asset_service.AnalyzeOrgPolicyGovernedAssetsResponse.deserialize, + self._stubs["analyze_org_policy_governed_assets"] = ( + self._logged_channel.unary_unary( + "/google.cloud.asset.v1.AssetService/AnalyzeOrgPolicyGovernedAssets", + request_serializer=asset_service.AnalyzeOrgPolicyGovernedAssetsRequest.serialize, + response_deserializer=asset_service.AnalyzeOrgPolicyGovernedAssetsResponse.deserialize, + ) ) return self._stubs["analyze_org_policy_governed_assets"] diff --git a/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/transports/rest.py b/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/transports/rest.py index f2c151a899..8f2c68ef7e 100755 --- a/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/transports/rest.py +++ b/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/transports/rest.py @@ -16,18 +16,20 @@ import dataclasses import json # type: ignore import logging -from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union import warnings +from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union -from google.api_core import gapic_v1, operations_v1, rest_helpers, rest_streaming +import google.protobuf from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1, operations_v1, rest_helpers, rest_streaming from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.requests import AuthorizedSession # type: ignore from google.longrunning import operations_pb2 # type: ignore -import google.protobuf -from google.protobuf import empty_pb2 # type: ignore -from google.protobuf import json_format +from google.protobuf import ( + empty_pb2, # type: ignore + json_format, +) from requests import __version__ as requests_version from google.cloud.asset_v1.types import asset_service @@ -1756,11 +1758,10 @@ def __call__( resp = self._interceptor.post_analyze_iam_policy_longrunning(resp) response_metadata = [(k, str(v)) for k, v in response.headers.items()] - ( - resp, - _, - ) = self._interceptor.post_analyze_iam_policy_longrunning_with_metadata( - resp, response_metadata + resp, _ = ( + self._interceptor.post_analyze_iam_policy_longrunning_with_metadata( + resp, response_metadata + ) ) if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( logging.DEBUG @@ -2152,11 +2153,10 @@ def __call__( _BaseAssetServiceRestTransport._BaseAnalyzeOrgPolicyGovernedAssets._get_http_options() ) - ( - request, - metadata, - ) = self._interceptor.pre_analyze_org_policy_governed_assets( - request, metadata + request, metadata = ( + self._interceptor.pre_analyze_org_policy_governed_assets( + request, metadata + ) ) transcoded_request = _BaseAssetServiceRestTransport._BaseAnalyzeOrgPolicyGovernedAssets._get_transcoded_request( http_options, request @@ -2219,11 +2219,10 @@ def __call__( resp = self._interceptor.post_analyze_org_policy_governed_assets(resp) response_metadata = [(k, str(v)) for k, v in response.headers.items()] - ( - resp, - _, - ) = self._interceptor.post_analyze_org_policy_governed_assets_with_metadata( - resp, response_metadata + resp, _ = ( + self._interceptor.post_analyze_org_policy_governed_assets_with_metadata( + resp, response_metadata + ) ) if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( logging.DEBUG @@ -2315,11 +2314,10 @@ def __call__( _BaseAssetServiceRestTransport._BaseAnalyzeOrgPolicyGovernedContainers._get_http_options() ) - ( - request, - metadata, - ) = self._interceptor.pre_analyze_org_policy_governed_containers( - request, metadata + request, metadata = ( + self._interceptor.pre_analyze_org_policy_governed_containers( + request, metadata + ) ) transcoded_request = _BaseAssetServiceRestTransport._BaseAnalyzeOrgPolicyGovernedContainers._get_transcoded_request( http_options, request @@ -2380,11 +2378,10 @@ def __call__( resp = self._interceptor.post_analyze_org_policy_governed_containers(resp) response_metadata = [(k, str(v)) for k, v in response.headers.items()] - ( - resp, - _, - ) = self._interceptor.post_analyze_org_policy_governed_containers_with_metadata( - resp, response_metadata + resp, _ = ( + self._interceptor.post_analyze_org_policy_governed_containers_with_metadata( + resp, response_metadata + ) ) if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( logging.DEBUG @@ -2686,11 +2683,10 @@ def __call__( resp = self._interceptor.post_batch_get_effective_iam_policies(resp) response_metadata = [(k, str(v)) for k, v in response.headers.items()] - ( - resp, - _, - ) = self._interceptor.post_batch_get_effective_iam_policies_with_metadata( - resp, response_metadata + resp, _ = ( + self._interceptor.post_batch_get_effective_iam_policies_with_metadata( + resp, response_metadata + ) ) if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( logging.DEBUG @@ -4946,7 +4942,9 @@ def analyze_iam_policy_longrunning( ]: # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. # In C++ this would require a dynamic_cast - return self._AnalyzeIamPolicyLongrunning(self._session, self._host, self._interceptor) # type: ignore + return self._AnalyzeIamPolicyLongrunning( + self._session, self._host, self._interceptor + ) # type: ignore @property def analyze_move( @@ -4978,7 +4976,9 @@ def analyze_org_policy_governed_assets( ]: # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. # In C++ this would require a dynamic_cast - return self._AnalyzeOrgPolicyGovernedAssets(self._session, self._host, self._interceptor) # type: ignore + return self._AnalyzeOrgPolicyGovernedAssets( + self._session, self._host, self._interceptor + ) # type: ignore @property def analyze_org_policy_governed_containers( @@ -4989,7 +4989,9 @@ def analyze_org_policy_governed_containers( ]: # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. # In C++ this would require a dynamic_cast - return self._AnalyzeOrgPolicyGovernedContainers(self._session, self._host, self._interceptor) # type: ignore + return self._AnalyzeOrgPolicyGovernedContainers( + self._session, self._host, self._interceptor + ) # type: ignore @property def batch_get_assets_history( @@ -5011,7 +5013,9 @@ def batch_get_effective_iam_policies( ]: # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. # In C++ this would require a dynamic_cast - return self._BatchGetEffectiveIamPolicies(self._session, self._host, self._interceptor) # type: ignore + return self._BatchGetEffectiveIamPolicies( + self._session, self._host, self._interceptor + ) # type: ignore @property def create_feed( diff --git a/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/transports/rest_base.py b/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/transports/rest_base.py index f8f831e0a9..4f99161a8e 100755 --- a/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/transports/rest_base.py +++ b/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/transports/rest_base.py @@ -19,8 +19,10 @@ from google.api_core import gapic_v1, path_template from google.longrunning import operations_pb2 # type: ignore -from google.protobuf import empty_pb2 # type: ignore -from google.protobuf import json_format +from google.protobuf import ( + empty_pb2, # type: ignore + json_format, +) from google.cloud.asset_v1.types import asset_service diff --git a/tests/integration/goldens/asset/google/cloud/asset_v1/types/asset_service.py b/tests/integration/goldens/asset/google/cloud/asset_v1/types/asset_service.py index caa108900b..82f268b176 100755 --- a/tests/integration/goldens/asset/google/cloud/asset_v1/types/asset_service.py +++ b/tests/integration/goldens/asset/google/cloud/asset_v1/types/asset_service.py @@ -17,11 +17,14 @@ from typing import MutableMapping, MutableSequence +import proto # type: ignore from google.iam.v1 import policy_pb2 # type: ignore -from google.protobuf import duration_pb2 # type: ignore -from google.protobuf import field_mask_pb2 # type: ignore -from google.protobuf import struct_pb2 # type: ignore -from google.protobuf import timestamp_pb2 # type: ignore +from google.protobuf import ( + duration_pb2, # type: ignore + field_mask_pb2, # type: ignore + struct_pb2, # type: ignore + timestamp_pb2, # type: ignore +) from google.rpc import status_pb2 # type: ignore from google.type import expr_pb2 # type: ignore import proto # type: ignore @@ -116,6 +119,7 @@ class ContentType(proto.Enum): RELATIONSHIP (7): The related resources. """ + CONTENT_TYPE_UNSPECIFIED = 0 RESOURCE = 1 IAM_POLICY = 2 @@ -910,6 +914,7 @@ class PartitionKey(proto.Enum): timestamp column representing when the request was received. """ + PARTITION_KEY_UNSPECIFIED = 0 READ_TIME = 1 REQUEST_TIME = 2 @@ -1863,23 +1868,23 @@ class IamPolicyAnalysis(proto.Message): number=1, message="IamPolicyAnalysisQuery", ) - analysis_results: MutableSequence[ - gca_assets.IamPolicyAnalysisResult - ] = proto.RepeatedField( - proto.MESSAGE, - number=2, - message=gca_assets.IamPolicyAnalysisResult, + analysis_results: MutableSequence[gca_assets.IamPolicyAnalysisResult] = ( + proto.RepeatedField( + proto.MESSAGE, + number=2, + message=gca_assets.IamPolicyAnalysisResult, + ) ) fully_explored: bool = proto.Field( proto.BOOL, number=3, ) - non_critical_errors: MutableSequence[ - gca_assets.IamPolicyAnalysisState - ] = proto.RepeatedField( - proto.MESSAGE, - number=5, - message=gca_assets.IamPolicyAnalysisState, + non_critical_errors: MutableSequence[gca_assets.IamPolicyAnalysisState] = ( + proto.RepeatedField( + proto.MESSAGE, + number=5, + message=gca_assets.IamPolicyAnalysisState, + ) ) main_analysis: IamPolicyAnalysis = proto.Field( @@ -1887,12 +1892,12 @@ class IamPolicyAnalysis(proto.Message): number=1, message=IamPolicyAnalysis, ) - service_account_impersonation_analysis: MutableSequence[ - IamPolicyAnalysis - ] = proto.RepeatedField( - proto.MESSAGE, - number=2, - message=IamPolicyAnalysis, + service_account_impersonation_analysis: MutableSequence[IamPolicyAnalysis] = ( + proto.RepeatedField( + proto.MESSAGE, + number=2, + message=IamPolicyAnalysis, + ) ) fully_explored: bool = proto.Field( proto.BOOL, @@ -2007,6 +2012,7 @@ class PartitionKey(proto.Enum): additional timestamp column representing when the request was received. """ + PARTITION_KEY_UNSPECIFIED = 0 REQUEST_TIME = 1 @@ -2423,6 +2429,7 @@ class AnalysisView(proto.Enum): will prevent the specified resource move at runtime. """ + ANALYSIS_VIEW_UNSPECIFIED = 0 FULL = 1 BASIC = 2 @@ -3270,6 +3277,7 @@ class ConstraintDefault(proto.Enum): constraints. Indicate that enforcement is on for boolean constraints. """ + CONSTRAINT_DEFAULT_UNSPECIFIED = 0 ALLOW = 1 DENY = 2 @@ -3396,6 +3404,7 @@ class MethodType(proto.Enum): Constraint applied when deleting the resource. """ + METHOD_TYPE_UNSPECIFIED = 0 CREATE = 1 UPDATE = 2 @@ -3412,6 +3421,7 @@ class ActionType(proto.Enum): DENY (2): Deny action type. """ + ACTION_TYPE_UNSPECIFIED = 0 ALLOW = 1 DENY = 2 diff --git a/tests/integration/goldens/asset/google/cloud/asset_v1/types/assets.py b/tests/integration/goldens/asset/google/cloud/asset_v1/types/assets.py index bbf535dfcb..c21043028b 100755 --- a/tests/integration/goldens/asset/google/cloud/asset_v1/types/assets.py +++ b/tests/integration/goldens/asset/google/cloud/asset_v1/types/assets.py @@ -17,18 +17,20 @@ from typing import MutableMapping, MutableSequence +import proto # type: ignore from google.cloud.orgpolicy.v1 import orgpolicy_pb2 # type: ignore from google.cloud.osconfig.v1 import inventory_pb2 # type: ignore from google.iam.v1 import policy_pb2 # type: ignore -from google.identity.accesscontextmanager.v1 import access_level_pb2 # type: ignore -from google.identity.accesscontextmanager.v1 import access_policy_pb2 # type: ignore from google.identity.accesscontextmanager.v1 import ( - service_perimeter_pb2, -) # type: ignore -from google.protobuf import struct_pb2 # type: ignore -from google.protobuf import timestamp_pb2 # type: ignore + access_level_pb2, # type: ignore + access_policy_pb2, # type: ignore + service_perimeter_pb2, # type: ignore +) +from google.protobuf import ( + struct_pb2, # type: ignore + timestamp_pb2, # type: ignore +) from google.rpc import code_pb2 # type: ignore -import proto # type: ignore __protobuf__ = proto.module( package="google.cloud.asset.v1", @@ -89,6 +91,7 @@ class PriorAssetState(proto.Enum): DELETED (4): prior_asset is a deletion. """ + PRIOR_ASSET_STATE_UNSPECIFIED = 0 PRESENT = 1 INVALID = 2 @@ -1238,6 +1241,7 @@ class EvaluationValue(proto.Enum): expression contains variables that are either missing input values or have not been supported by Analyzer yet. """ + EVALUATION_VALUE_UNSPECIFIED = 0 TRUE = 1 FALSE = 2 @@ -1441,26 +1445,26 @@ class AccessControlList(proto.Message): defined in the above IAM policy binding. """ - resources: MutableSequence[ - "IamPolicyAnalysisResult.Resource" - ] = proto.RepeatedField( - proto.MESSAGE, - number=1, - message="IamPolicyAnalysisResult.Resource", + resources: MutableSequence["IamPolicyAnalysisResult.Resource"] = ( + proto.RepeatedField( + proto.MESSAGE, + number=1, + message="IamPolicyAnalysisResult.Resource", + ) ) - accesses: MutableSequence[ - "IamPolicyAnalysisResult.Access" - ] = proto.RepeatedField( - proto.MESSAGE, - number=2, - message="IamPolicyAnalysisResult.Access", + accesses: MutableSequence["IamPolicyAnalysisResult.Access"] = ( + proto.RepeatedField( + proto.MESSAGE, + number=2, + message="IamPolicyAnalysisResult.Access", + ) ) - resource_edges: MutableSequence[ - "IamPolicyAnalysisResult.Edge" - ] = proto.RepeatedField( - proto.MESSAGE, - number=3, - message="IamPolicyAnalysisResult.Edge", + resource_edges: MutableSequence["IamPolicyAnalysisResult.Edge"] = ( + proto.RepeatedField( + proto.MESSAGE, + number=3, + message="IamPolicyAnalysisResult.Edge", + ) ) condition_evaluation: "ConditionEvaluation" = proto.Field( proto.MESSAGE, @@ -1493,19 +1497,19 @@ class IdentityList(proto.Message): enabled in request. """ - identities: MutableSequence[ - "IamPolicyAnalysisResult.Identity" - ] = proto.RepeatedField( - proto.MESSAGE, - number=1, - message="IamPolicyAnalysisResult.Identity", + identities: MutableSequence["IamPolicyAnalysisResult.Identity"] = ( + proto.RepeatedField( + proto.MESSAGE, + number=1, + message="IamPolicyAnalysisResult.Identity", + ) ) - group_edges: MutableSequence[ - "IamPolicyAnalysisResult.Edge" - ] = proto.RepeatedField( - proto.MESSAGE, - number=2, - message="IamPolicyAnalysisResult.Edge", + group_edges: MutableSequence["IamPolicyAnalysisResult.Edge"] = ( + proto.RepeatedField( + proto.MESSAGE, + number=2, + message="IamPolicyAnalysisResult.Edge", + ) ) attached_resource_full_name: str = proto.Field( diff --git a/tests/integration/goldens/asset/noxfile.py b/tests/integration/goldens/asset/noxfile.py index 396d6dd96e..7f67ea658c 100755 --- a/tests/integration/goldens/asset/noxfile.py +++ b/tests/integration/goldens/asset/noxfile.py @@ -17,8 +17,12 @@ import pathlib import re import shutil +<<<<<<< HEAD from typing import Dict, List +======= +>>>>>>> 5b735723 ( forma nox session with ruff) import warnings +from typing import Dict, List import nox @@ -159,7 +163,9 @@ def lint(session): @nox.session(python=DEFAULT_PYTHON_VERSION) def blacken(session): """(Deprecated) Legacy session. Please use 'nox -s format'.""" - session.log("WARNING: The 'blacken' session is deprecated and will be removed in the next release. Please use 'nox -s format' in the future.") + session.log( + "WARNING: The 'blacken' session is deprecated and will be removed in the next release. Please use 'nox -s format' in the future." + ) # Just run the ruff formatter (keeping legacy behavior of only formatting, not sorting imports) session.install(RUFF_VERSION) @@ -178,8 +184,10 @@ def format(session): # check --select I: Enables strict import sorting # --fix: Applies the changes automatically session.run( - "ruff", "check", - "--select", "I", + "ruff", + "check", + "--select", + "I", "--fix", "--line-length=88", # Standard Black line length *LINT_PATHS, @@ -187,7 +195,8 @@ def format(session): # 3. Run Ruff to format code session.run( - "ruff", "format", + "ruff", + "format", "--line-length=88", # Standard Black line length *LINT_PATHS, ) diff --git a/tests/integration/goldens/asset/tests/unit/gapic/asset_v1/test_asset_service.py b/tests/integration/goldens/asset/tests/unit/gapic/asset_v1/test_asset_service.py index 17bae13533..79c4bcd7a4 100755 --- a/tests/integration/goldens/asset/tests/unit/gapic/asset_v1/test_asset_service.py +++ b/tests/integration/goldens/asset/tests/unit/gapic/asset_v1/test_asset_service.py @@ -22,17 +22,17 @@ except ImportError: # pragma: NO COVER import mock -from collections.abc import AsyncIterable, Iterable import json import math +from collections.abc import AsyncIterable, Iterable +import grpc +import pytest from google.api_core import api_core_version from google.protobuf import json_format -import grpc from grpc.experimental import aio from proto.marshal.rules import wrappers from proto.marshal.rules.dates import DurationRule, TimestampRule -import pytest from requests import PreparedRequest, Request, Response from requests.sessions import Session @@ -43,27 +43,30 @@ except ImportError: # pragma: NO COVER HAS_GOOGLE_AUTH_AIO = False +import google.auth from google.api_core import ( + client_options, future, gapic_v1, grpc_helpers, grpc_helpers_async, operation, + operation_async, # type: ignore operations_v1, path_template, ) -from google.api_core import client_options from google.api_core import exceptions as core_exceptions -from google.api_core import operation_async # type: ignore from google.api_core import retry as retries import google.auth from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError from google.longrunning import operations_pb2 # type: ignore from google.oauth2 import service_account -from google.protobuf import duration_pb2 # type: ignore -from google.protobuf import field_mask_pb2 # type: ignore -from google.protobuf import timestamp_pb2 # type: ignore +from google.protobuf import ( + duration_pb2, # type: ignore + field_mask_pb2, # type: ignore + timestamp_pb2, # type: ignore +) from google.rpc import status_pb2 # type: ignore from google.type import expr_pb2 # type: ignore @@ -941,10 +944,9 @@ def test_asset_service_client_get_mtls_endpoint_and_cert_source(client_class): client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint, ) - ( - api_endpoint, - cert_source, - ) = client_class.get_mtls_endpoint_and_cert_source(options) + api_endpoint, cert_source = ( + client_class.get_mtls_endpoint_and_cert_source(options) + ) assert api_endpoint == mock_api_endpoint assert cert_source is expected_cert_source @@ -989,10 +991,9 @@ def test_asset_service_client_get_mtls_endpoint_and_cert_source(client_class): client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint, ) - ( - api_endpoint, - cert_source, - ) = client_class.get_mtls_endpoint_and_cert_source(options) + api_endpoint, cert_source = ( + client_class.get_mtls_endpoint_and_cert_source(options) + ) assert api_endpoint == mock_api_endpoint assert cert_source is expected_cert_source @@ -1028,10 +1029,9 @@ def test_asset_service_client_get_mtls_endpoint_and_cert_source(client_class): "google.auth.transport.mtls.default_client_cert_source", return_value=mock_client_cert_source, ): - ( - api_endpoint, - cert_source, - ) = client_class.get_mtls_endpoint_and_cert_source() + api_endpoint, cert_source = ( + client_class.get_mtls_endpoint_and_cert_source() + ) assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT assert cert_source == mock_client_cert_source @@ -1270,13 +1270,13 @@ def test_asset_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel" - ) as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4037,9 +4037,9 @@ def test_search_all_resources_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.search_all_resources - ] = mock_rpc + client._transport._wrapped_methods[client._transport.search_all_resources] = ( + mock_rpc + ) request = {} client.search_all_resources(request) @@ -5162,9 +5162,9 @@ def test_analyze_iam_policy_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.analyze_iam_policy - ] = mock_rpc + client._transport._wrapped_methods[client._transport.analyze_iam_policy] = ( + mock_rpc + ) request = {} client.analyze_iam_policy(request) @@ -6174,9 +6174,9 @@ def test_create_saved_query_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.create_saved_query - ] = mock_rpc + client._transport._wrapped_methods[client._transport.create_saved_query] = ( + mock_rpc + ) request = {} client.create_saved_query(request) @@ -6880,9 +6880,9 @@ def test_list_saved_queries_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.list_saved_queries - ] = mock_rpc + client._transport._wrapped_methods[client._transport.list_saved_queries] = ( + mock_rpc + ) request = {} client.list_saved_queries(request) @@ -7425,9 +7425,9 @@ def test_update_saved_query_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.update_saved_query - ] = mock_rpc + client._transport._wrapped_methods[client._transport.update_saved_query] = ( + mock_rpc + ) request = {} client.update_saved_query(request) @@ -7779,9 +7779,9 @@ def test_delete_saved_query_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.delete_saved_query - ] = mock_rpc + client._transport._wrapped_methods[client._transport.delete_saved_query] = ( + mock_rpc + ) request = {} client.delete_saved_query(request) @@ -8368,9 +8368,9 @@ def test_analyze_org_policies_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.analyze_org_policies - ] = mock_rpc + client._transport._wrapped_methods[client._transport.analyze_org_policies] = ( + mock_rpc + ) request = {} client.analyze_org_policies(request) @@ -11453,9 +11453,9 @@ def test_search_all_resources_rest_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.search_all_resources - ] = mock_rpc + client._transport._wrapped_methods[client._transport.search_all_resources] = ( + mock_rpc + ) request = {} client.search_all_resources(request) @@ -11990,9 +11990,9 @@ def test_analyze_iam_policy_rest_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.analyze_iam_policy - ] = mock_rpc + client._transport._wrapped_methods[client._transport.analyze_iam_policy] = ( + mock_rpc + ) request = {} client.analyze_iam_policy(request) @@ -12531,9 +12531,9 @@ def test_create_saved_query_rest_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.create_saved_query - ] = mock_rpc + client._transport._wrapped_methods[client._transport.create_saved_query] = ( + mock_rpc + ) request = {} client.create_saved_query(request) @@ -12915,9 +12915,9 @@ def test_list_saved_queries_rest_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.list_saved_queries - ] = mock_rpc + client._transport._wrapped_methods[client._transport.list_saved_queries] = ( + mock_rpc + ) request = {} client.list_saved_queries(request) @@ -13175,9 +13175,9 @@ def test_update_saved_query_rest_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.update_saved_query - ] = mock_rpc + client._transport._wrapped_methods[client._transport.update_saved_query] = ( + mock_rpc + ) request = {} client.update_saved_query(request) @@ -13366,9 +13366,9 @@ def test_delete_saved_query_rest_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.delete_saved_query - ] = mock_rpc + client._transport._wrapped_methods[client._transport.delete_saved_query] = ( + mock_rpc + ) request = {} client.delete_saved_query(request) @@ -13692,9 +13692,9 @@ def test_analyze_org_policies_rest_use_cached_wrapped_rpc(): mock_rpc.return_value.name = ( "foo" # operation_request.operation in compute client(s) expect a string. ) - client._transport._wrapped_methods[ - client._transport.analyze_org_policies - ] = mock_rpc + client._transport._wrapped_methods[client._transport.analyze_org_policies] = ( + mock_rpc + ) request = {} client.analyze_org_policies(request) @@ -15857,8 +15857,9 @@ def test_export_assets_rest_bad_request(request_type=asset_service.ExportAssetsR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15915,19 +15916,20 @@ def test_export_assets_rest_interceptors(null_interceptor): ) client = AssetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AssetServiceRestInterceptor, "post_export_assets" - ) as post, mock.patch.object( - transports.AssetServiceRestInterceptor, "post_export_assets_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AssetServiceRestInterceptor, "pre_export_assets" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AssetServiceRestInterceptor, "post_export_assets" + ) as post, + mock.patch.object( + transports.AssetServiceRestInterceptor, "post_export_assets_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AssetServiceRestInterceptor, "pre_export_assets" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15978,8 +15980,9 @@ def test_list_assets_rest_bad_request(request_type=asset_service.ListAssetsReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16042,17 +16045,19 @@ def test_list_assets_rest_interceptors(null_interceptor): ) client = AssetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AssetServiceRestInterceptor, "post_list_assets" - ) as post, mock.patch.object( - transports.AssetServiceRestInterceptor, "post_list_assets_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AssetServiceRestInterceptor, "pre_list_assets" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AssetServiceRestInterceptor, "post_list_assets" + ) as post, + mock.patch.object( + transports.AssetServiceRestInterceptor, "post_list_assets_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AssetServiceRestInterceptor, "pre_list_assets" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16107,8 +16112,9 @@ def test_batch_get_assets_history_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16168,18 +16174,20 @@ def test_batch_get_assets_history_rest_interceptors(null_interceptor): ) client = AssetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AssetServiceRestInterceptor, "post_batch_get_assets_history" - ) as post, mock.patch.object( - transports.AssetServiceRestInterceptor, - "post_batch_get_assets_history_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AssetServiceRestInterceptor, "pre_batch_get_assets_history" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AssetServiceRestInterceptor, "post_batch_get_assets_history" + ) as post, + mock.patch.object( + transports.AssetServiceRestInterceptor, + "post_batch_get_assets_history_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AssetServiceRestInterceptor, "pre_batch_get_assets_history" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16235,8 +16243,9 @@ def test_create_feed_rest_bad_request(request_type=asset_service.CreateFeedReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16307,17 +16316,19 @@ def test_create_feed_rest_interceptors(null_interceptor): ) client = AssetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AssetServiceRestInterceptor, "post_create_feed" - ) as post, mock.patch.object( - transports.AssetServiceRestInterceptor, "post_create_feed_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AssetServiceRestInterceptor, "pre_create_feed" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AssetServiceRestInterceptor, "post_create_feed" + ) as post, + mock.patch.object( + transports.AssetServiceRestInterceptor, "post_create_feed_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AssetServiceRestInterceptor, "pre_create_feed" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16368,8 +16379,9 @@ def test_get_feed_rest_bad_request(request_type=asset_service.GetFeedRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16440,17 +16452,19 @@ def test_get_feed_rest_interceptors(null_interceptor): ) client = AssetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AssetServiceRestInterceptor, "post_get_feed" - ) as post, mock.patch.object( - transports.AssetServiceRestInterceptor, "post_get_feed_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AssetServiceRestInterceptor, "pre_get_feed" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AssetServiceRestInterceptor, "post_get_feed" + ) as post, + mock.patch.object( + transports.AssetServiceRestInterceptor, "post_get_feed_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AssetServiceRestInterceptor, "pre_get_feed" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16499,8 +16513,9 @@ def test_list_feeds_rest_bad_request(request_type=asset_service.ListFeedsRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16560,17 +16575,19 @@ def test_list_feeds_rest_interceptors(null_interceptor): ) client = AssetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AssetServiceRestInterceptor, "post_list_feeds" - ) as post, mock.patch.object( - transports.AssetServiceRestInterceptor, "post_list_feeds_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AssetServiceRestInterceptor, "pre_list_feeds" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AssetServiceRestInterceptor, "post_list_feeds" + ) as post, + mock.patch.object( + transports.AssetServiceRestInterceptor, "post_list_feeds_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AssetServiceRestInterceptor, "pre_list_feeds" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16621,8 +16638,9 @@ def test_update_feed_rest_bad_request(request_type=asset_service.UpdateFeedReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16693,17 +16711,19 @@ def test_update_feed_rest_interceptors(null_interceptor): ) client = AssetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AssetServiceRestInterceptor, "post_update_feed" - ) as post, mock.patch.object( - transports.AssetServiceRestInterceptor, "post_update_feed_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AssetServiceRestInterceptor, "pre_update_feed" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AssetServiceRestInterceptor, "post_update_feed" + ) as post, + mock.patch.object( + transports.AssetServiceRestInterceptor, "post_update_feed_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AssetServiceRestInterceptor, "pre_update_feed" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16754,8 +16774,9 @@ def test_delete_feed_rest_bad_request(request_type=asset_service.DeleteFeedReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16812,13 +16833,13 @@ def test_delete_feed_rest_interceptors(null_interceptor): ) client = AssetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AssetServiceRestInterceptor, "pre_delete_feed" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AssetServiceRestInterceptor, "pre_delete_feed" + ) as pre, + ): pre.assert_not_called() pb_message = asset_service.DeleteFeedRequest.pb( asset_service.DeleteFeedRequest() @@ -16863,8 +16884,9 @@ def test_search_all_resources_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16927,18 +16949,20 @@ def test_search_all_resources_rest_interceptors(null_interceptor): ) client = AssetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AssetServiceRestInterceptor, "post_search_all_resources" - ) as post, mock.patch.object( - transports.AssetServiceRestInterceptor, - "post_search_all_resources_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AssetServiceRestInterceptor, "pre_search_all_resources" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AssetServiceRestInterceptor, "post_search_all_resources" + ) as post, + mock.patch.object( + transports.AssetServiceRestInterceptor, + "post_search_all_resources_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AssetServiceRestInterceptor, "pre_search_all_resources" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16996,8 +17020,9 @@ def test_search_all_iam_policies_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17060,18 +17085,20 @@ def test_search_all_iam_policies_rest_interceptors(null_interceptor): ) client = AssetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AssetServiceRestInterceptor, "post_search_all_iam_policies" - ) as post, mock.patch.object( - transports.AssetServiceRestInterceptor, - "post_search_all_iam_policies_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AssetServiceRestInterceptor, "pre_search_all_iam_policies" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AssetServiceRestInterceptor, "post_search_all_iam_policies" + ) as post, + mock.patch.object( + transports.AssetServiceRestInterceptor, + "post_search_all_iam_policies_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AssetServiceRestInterceptor, "pre_search_all_iam_policies" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -17129,8 +17156,9 @@ def test_analyze_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17193,17 +17221,20 @@ def test_analyze_iam_policy_rest_interceptors(null_interceptor): ) client = AssetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AssetServiceRestInterceptor, "post_analyze_iam_policy" - ) as post, mock.patch.object( - transports.AssetServiceRestInterceptor, "post_analyze_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AssetServiceRestInterceptor, "pre_analyze_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AssetServiceRestInterceptor, "post_analyze_iam_policy" + ) as post, + mock.patch.object( + transports.AssetServiceRestInterceptor, + "post_analyze_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AssetServiceRestInterceptor, "pre_analyze_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -17261,8 +17292,9 @@ def test_analyze_iam_policy_longrunning_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17319,20 +17351,22 @@ def test_analyze_iam_policy_longrunning_rest_interceptors(null_interceptor): ) client = AssetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AssetServiceRestInterceptor, "post_analyze_iam_policy_longrunning" - ) as post, mock.patch.object( - transports.AssetServiceRestInterceptor, - "post_analyze_iam_policy_longrunning_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AssetServiceRestInterceptor, "pre_analyze_iam_policy_longrunning" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AssetServiceRestInterceptor, + "post_analyze_iam_policy_longrunning", + ) as post, + mock.patch.object( + transports.AssetServiceRestInterceptor, + "post_analyze_iam_policy_longrunning_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AssetServiceRestInterceptor, "pre_analyze_iam_policy_longrunning" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -17383,8 +17417,9 @@ def test_analyze_move_rest_bad_request(request_type=asset_service.AnalyzeMoveReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17444,17 +17479,19 @@ def test_analyze_move_rest_interceptors(null_interceptor): ) client = AssetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AssetServiceRestInterceptor, "post_analyze_move" - ) as post, mock.patch.object( - transports.AssetServiceRestInterceptor, "post_analyze_move_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AssetServiceRestInterceptor, "pre_analyze_move" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AssetServiceRestInterceptor, "post_analyze_move" + ) as post, + mock.patch.object( + transports.AssetServiceRestInterceptor, "post_analyze_move_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AssetServiceRestInterceptor, "pre_analyze_move" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -17507,8 +17544,9 @@ def test_query_assets_rest_bad_request(request_type=asset_service.QueryAssetsReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17573,17 +17611,19 @@ def test_query_assets_rest_interceptors(null_interceptor): ) client = AssetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AssetServiceRestInterceptor, "post_query_assets" - ) as post, mock.patch.object( - transports.AssetServiceRestInterceptor, "post_query_assets_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AssetServiceRestInterceptor, "pre_query_assets" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AssetServiceRestInterceptor, "post_query_assets" + ) as post, + mock.patch.object( + transports.AssetServiceRestInterceptor, "post_query_assets_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AssetServiceRestInterceptor, "pre_query_assets" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -17638,8 +17678,9 @@ def test_create_saved_query_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17804,17 +17845,20 @@ def test_create_saved_query_rest_interceptors(null_interceptor): ) client = AssetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AssetServiceRestInterceptor, "post_create_saved_query" - ) as post, mock.patch.object( - transports.AssetServiceRestInterceptor, "post_create_saved_query_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AssetServiceRestInterceptor, "pre_create_saved_query" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AssetServiceRestInterceptor, "post_create_saved_query" + ) as post, + mock.patch.object( + transports.AssetServiceRestInterceptor, + "post_create_saved_query_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AssetServiceRestInterceptor, "pre_create_saved_query" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -17867,8 +17911,9 @@ def test_get_saved_query_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17937,17 +17982,19 @@ def test_get_saved_query_rest_interceptors(null_interceptor): ) client = AssetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AssetServiceRestInterceptor, "post_get_saved_query" - ) as post, mock.patch.object( - transports.AssetServiceRestInterceptor, "post_get_saved_query_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AssetServiceRestInterceptor, "pre_get_saved_query" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AssetServiceRestInterceptor, "post_get_saved_query" + ) as post, + mock.patch.object( + transports.AssetServiceRestInterceptor, "post_get_saved_query_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AssetServiceRestInterceptor, "pre_get_saved_query" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -18000,8 +18047,9 @@ def test_list_saved_queries_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -18064,17 +18112,20 @@ def test_list_saved_queries_rest_interceptors(null_interceptor): ) client = AssetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AssetServiceRestInterceptor, "post_list_saved_queries" - ) as post, mock.patch.object( - transports.AssetServiceRestInterceptor, "post_list_saved_queries_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AssetServiceRestInterceptor, "pre_list_saved_queries" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AssetServiceRestInterceptor, "post_list_saved_queries" + ) as post, + mock.patch.object( + transports.AssetServiceRestInterceptor, + "post_list_saved_queries_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AssetServiceRestInterceptor, "pre_list_saved_queries" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -18132,8 +18183,9 @@ def test_update_saved_query_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -18298,17 +18350,20 @@ def test_update_saved_query_rest_interceptors(null_interceptor): ) client = AssetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AssetServiceRestInterceptor, "post_update_saved_query" - ) as post, mock.patch.object( - transports.AssetServiceRestInterceptor, "post_update_saved_query_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AssetServiceRestInterceptor, "pre_update_saved_query" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AssetServiceRestInterceptor, "post_update_saved_query" + ) as post, + mock.patch.object( + transports.AssetServiceRestInterceptor, + "post_update_saved_query_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AssetServiceRestInterceptor, "pre_update_saved_query" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -18361,8 +18416,9 @@ def test_delete_saved_query_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -18419,13 +18475,13 @@ def test_delete_saved_query_rest_interceptors(null_interceptor): ) client = AssetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AssetServiceRestInterceptor, "pre_delete_saved_query" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AssetServiceRestInterceptor, "pre_delete_saved_query" + ) as pre, + ): pre.assert_not_called() pb_message = asset_service.DeleteSavedQueryRequest.pb( asset_service.DeleteSavedQueryRequest() @@ -18470,8 +18526,9 @@ def test_batch_get_effective_iam_policies_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -18533,18 +18590,22 @@ def test_batch_get_effective_iam_policies_rest_interceptors(null_interceptor): ) client = AssetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AssetServiceRestInterceptor, "post_batch_get_effective_iam_policies" - ) as post, mock.patch.object( - transports.AssetServiceRestInterceptor, - "post_batch_get_effective_iam_policies_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AssetServiceRestInterceptor, "pre_batch_get_effective_iam_policies" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AssetServiceRestInterceptor, + "post_batch_get_effective_iam_policies", + ) as post, + mock.patch.object( + transports.AssetServiceRestInterceptor, + "post_batch_get_effective_iam_policies_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AssetServiceRestInterceptor, + "pre_batch_get_effective_iam_policies", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -18602,8 +18663,9 @@ def test_analyze_org_policies_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -18666,18 +18728,20 @@ def test_analyze_org_policies_rest_interceptors(null_interceptor): ) client = AssetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AssetServiceRestInterceptor, "post_analyze_org_policies" - ) as post, mock.patch.object( - transports.AssetServiceRestInterceptor, - "post_analyze_org_policies_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AssetServiceRestInterceptor, "pre_analyze_org_policies" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AssetServiceRestInterceptor, "post_analyze_org_policies" + ) as post, + mock.patch.object( + transports.AssetServiceRestInterceptor, + "post_analyze_org_policies_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AssetServiceRestInterceptor, "pre_analyze_org_policies" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -18735,8 +18799,9 @@ def test_analyze_org_policy_governed_containers_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -18801,20 +18866,22 @@ def test_analyze_org_policy_governed_containers_rest_interceptors(null_intercept ) client = AssetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AssetServiceRestInterceptor, - "post_analyze_org_policy_governed_containers", - ) as post, mock.patch.object( - transports.AssetServiceRestInterceptor, - "post_analyze_org_policy_governed_containers_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AssetServiceRestInterceptor, - "pre_analyze_org_policy_governed_containers", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AssetServiceRestInterceptor, + "post_analyze_org_policy_governed_containers", + ) as post, + mock.patch.object( + transports.AssetServiceRestInterceptor, + "post_analyze_org_policy_governed_containers_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AssetServiceRestInterceptor, + "pre_analyze_org_policy_governed_containers", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -18872,8 +18939,9 @@ def test_analyze_org_policy_governed_assets_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -18938,19 +19006,22 @@ def test_analyze_org_policy_governed_assets_rest_interceptors(null_interceptor): ) client = AssetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AssetServiceRestInterceptor, - "post_analyze_org_policy_governed_assets", - ) as post, mock.patch.object( - transports.AssetServiceRestInterceptor, - "post_analyze_org_policy_governed_assets_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AssetServiceRestInterceptor, "pre_analyze_org_policy_governed_assets" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AssetServiceRestInterceptor, + "post_analyze_org_policy_governed_assets", + ) as post, + mock.patch.object( + transports.AssetServiceRestInterceptor, + "post_analyze_org_policy_governed_assets_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AssetServiceRestInterceptor, + "pre_analyze_org_policy_governed_assets", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -19010,8 +19081,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -19650,11 +19722,14 @@ def test_asset_service_base_transport(): def test_asset_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.asset_v1.services.asset_service.transports.AssetServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.asset_v1.services.asset_service.transports.AssetServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AssetServiceTransport( @@ -19671,9 +19746,12 @@ def test_asset_service_base_transport_with_credentials_file(): def test_asset_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.asset_v1.services.asset_service.transports.AssetServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.asset_v1.services.asset_service.transports.AssetServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AssetServiceTransport() @@ -19745,11 +19823,12 @@ def test_asset_service_transport_auth_gdch_credentials(transport_class): def test_asset_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"])