From b4dc5a9f4294852320438cbd2c0fa23cf3e11399 Mon Sep 17 00:00:00 2001 From: Christopher Wilcox Date: Wed, 28 Nov 2018 14:28:56 -0800 Subject: [PATCH] Run Black on Generated libraries (#6666) * blacken appveyor * Blacken all gen'd libraries not under PR --- packages/google-cloud-language/docs/conf.py | 173 +++++----- .../google-cloud-language/google/__init__.py | 2 + .../google/cloud/__init__.py | 2 + .../google/cloud/language.py | 6 +- .../google/cloud/language_v1/__init__.py | 5 +- .../google/cloud/language_v1/gapic/enums.py | 17 + .../gapic/language_service_client.py | 293 ++++++++--------- .../gapic/language_service_client_config.py | 20 +- .../language_service_grpc_transport.py | 44 ++- .../google/cloud/language_v1/types.py | 11 +- .../google/cloud/language_v1beta2/__init__.py | 5 +- .../cloud/language_v1beta2/gapic/enums.py | 17 + .../gapic/language_service_client.py | 297 +++++++++--------- .../gapic/language_service_client_config.py | 20 +- .../language_service_grpc_transport.py | 44 ++- .../google/cloud/language_v1beta2/types.py | 6 +- .../v1/test_system_language_service_v1.py | 4 +- .../test_system_language_service_v1beta2.py | 4 +- .../v1/test_language_service_client_v1.py | 85 ++--- .../test_language_service_client_v1beta2.py | 85 ++--- 20 files changed, 596 insertions(+), 544 deletions(-) diff --git a/packages/google-cloud-language/docs/conf.py b/packages/google-cloud-language/docs/conf.py index ad6af1f51564..1058e654d041 100644 --- a/packages/google-cloud-language/docs/conf.py +++ b/packages/google-cloud-language/docs/conf.py @@ -18,57 +18,55 @@ # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. -sys.path.insert(0, os.path.abspath('..')) +sys.path.insert(0, os.path.abspath("..")) -__version__ = '0.90.4' +__version__ = "0.90.4" # -- General configuration ------------------------------------------------ # If your documentation needs a minimal Sphinx version, state it here. -#needs_sphinx = '1.0' +# needs_sphinx = '1.0' # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. extensions = [ - 'sphinx.ext.autodoc', - 'sphinx.ext.autosummary', - 'sphinx.ext.doctest', - 'sphinx.ext.intersphinx', - 'sphinx.ext.coverage', - 'sphinx.ext.napoleon', - 'sphinx.ext.viewcode', + "sphinx.ext.autodoc", + "sphinx.ext.autosummary", + "sphinx.ext.doctest", + "sphinx.ext.intersphinx", + "sphinx.ext.coverage", + "sphinx.ext.napoleon", + "sphinx.ext.viewcode", ] # autodoc/autosummary flags -autoclass_content = 'both' -autodoc_default_flags = ['members'] +autoclass_content = "both" +autodoc_default_flags = ["members"] autosummary_generate = True # Add any paths that contain templates here, relative to this directory. -templates_path = ['_templates'] +templates_path = ["_templates"] # Allow markdown includes (so releases.md can include CHANGLEOG.md) # http://www.sphinx-doc.org/en/master/markdown.html -source_parsers = { - '.md': 'recommonmark.parser.CommonMarkParser', -} +source_parsers = {".md": "recommonmark.parser.CommonMarkParser"} # The suffix(es) of source filenames. # You can specify multiple suffix as a list of string: # source_suffix = ['.rst', '.md'] -source_suffix = '.rst' +source_suffix = ".rst" # The encoding of source files. -#source_encoding = 'utf-8-sig' +# source_encoding = 'utf-8-sig' # The master toctree document. -master_doc = 'index' +master_doc = "index" # General information about the project. -project = u'google-cloud-language' -copyright = u'2017, Google' -author = u'Google APIs' +project = u"google-cloud-language" +copyright = u"2017, Google" +author = u"Google APIs" # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the @@ -77,7 +75,7 @@ # The full version, including alpha/beta/rc tags. release = __version__ # The short X.Y version. -version = '.'.join(release.split('.')[0:2]) +version = ".".join(release.split(".")[0:2]) # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. @@ -88,37 +86,37 @@ # There are two options for replacing |today|: either, you set today to some # non-false value, then it is used: -#today = '' +# today = '' # Else, today_fmt is used as the format for a strftime call. -#today_fmt = '%B %d, %Y' +# today_fmt = '%B %d, %Y' # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. -exclude_patterns = ['_build'] +exclude_patterns = ["_build"] # The reST default role (used for this markup: `text`) to use for all # documents. -#default_role = None +# default_role = None # If true, '()' will be appended to :func: etc. cross-reference text. -#add_function_parentheses = True +# add_function_parentheses = True # If true, the current module name will be prepended to all description # unit titles (such as .. function::). -#add_module_names = True +# add_module_names = True # If true, sectionauthor and moduleauthor directives will be shown in the # output. They are ignored by default. -#show_authors = False +# show_authors = False # The name of the Pygments (syntax highlighting) style to use. -pygments_style = 'sphinx' +pygments_style = "sphinx" # A list of ignored prefixes for module index sorting. -#modindex_common_prefix = [] +# modindex_common_prefix = [] # If true, keep warnings as "system message" paragraphs in the built documents. -#keep_warnings = False +# keep_warnings = False # If true, `todo` and `todoList` produce output, else they produce nothing. todo_include_todos = True @@ -127,31 +125,31 @@ # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. -html_theme = 'alabaster' +html_theme = "alabaster" # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the # documentation. -#html_theme_options = {} +# html_theme_options = {} # Add any paths that contain custom themes here, relative to this directory. -#html_theme_path = [] +# html_theme_path = [] # The name for this set of Sphinx documents. If None, it defaults to # " v documentation". -#html_title = None +# html_title = None # A shorter title for the navigation bar. Default is the same as html_title. -#html_short_title = None +# html_short_title = None # The name of an image file (relative to this directory) to place at the top # of the sidebar. -#html_logo = None +# html_logo = None # The name of an image file (within the static path) to use as favicon of the # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 # pixels large. -#html_favicon = None +# html_favicon = None # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, @@ -161,78 +159,75 @@ # Add any extra paths that contain custom files (such as robots.txt or # .htaccess) here, relative to this directory. These files are copied # directly to the root of the documentation. -#html_extra_path = [] +# html_extra_path = [] # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, # using the given strftime format. -#html_last_updated_fmt = '%b %d, %Y' +# html_last_updated_fmt = '%b %d, %Y' # If true, SmartyPants will be used to convert quotes and dashes to # typographically correct entities. -#html_use_smartypants = True +# html_use_smartypants = True # Custom sidebar templates, maps document names to template names. -#html_sidebars = {} +# html_sidebars = {} # Additional templates that should be rendered to pages, maps page names to # template names. -#html_additional_pages = {} +# html_additional_pages = {} # If false, no module index is generated. -#html_domain_indices = True +# html_domain_indices = True # If false, no index is generated. -#html_use_index = True +# html_use_index = True # If true, the index is split into individual pages for each letter. -#html_split_index = False +# html_split_index = False # If true, links to the reST sources are added to the pages. -#html_show_sourcelink = True +# html_show_sourcelink = True # If true, "Created using Sphinx" is shown in the HTML footer. Default is True. -#html_show_sphinx = True +# html_show_sphinx = True # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. -#html_show_copyright = True +# html_show_copyright = True # If true, an OpenSearch description file will be output, and all pages will # contain a tag referring to it. The value of this option must be the # base URL from which the finished HTML is served. -#html_use_opensearch = '' +# html_use_opensearch = '' # This is the file name suffix for HTML files (e.g. ".xhtml"). -#html_file_suffix = None +# html_file_suffix = None # Language to be used for generating the HTML full-text search index. # Sphinx supports the following languages: # 'da', 'de', 'en', 'es', 'fi', 'fr', 'hu', 'it', 'ja' # 'nl', 'no', 'pt', 'ro', 'ru', 'sv', 'tr' -#html_search_language = 'en' +# html_search_language = 'en' # A dictionary with options for the search language support, empty by default. # Now only 'ja' uses this config value -#html_search_options = {'type': 'default'} +# html_search_options = {'type': 'default'} # The name of a javascript file (relative to the configuration directory) that # implements a search results scorer. If empty, the default will be used. -#html_search_scorer = 'scorer.js' +# html_search_scorer = 'scorer.js' # Output file base name for HTML help builder. -htmlhelp_basename = 'google-cloud-language-doc' +htmlhelp_basename = "google-cloud-language-doc" # -- Options for LaTeX output --------------------------------------------- latex_elements = { # The paper size ('letterpaper' or 'a4paper'). #'papersize': 'letterpaper', - # The font size ('10pt', '11pt' or '12pt'). #'pointsize': '10pt', - # Additional stuff for the LaTeX preamble. #'preamble': '', - # Latex figure (float) alignment #'figure_align': 'htbp', } @@ -241,39 +236,51 @@ # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). latex_documents = [ - (master_doc, 'google-cloud-language.tex', - u'google-cloud-language Documentation', author, 'manual'), + ( + master_doc, + "google-cloud-language.tex", + u"google-cloud-language Documentation", + author, + "manual", + ) ] # The name of an image file (relative to this directory) to place at the top of # the title page. -#latex_logo = None +# latex_logo = None # For "manual" documents, if this is true, then toplevel headings are parts, # not chapters. -#latex_use_parts = False +# latex_use_parts = False # If true, show page references after internal links. -#latex_show_pagerefs = False +# latex_show_pagerefs = False # If true, show URL addresses after external links. -#latex_show_urls = False +# latex_show_urls = False # Documents to append as an appendix to all manuals. -#latex_appendices = [] +# latex_appendices = [] # If false, no module index is generated. -#latex_domain_indices = True +# latex_domain_indices = True # -- Options for manual page output --------------------------------------- # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). -man_pages = [(master_doc, 'google-cloud-language', - u'google-cloud-language Documentation', [author], 1)] +man_pages = [ + ( + master_doc, + "google-cloud-language", + u"google-cloud-language Documentation", + [author], + 1, + ) +] # If true, show URL addresses after external links. -#man_show_urls = False +# man_show_urls = False # -- Options for Texinfo output ------------------------------------------- @@ -281,27 +288,33 @@ # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ - (master_doc, 'google-cloud-language', - u'google-cloud-language Documentation', author, 'google-cloud-language', - 'GAPIC library for the {metadata.shortName} v1 service', 'APIs'), + ( + master_doc, + "google-cloud-language", + u"google-cloud-language Documentation", + author, + "google-cloud-language", + "GAPIC library for the {metadata.shortName} v1 service", + "APIs", + ) ] # Documents to append as an appendix to all manuals. -#texinfo_appendices = [] +# texinfo_appendices = [] # If false, no module index is generated. -#texinfo_domain_indices = True +# texinfo_domain_indices = True # How to display URL addresses: 'footnote', 'no', or 'inline'. -#texinfo_show_urls = 'footnote' +# texinfo_show_urls = 'footnote' # If true, do not generate a @detailmenu in the "Top" node's menu. -#texinfo_no_detailmenu = False +# texinfo_no_detailmenu = False # Example configuration for intersphinx: refer to the Python standard library. intersphinx_mapping = { - 'python': ('http://python.readthedocs.org/en/latest/', None), - 'gax': ('https://gax-python.readthedocs.org/en/latest/', None), + "python": ("http://python.readthedocs.org/en/latest/", None), + "gax": ("https://gax-python.readthedocs.org/en/latest/", None), } # Napoleon settings diff --git a/packages/google-cloud-language/google/__init__.py b/packages/google-cloud-language/google/__init__.py index 9ee9bf4342ab..0e1bc5131ba6 100644 --- a/packages/google-cloud-language/google/__init__.py +++ b/packages/google-cloud-language/google/__init__.py @@ -14,7 +14,9 @@ try: import pkg_resources + pkg_resources.declare_namespace(__name__) except ImportError: import pkgutil + __path__ = pkgutil.extend_path(__path__, __name__) diff --git a/packages/google-cloud-language/google/cloud/__init__.py b/packages/google-cloud-language/google/cloud/__init__.py index 9ee9bf4342ab..0e1bc5131ba6 100644 --- a/packages/google-cloud-language/google/cloud/__init__.py +++ b/packages/google-cloud-language/google/cloud/__init__.py @@ -14,7 +14,9 @@ try: import pkg_resources + pkg_resources.declare_namespace(__name__) except ImportError: import pkgutil + __path__ = pkgutil.extend_path(__path__, __name__) diff --git a/packages/google-cloud-language/google/cloud/language.py b/packages/google-cloud-language/google/cloud/language.py index f66b7d1f94d8..624bd1194391 100644 --- a/packages/google-cloud-language/google/cloud/language.py +++ b/packages/google-cloud-language/google/cloud/language.py @@ -18,8 +18,4 @@ from google.cloud.language_v1 import enums from google.cloud.language_v1 import types -__all__ = ( - 'enums', - 'types', - 'LanguageServiceClient', -) +__all__ = ("enums", "types", "LanguageServiceClient") diff --git a/packages/google-cloud-language/google/cloud/language_v1/__init__.py b/packages/google-cloud-language/google/cloud/language_v1/__init__.py index 25ac70d64bcc..a44fe4c98d6c 100644 --- a/packages/google-cloud-language/google/cloud/language_v1/__init__.py +++ b/packages/google-cloud-language/google/cloud/language_v1/__init__.py @@ -24,7 +24,4 @@ class LanguageServiceClient(language_service_client.LanguageServiceClient): enums = enums -__all__ = ( - 'enums', - 'types', - 'LanguageServiceClient', ) +__all__ = ("enums", "types", "LanguageServiceClient") diff --git a/packages/google-cloud-language/google/cloud/language_v1/gapic/enums.py b/packages/google-cloud-language/google/cloud/language_v1/gapic/enums.py index dcd23c41470c..1845f221979c 100644 --- a/packages/google-cloud-language/google/cloud/language_v1/gapic/enums.py +++ b/packages/google-cloud-language/google/cloud/language_v1/gapic/enums.py @@ -39,6 +39,7 @@ class EncodingType(enum.IntEnum): based on the UTF-32 encoding of the input. Python is an example of a language that uses this encoding natively. """ + NONE = 0 UTF8 = 1 UTF16 = 2 @@ -55,6 +56,7 @@ class Type(enum.IntEnum): PLAIN_TEXT (int): Plain text HTML (int): HTML """ + TYPE_UNSPECIFIED = 0 PLAIN_TEXT = 1 HTML = 2 @@ -75,6 +77,7 @@ class Type(enum.IntEnum): CONSUMER_GOOD (int): Consumer goods OTHER (int): Other types """ + UNKNOWN = 0 PERSON = 1 LOCATION = 2 @@ -106,6 +109,7 @@ class Tag(enum.IntEnum): X (int): Other: foreign words, typos, abbreviations AFFIX (int): Affix """ + UNKNOWN = 0 ADJ = 1 ADP = 2 @@ -131,6 +135,7 @@ class Aspect(enum.IntEnum): IMPERFECTIVE (int): Imperfective PROGRESSIVE (int): Progressive """ + ASPECT_UNKNOWN = 0 PERFECTIVE = 1 IMPERFECTIVE = 2 @@ -159,6 +164,7 @@ class Case(enum.IntEnum): RELATIVE_CASE (int): Relative VOCATIVE (int): Vocative """ + CASE_UNKNOWN = 0 ACCUSATIVE = 1 ADVERBIAL = 2 @@ -196,6 +202,7 @@ class Form(enum.IntEnum): ORDER (int): Order form SPECIFIC (int): Specific form """ + FORM_UNKNOWN = 0 ADNOMIAL = 1 AUXILIARY = 2 @@ -219,6 +226,7 @@ class Gender(enum.IntEnum): MASCULINE (int): Masculine NEUTER (int): Neuter """ + GENDER_UNKNOWN = 0 FEMININE = 1 MASCULINE = 2 @@ -237,6 +245,7 @@ class Mood(enum.IntEnum): JUSSIVE (int): Jussive SUBJUNCTIVE (int): Subjunctive """ + MOOD_UNKNOWN = 0 CONDITIONAL_MOOD = 1 IMPERATIVE = 2 @@ -255,6 +264,7 @@ class Number(enum.IntEnum): PLURAL (int): Plural DUAL (int): Dual """ + NUMBER_UNKNOWN = 0 SINGULAR = 1 PLURAL = 2 @@ -271,6 +281,7 @@ class Person(enum.IntEnum): THIRD (int): Third REFLEXIVE_PERSON (int): Reflexive """ + PERSON_UNKNOWN = 0 FIRST = 1 SECOND = 2 @@ -286,6 +297,7 @@ class Proper(enum.IntEnum): PROPER (int): Proper NOT_PROPER (int): Not proper """ + PROPER_UNKNOWN = 0 PROPER = 1 NOT_PROPER = 2 @@ -300,6 +312,7 @@ class Reciprocity(enum.IntEnum): RECIPROCAL (int): Reciprocal NON_RECIPROCAL (int): Non-reciprocal """ + RECIPROCITY_UNKNOWN = 0 RECIPROCAL = 1 NON_RECIPROCAL = 2 @@ -317,6 +330,7 @@ class Tense(enum.IntEnum): IMPERFECT (int): Imperfect PLUPERFECT (int): Pluperfect """ + TENSE_UNKNOWN = 0 CONDITIONAL_TENSE = 1 FUTURE = 2 @@ -336,6 +350,7 @@ class Voice(enum.IntEnum): CAUSATIVE (int): Causative PASSIVE (int): Passive """ + VOICE_UNKNOWN = 0 ACTIVE = 1 CAUSATIVE = 2 @@ -432,6 +447,7 @@ class Label(enum.IntEnum): MES (int): Measure NCOMP (int): Nominal complement of a noun """ + UNKNOWN = 0 ABBREV = 1 ACOMP = 2 @@ -527,6 +543,7 @@ class Type(enum.IntEnum): PROPER (int): Proper name COMMON (int): Common noun (or noun compound) """ + TYPE_UNKNOWN = 0 PROPER = 1 COMMON = 2 diff --git a/packages/google-cloud-language/google/cloud/language_v1/gapic/language_service_client.py b/packages/google-cloud-language/google/cloud/language_v1/gapic/language_service_client.py index e5daf10e6d87..b84718e07ef7 100644 --- a/packages/google-cloud-language/google/cloud/language_v1/gapic/language_service_client.py +++ b/packages/google-cloud-language/google/cloud/language_v1/gapic/language_service_client.py @@ -31,8 +31,7 @@ from google.cloud.language_v1.proto import language_service_pb2 from google.cloud.language_v1.proto import language_service_pb2_grpc -_GAPIC_LIBRARY_VERSION = pkg_resources.get_distribution( - 'google-cloud-language', ).version +_GAPIC_LIBRARY_VERSION = pkg_resources.get_distribution("google-cloud-language").version class LanguageServiceClient(object): @@ -41,12 +40,12 @@ class LanguageServiceClient(object): recognition. """ - SERVICE_ADDRESS = 'language.googleapis.com:443' + SERVICE_ADDRESS = "language.googleapis.com:443" """The default address of the service.""" # The name of the interface for this client. This is the key used to # find the method configuration in the client_config dictionary. - _INTERFACE_NAME = 'google.cloud.language.v1.LanguageService' + _INTERFACE_NAME = "google.cloud.language.v1.LanguageService" @classmethod def from_service_account_file(cls, filename, *args, **kwargs): @@ -62,19 +61,20 @@ def from_service_account_file(cls, filename, *args, **kwargs): Returns: LanguageServiceClient: The constructed client. """ - credentials = service_account.Credentials.from_service_account_file( - filename) - kwargs['credentials'] = credentials + credentials = service_account.Credentials.from_service_account_file(filename) + kwargs["credentials"] = credentials return cls(*args, **kwargs) from_service_account_json = from_service_account_file - def __init__(self, - transport=None, - channel=None, - credentials=None, - client_config=None, - client_info=None): + def __init__( + self, + transport=None, + channel=None, + credentials=None, + client_config=None, + client_info=None, + ): """Constructor. Args: @@ -108,18 +108,19 @@ def __init__(self, # Raise deprecation warnings for things we want to go away. if client_config is not None: warnings.warn( - 'The `client_config` argument is deprecated.', + "The `client_config` argument is deprecated.", PendingDeprecationWarning, - stacklevel=2) + stacklevel=2, + ) else: client_config = language_service_client_config.config if channel: warnings.warn( - 'The `channel` argument is deprecated; use ' - '`transport` instead.', + "The `channel` argument is deprecated; use " "`transport` instead.", PendingDeprecationWarning, - stacklevel=2) + stacklevel=2, + ) # Instantiate the transport. # The transport is responsible for handling serialization and @@ -128,25 +129,24 @@ def __init__(self, if callable(transport): self.transport = transport( credentials=credentials, - default_class=language_service_grpc_transport. - LanguageServiceGrpcTransport, + default_class=language_service_grpc_transport.LanguageServiceGrpcTransport, ) else: if credentials: raise ValueError( - 'Received both a transport instance and ' - 'credentials; these are mutually exclusive.') + "Received both a transport instance and " + "credentials; these are mutually exclusive." + ) self.transport = transport else: self.transport = language_service_grpc_transport.LanguageServiceGrpcTransport( - address=self.SERVICE_ADDRESS, - channel=channel, - credentials=credentials, + address=self.SERVICE_ADDRESS, channel=channel, credentials=credentials ) if client_info is None: client_info = google.api_core.gapic_v1.client_info.ClientInfo( - gapic_version=_GAPIC_LIBRARY_VERSION, ) + gapic_version=_GAPIC_LIBRARY_VERSION + ) else: client_info.gapic_version = _GAPIC_LIBRARY_VERSION self._client_info = client_info @@ -156,7 +156,8 @@ def __init__(self, # (Ordinarily, these are the defaults specified in the `*_config.py` # file next to this one.) self._method_configs = google.api_core.gapic_v1.config.parse_method_configs( - client_config['interfaces'][self._INTERFACE_NAME], ) + client_config["interfaces"][self._INTERFACE_NAME] + ) # Save a dictionary of cached API call functions. # These are the actual callables which invoke the proper @@ -165,12 +166,14 @@ def __init__(self, self._inner_api_calls = {} # Service calls - def analyze_sentiment(self, - document, - encoding_type=None, - retry=google.api_core.gapic_v1.method.DEFAULT, - timeout=google.api_core.gapic_v1.method.DEFAULT, - metadata=None): + def analyze_sentiment( + self, + document, + encoding_type=None, + retry=google.api_core.gapic_v1.method.DEFAULT, + timeout=google.api_core.gapic_v1.method.DEFAULT, + metadata=None, + ): """ Analyzes the sentiment of the provided text. @@ -210,30 +213,31 @@ def analyze_sentiment(self, ValueError: If the parameters are invalid. """ # Wrap the transport method to add retry and timeout logic. - if 'analyze_sentiment' not in self._inner_api_calls: + if "analyze_sentiment" not in self._inner_api_calls: self._inner_api_calls[ - 'analyze_sentiment'] = google.api_core.gapic_v1.method.wrap_method( - self.transport.analyze_sentiment, - default_retry=self._method_configs['AnalyzeSentiment']. - retry, - default_timeout=self._method_configs['AnalyzeSentiment']. - timeout, - client_info=self._client_info, - ) + "analyze_sentiment" + ] = google.api_core.gapic_v1.method.wrap_method( + self.transport.analyze_sentiment, + default_retry=self._method_configs["AnalyzeSentiment"].retry, + default_timeout=self._method_configs["AnalyzeSentiment"].timeout, + client_info=self._client_info, + ) request = language_service_pb2.AnalyzeSentimentRequest( - document=document, - encoding_type=encoding_type, + document=document, encoding_type=encoding_type + ) + return self._inner_api_calls["analyze_sentiment"]( + request, retry=retry, timeout=timeout, metadata=metadata ) - return self._inner_api_calls['analyze_sentiment']( - request, retry=retry, timeout=timeout, metadata=metadata) - - def analyze_entities(self, - document, - encoding_type=None, - retry=google.api_core.gapic_v1.method.DEFAULT, - timeout=google.api_core.gapic_v1.method.DEFAULT, - metadata=None): + + def analyze_entities( + self, + document, + encoding_type=None, + retry=google.api_core.gapic_v1.method.DEFAULT, + timeout=google.api_core.gapic_v1.method.DEFAULT, + metadata=None, + ): """ Finds named entities (currently proper names and common nouns) in the text along with entity types, salience, mentions for each entity, and @@ -275,31 +279,31 @@ def analyze_entities(self, ValueError: If the parameters are invalid. """ # Wrap the transport method to add retry and timeout logic. - if 'analyze_entities' not in self._inner_api_calls: + if "analyze_entities" not in self._inner_api_calls: self._inner_api_calls[ - 'analyze_entities'] = google.api_core.gapic_v1.method.wrap_method( - self.transport.analyze_entities, - default_retry=self._method_configs['AnalyzeEntities']. - retry, - default_timeout=self._method_configs['AnalyzeEntities']. - timeout, - client_info=self._client_info, - ) + "analyze_entities" + ] = google.api_core.gapic_v1.method.wrap_method( + self.transport.analyze_entities, + default_retry=self._method_configs["AnalyzeEntities"].retry, + default_timeout=self._method_configs["AnalyzeEntities"].timeout, + client_info=self._client_info, + ) request = language_service_pb2.AnalyzeEntitiesRequest( - document=document, - encoding_type=encoding_type, + document=document, encoding_type=encoding_type + ) + return self._inner_api_calls["analyze_entities"]( + request, retry=retry, timeout=timeout, metadata=metadata ) - return self._inner_api_calls['analyze_entities']( - request, retry=retry, timeout=timeout, metadata=metadata) def analyze_entity_sentiment( - self, - document, - encoding_type=None, - retry=google.api_core.gapic_v1.method.DEFAULT, - timeout=google.api_core.gapic_v1.method.DEFAULT, - metadata=None): + self, + document, + encoding_type=None, + retry=google.api_core.gapic_v1.method.DEFAULT, + timeout=google.api_core.gapic_v1.method.DEFAULT, + metadata=None, + ): """ Finds entities, similar to ``AnalyzeEntities`` in the text and analyzes sentiment associated with each entity and its mentions. @@ -340,30 +344,31 @@ def analyze_entity_sentiment( ValueError: If the parameters are invalid. """ # Wrap the transport method to add retry and timeout logic. - if 'analyze_entity_sentiment' not in self._inner_api_calls: + if "analyze_entity_sentiment" not in self._inner_api_calls: self._inner_api_calls[ - 'analyze_entity_sentiment'] = google.api_core.gapic_v1.method.wrap_method( - self.transport.analyze_entity_sentiment, - default_retry=self. - _method_configs['AnalyzeEntitySentiment'].retry, - default_timeout=self. - _method_configs['AnalyzeEntitySentiment'].timeout, - client_info=self._client_info, - ) + "analyze_entity_sentiment" + ] = google.api_core.gapic_v1.method.wrap_method( + self.transport.analyze_entity_sentiment, + default_retry=self._method_configs["AnalyzeEntitySentiment"].retry, + default_timeout=self._method_configs["AnalyzeEntitySentiment"].timeout, + client_info=self._client_info, + ) request = language_service_pb2.AnalyzeEntitySentimentRequest( - document=document, - encoding_type=encoding_type, + document=document, encoding_type=encoding_type ) - return self._inner_api_calls['analyze_entity_sentiment']( - request, retry=retry, timeout=timeout, metadata=metadata) - - def analyze_syntax(self, - document, - encoding_type=None, - retry=google.api_core.gapic_v1.method.DEFAULT, - timeout=google.api_core.gapic_v1.method.DEFAULT, - metadata=None): + return self._inner_api_calls["analyze_entity_sentiment"]( + request, retry=retry, timeout=timeout, metadata=metadata + ) + + def analyze_syntax( + self, + document, + encoding_type=None, + retry=google.api_core.gapic_v1.method.DEFAULT, + timeout=google.api_core.gapic_v1.method.DEFAULT, + metadata=None, + ): """ Analyzes the syntax of the text and provides sentence boundaries and tokenization along with part of speech tags, dependency trees, and other @@ -405,28 +410,30 @@ def analyze_syntax(self, ValueError: If the parameters are invalid. """ # Wrap the transport method to add retry and timeout logic. - if 'analyze_syntax' not in self._inner_api_calls: + if "analyze_syntax" not in self._inner_api_calls: self._inner_api_calls[ - 'analyze_syntax'] = google.api_core.gapic_v1.method.wrap_method( - self.transport.analyze_syntax, - default_retry=self._method_configs['AnalyzeSyntax'].retry, - default_timeout=self._method_configs['AnalyzeSyntax']. - timeout, - client_info=self._client_info, - ) + "analyze_syntax" + ] = google.api_core.gapic_v1.method.wrap_method( + self.transport.analyze_syntax, + default_retry=self._method_configs["AnalyzeSyntax"].retry, + default_timeout=self._method_configs["AnalyzeSyntax"].timeout, + client_info=self._client_info, + ) request = language_service_pb2.AnalyzeSyntaxRequest( - document=document, - encoding_type=encoding_type, + document=document, encoding_type=encoding_type ) - return self._inner_api_calls['analyze_syntax']( - request, retry=retry, timeout=timeout, metadata=metadata) - - def classify_text(self, - document, - retry=google.api_core.gapic_v1.method.DEFAULT, - timeout=google.api_core.gapic_v1.method.DEFAULT, - metadata=None): + return self._inner_api_calls["analyze_syntax"]( + request, retry=retry, timeout=timeout, metadata=metadata + ) + + def classify_text( + self, + document, + retry=google.api_core.gapic_v1.method.DEFAULT, + timeout=google.api_core.gapic_v1.method.DEFAULT, + metadata=None, + ): """ Classifies a document into categories. @@ -465,27 +472,30 @@ def classify_text(self, ValueError: If the parameters are invalid. """ # Wrap the transport method to add retry and timeout logic. - if 'classify_text' not in self._inner_api_calls: + if "classify_text" not in self._inner_api_calls: self._inner_api_calls[ - 'classify_text'] = google.api_core.gapic_v1.method.wrap_method( - self.transport.classify_text, - default_retry=self._method_configs['ClassifyText'].retry, - default_timeout=self._method_configs['ClassifyText']. - timeout, - client_info=self._client_info, - ) + "classify_text" + ] = google.api_core.gapic_v1.method.wrap_method( + self.transport.classify_text, + default_retry=self._method_configs["ClassifyText"].retry, + default_timeout=self._method_configs["ClassifyText"].timeout, + client_info=self._client_info, + ) + + request = language_service_pb2.ClassifyTextRequest(document=document) + return self._inner_api_calls["classify_text"]( + request, retry=retry, timeout=timeout, metadata=metadata + ) - request = language_service_pb2.ClassifyTextRequest(document=document, ) - return self._inner_api_calls['classify_text']( - request, retry=retry, timeout=timeout, metadata=metadata) - - def annotate_text(self, - document, - features, - encoding_type=None, - retry=google.api_core.gapic_v1.method.DEFAULT, - timeout=google.api_core.gapic_v1.method.DEFAULT, - metadata=None): + def annotate_text( + self, + document, + features, + encoding_type=None, + retry=google.api_core.gapic_v1.method.DEFAULT, + timeout=google.api_core.gapic_v1.method.DEFAULT, + metadata=None, + ): """ A convenience method that provides all the features that analyzeSentiment, analyzeEntities, and analyzeSyntax provide in one call. @@ -533,20 +543,19 @@ def annotate_text(self, ValueError: If the parameters are invalid. """ # Wrap the transport method to add retry and timeout logic. - if 'annotate_text' not in self._inner_api_calls: + if "annotate_text" not in self._inner_api_calls: self._inner_api_calls[ - 'annotate_text'] = google.api_core.gapic_v1.method.wrap_method( - self.transport.annotate_text, - default_retry=self._method_configs['AnnotateText'].retry, - default_timeout=self._method_configs['AnnotateText']. - timeout, - client_info=self._client_info, - ) + "annotate_text" + ] = google.api_core.gapic_v1.method.wrap_method( + self.transport.annotate_text, + default_retry=self._method_configs["AnnotateText"].retry, + default_timeout=self._method_configs["AnnotateText"].timeout, + client_info=self._client_info, + ) request = language_service_pb2.AnnotateTextRequest( - document=document, - features=features, - encoding_type=encoding_type, + document=document, features=features, encoding_type=encoding_type + ) + return self._inner_api_calls["annotate_text"]( + request, retry=retry, timeout=timeout, metadata=metadata ) - return self._inner_api_calls['annotate_text']( - request, retry=retry, timeout=timeout, metadata=metadata) diff --git a/packages/google-cloud-language/google/cloud/language_v1/gapic/language_service_client_config.py b/packages/google-cloud-language/google/cloud/language_v1/gapic/language_service_client_config.py index 789883153df0..a36baec5bca5 100644 --- a/packages/google-cloud-language/google/cloud/language_v1/gapic/language_service_client_config.py +++ b/packages/google-cloud-language/google/cloud/language_v1/gapic/language_service_client_config.py @@ -3,7 +3,7 @@ "google.cloud.language.v1.LanguageService": { "retry_codes": { "idempotent": ["DEADLINE_EXCEEDED", "UNAVAILABLE"], - "non_idempotent": [] + "non_idempotent": [], }, "retry_params": { "default": { @@ -13,41 +13,41 @@ "initial_rpc_timeout_millis": 60000, "rpc_timeout_multiplier": 1.0, "max_rpc_timeout_millis": 60000, - "total_timeout_millis": 600000 + "total_timeout_millis": 600000, } }, "methods": { "AnalyzeSentiment": { "timeout_millis": 30000, "retry_codes_name": "idempotent", - "retry_params_name": "default" + "retry_params_name": "default", }, "AnalyzeEntities": { "timeout_millis": 30000, "retry_codes_name": "idempotent", - "retry_params_name": "default" + "retry_params_name": "default", }, "AnalyzeEntitySentiment": { "timeout_millis": 30000, "retry_codes_name": "idempotent", - "retry_params_name": "default" + "retry_params_name": "default", }, "AnalyzeSyntax": { "timeout_millis": 30000, "retry_codes_name": "idempotent", - "retry_params_name": "default" + "retry_params_name": "default", }, "ClassifyText": { "timeout_millis": 30000, "retry_codes_name": "idempotent", - "retry_params_name": "default" + "retry_params_name": "default", }, "AnnotateText": { "timeout_millis": 30000, "retry_codes_name": "idempotent", - "retry_params_name": "default" - } - } + "retry_params_name": "default", + }, + }, } } } diff --git a/packages/google-cloud-language/google/cloud/language_v1/gapic/transports/language_service_grpc_transport.py b/packages/google-cloud-language/google/cloud/language_v1/gapic/transports/language_service_grpc_transport.py index a6f62471a1cd..82acb8fc6d22 100644 --- a/packages/google-cloud-language/google/cloud/language_v1/gapic/transports/language_service_grpc_transport.py +++ b/packages/google-cloud-language/google/cloud/language_v1/gapic/transports/language_service_grpc_transport.py @@ -27,14 +27,14 @@ class LanguageServiceGrpcTransport(object): which can be used to take advantage of advanced features of gRPC. """ + # The scopes needed to make gRPC calls to all of the methods defined # in this service. - _OAUTH_SCOPES = ('https://www.googleapis.com/auth/cloud-platform', ) + _OAUTH_SCOPES = ("https://www.googleapis.com/auth/cloud-platform",) - def __init__(self, - channel=None, - credentials=None, - address='language.googleapis.com:443'): + def __init__( + self, channel=None, credentials=None, address="language.googleapis.com:443" + ): """Instantiate the transport class. Args: @@ -52,29 +52,25 @@ def __init__(self, # exception (channels come with credentials baked in already). if channel is not None and credentials is not None: raise ValueError( - 'The `channel` and `credentials` arguments are mutually ' - 'exclusive.', ) + "The `channel` and `credentials` arguments are mutually " "exclusive." + ) # Create the channel. if channel is None: - channel = self.create_channel( - address=address, - credentials=credentials, - ) + channel = self.create_channel(address=address, credentials=credentials) self._channel = channel # gRPC uses objects called "stubs" that are bound to the # channel and provide a basic method for each RPC. self._stubs = { - 'language_service_stub': - language_service_pb2_grpc.LanguageServiceStub(channel), + "language_service_stub": language_service_pb2_grpc.LanguageServiceStub( + channel + ) } @classmethod - def create_channel(cls, - address='language.googleapis.com:443', - credentials=None): + def create_channel(cls, address="language.googleapis.com:443", credentials=None): """Create and return a gRPC channel object. Args: @@ -89,9 +85,7 @@ def create_channel(cls, grpc.Channel: A gRPC channel object. """ return google.api_core.grpc_helpers.create_channel( - address, - credentials=credentials, - scopes=cls._OAUTH_SCOPES, + address, credentials=credentials, scopes=cls._OAUTH_SCOPES ) @property @@ -114,7 +108,7 @@ def analyze_sentiment(self): deserialized request object and returns a deserialized response object. """ - return self._stubs['language_service_stub'].AnalyzeSentiment + return self._stubs["language_service_stub"].AnalyzeSentiment @property def analyze_entities(self): @@ -129,7 +123,7 @@ def analyze_entities(self): deserialized request object and returns a deserialized response object. """ - return self._stubs['language_service_stub'].AnalyzeEntities + return self._stubs["language_service_stub"].AnalyzeEntities @property def analyze_entity_sentiment(self): @@ -143,7 +137,7 @@ def analyze_entity_sentiment(self): deserialized request object and returns a deserialized response object. """ - return self._stubs['language_service_stub'].AnalyzeEntitySentiment + return self._stubs["language_service_stub"].AnalyzeEntitySentiment @property def analyze_syntax(self): @@ -158,7 +152,7 @@ def analyze_syntax(self): deserialized request object and returns a deserialized response object. """ - return self._stubs['language_service_stub'].AnalyzeSyntax + return self._stubs["language_service_stub"].AnalyzeSyntax @property def classify_text(self): @@ -171,7 +165,7 @@ def classify_text(self): deserialized request object and returns a deserialized response object. """ - return self._stubs['language_service_stub'].ClassifyText + return self._stubs["language_service_stub"].ClassifyText @property def annotate_text(self): @@ -185,4 +179,4 @@ def annotate_text(self): deserialized request object and returns a deserialized response object. """ - return self._stubs['language_service_stub'].AnnotateText + return self._stubs["language_service_stub"].AnnotateText diff --git a/packages/google-cloud-language/google/cloud/language_v1/types.py b/packages/google-cloud-language/google/cloud/language_v1/types.py index 469269333ef0..758829425134 100644 --- a/packages/google-cloud-language/google/cloud/language_v1/types.py +++ b/packages/google-cloud-language/google/cloud/language_v1/types.py @@ -22,14 +22,9 @@ from google.cloud.language_v1.proto import language_service_pb2 -_shared_modules = [ - http_pb2, - descriptor_pb2, -] +_shared_modules = [http_pb2, descriptor_pb2] -_local_modules = [ - language_service_pb2, -] +_local_modules = [language_service_pb2] names = [] @@ -40,7 +35,7 @@ for module in _local_modules: for name, message in get_messages(module).items(): - message.__module__ = 'google.cloud.language_v1.types' + message.__module__ = "google.cloud.language_v1.types" setattr(sys.modules[__name__], name, message) names.append(name) diff --git a/packages/google-cloud-language/google/cloud/language_v1beta2/__init__.py b/packages/google-cloud-language/google/cloud/language_v1beta2/__init__.py index f9846d89b1f0..d980c998cc19 100644 --- a/packages/google-cloud-language/google/cloud/language_v1beta2/__init__.py +++ b/packages/google-cloud-language/google/cloud/language_v1beta2/__init__.py @@ -24,7 +24,4 @@ class LanguageServiceClient(language_service_client.LanguageServiceClient): enums = enums -__all__ = ( - 'enums', - 'types', - 'LanguageServiceClient', ) +__all__ = ("enums", "types", "LanguageServiceClient") diff --git a/packages/google-cloud-language/google/cloud/language_v1beta2/gapic/enums.py b/packages/google-cloud-language/google/cloud/language_v1beta2/gapic/enums.py index dcd23c41470c..1845f221979c 100644 --- a/packages/google-cloud-language/google/cloud/language_v1beta2/gapic/enums.py +++ b/packages/google-cloud-language/google/cloud/language_v1beta2/gapic/enums.py @@ -39,6 +39,7 @@ class EncodingType(enum.IntEnum): based on the UTF-32 encoding of the input. Python is an example of a language that uses this encoding natively. """ + NONE = 0 UTF8 = 1 UTF16 = 2 @@ -55,6 +56,7 @@ class Type(enum.IntEnum): PLAIN_TEXT (int): Plain text HTML (int): HTML """ + TYPE_UNSPECIFIED = 0 PLAIN_TEXT = 1 HTML = 2 @@ -75,6 +77,7 @@ class Type(enum.IntEnum): CONSUMER_GOOD (int): Consumer goods OTHER (int): Other types """ + UNKNOWN = 0 PERSON = 1 LOCATION = 2 @@ -106,6 +109,7 @@ class Tag(enum.IntEnum): X (int): Other: foreign words, typos, abbreviations AFFIX (int): Affix """ + UNKNOWN = 0 ADJ = 1 ADP = 2 @@ -131,6 +135,7 @@ class Aspect(enum.IntEnum): IMPERFECTIVE (int): Imperfective PROGRESSIVE (int): Progressive """ + ASPECT_UNKNOWN = 0 PERFECTIVE = 1 IMPERFECTIVE = 2 @@ -159,6 +164,7 @@ class Case(enum.IntEnum): RELATIVE_CASE (int): Relative VOCATIVE (int): Vocative """ + CASE_UNKNOWN = 0 ACCUSATIVE = 1 ADVERBIAL = 2 @@ -196,6 +202,7 @@ class Form(enum.IntEnum): ORDER (int): Order form SPECIFIC (int): Specific form """ + FORM_UNKNOWN = 0 ADNOMIAL = 1 AUXILIARY = 2 @@ -219,6 +226,7 @@ class Gender(enum.IntEnum): MASCULINE (int): Masculine NEUTER (int): Neuter """ + GENDER_UNKNOWN = 0 FEMININE = 1 MASCULINE = 2 @@ -237,6 +245,7 @@ class Mood(enum.IntEnum): JUSSIVE (int): Jussive SUBJUNCTIVE (int): Subjunctive """ + MOOD_UNKNOWN = 0 CONDITIONAL_MOOD = 1 IMPERATIVE = 2 @@ -255,6 +264,7 @@ class Number(enum.IntEnum): PLURAL (int): Plural DUAL (int): Dual """ + NUMBER_UNKNOWN = 0 SINGULAR = 1 PLURAL = 2 @@ -271,6 +281,7 @@ class Person(enum.IntEnum): THIRD (int): Third REFLEXIVE_PERSON (int): Reflexive """ + PERSON_UNKNOWN = 0 FIRST = 1 SECOND = 2 @@ -286,6 +297,7 @@ class Proper(enum.IntEnum): PROPER (int): Proper NOT_PROPER (int): Not proper """ + PROPER_UNKNOWN = 0 PROPER = 1 NOT_PROPER = 2 @@ -300,6 +312,7 @@ class Reciprocity(enum.IntEnum): RECIPROCAL (int): Reciprocal NON_RECIPROCAL (int): Non-reciprocal """ + RECIPROCITY_UNKNOWN = 0 RECIPROCAL = 1 NON_RECIPROCAL = 2 @@ -317,6 +330,7 @@ class Tense(enum.IntEnum): IMPERFECT (int): Imperfect PLUPERFECT (int): Pluperfect """ + TENSE_UNKNOWN = 0 CONDITIONAL_TENSE = 1 FUTURE = 2 @@ -336,6 +350,7 @@ class Voice(enum.IntEnum): CAUSATIVE (int): Causative PASSIVE (int): Passive """ + VOICE_UNKNOWN = 0 ACTIVE = 1 CAUSATIVE = 2 @@ -432,6 +447,7 @@ class Label(enum.IntEnum): MES (int): Measure NCOMP (int): Nominal complement of a noun """ + UNKNOWN = 0 ABBREV = 1 ACOMP = 2 @@ -527,6 +543,7 @@ class Type(enum.IntEnum): PROPER (int): Proper name COMMON (int): Common noun (or noun compound) """ + TYPE_UNKNOWN = 0 PROPER = 1 COMMON = 2 diff --git a/packages/google-cloud-language/google/cloud/language_v1beta2/gapic/language_service_client.py b/packages/google-cloud-language/google/cloud/language_v1beta2/gapic/language_service_client.py index a5215cf38b0a..01b09fa90bdc 100644 --- a/packages/google-cloud-language/google/cloud/language_v1beta2/gapic/language_service_client.py +++ b/packages/google-cloud-language/google/cloud/language_v1beta2/gapic/language_service_client.py @@ -27,12 +27,13 @@ from google.cloud.language_v1beta2.gapic import enums from google.cloud.language_v1beta2.gapic import language_service_client_config -from google.cloud.language_v1beta2.gapic.transports import language_service_grpc_transport +from google.cloud.language_v1beta2.gapic.transports import ( + language_service_grpc_transport, +) from google.cloud.language_v1beta2.proto import language_service_pb2 from google.cloud.language_v1beta2.proto import language_service_pb2_grpc -_GAPIC_LIBRARY_VERSION = pkg_resources.get_distribution( - 'google-cloud-language', ).version +_GAPIC_LIBRARY_VERSION = pkg_resources.get_distribution("google-cloud-language").version class LanguageServiceClient(object): @@ -41,12 +42,12 @@ class LanguageServiceClient(object): recognition. """ - SERVICE_ADDRESS = 'language.googleapis.com:443' + SERVICE_ADDRESS = "language.googleapis.com:443" """The default address of the service.""" # The name of the interface for this client. This is the key used to # find the method configuration in the client_config dictionary. - _INTERFACE_NAME = 'google.cloud.language.v1beta2.LanguageService' + _INTERFACE_NAME = "google.cloud.language.v1beta2.LanguageService" @classmethod def from_service_account_file(cls, filename, *args, **kwargs): @@ -62,19 +63,20 @@ def from_service_account_file(cls, filename, *args, **kwargs): Returns: LanguageServiceClient: The constructed client. """ - credentials = service_account.Credentials.from_service_account_file( - filename) - kwargs['credentials'] = credentials + credentials = service_account.Credentials.from_service_account_file(filename) + kwargs["credentials"] = credentials return cls(*args, **kwargs) from_service_account_json = from_service_account_file - def __init__(self, - transport=None, - channel=None, - credentials=None, - client_config=None, - client_info=None): + def __init__( + self, + transport=None, + channel=None, + credentials=None, + client_config=None, + client_info=None, + ): """Constructor. Args: @@ -108,18 +110,19 @@ def __init__(self, # Raise deprecation warnings for things we want to go away. if client_config is not None: warnings.warn( - 'The `client_config` argument is deprecated.', + "The `client_config` argument is deprecated.", PendingDeprecationWarning, - stacklevel=2) + stacklevel=2, + ) else: client_config = language_service_client_config.config if channel: warnings.warn( - 'The `channel` argument is deprecated; use ' - '`transport` instead.', + "The `channel` argument is deprecated; use " "`transport` instead.", PendingDeprecationWarning, - stacklevel=2) + stacklevel=2, + ) # Instantiate the transport. # The transport is responsible for handling serialization and @@ -128,25 +131,24 @@ def __init__(self, if callable(transport): self.transport = transport( credentials=credentials, - default_class=language_service_grpc_transport. - LanguageServiceGrpcTransport, + default_class=language_service_grpc_transport.LanguageServiceGrpcTransport, ) else: if credentials: raise ValueError( - 'Received both a transport instance and ' - 'credentials; these are mutually exclusive.') + "Received both a transport instance and " + "credentials; these are mutually exclusive." + ) self.transport = transport else: self.transport = language_service_grpc_transport.LanguageServiceGrpcTransport( - address=self.SERVICE_ADDRESS, - channel=channel, - credentials=credentials, + address=self.SERVICE_ADDRESS, channel=channel, credentials=credentials ) if client_info is None: client_info = google.api_core.gapic_v1.client_info.ClientInfo( - gapic_version=_GAPIC_LIBRARY_VERSION, ) + gapic_version=_GAPIC_LIBRARY_VERSION + ) else: client_info.gapic_version = _GAPIC_LIBRARY_VERSION self._client_info = client_info @@ -156,7 +158,8 @@ def __init__(self, # (Ordinarily, these are the defaults specified in the `*_config.py` # file next to this one.) self._method_configs = google.api_core.gapic_v1.config.parse_method_configs( - client_config['interfaces'][self._INTERFACE_NAME], ) + client_config["interfaces"][self._INTERFACE_NAME] + ) # Save a dictionary of cached API call functions. # These are the actual callables which invoke the proper @@ -165,12 +168,14 @@ def __init__(self, self._inner_api_calls = {} # Service calls - def analyze_sentiment(self, - document, - encoding_type=None, - retry=google.api_core.gapic_v1.method.DEFAULT, - timeout=google.api_core.gapic_v1.method.DEFAULT, - metadata=None): + def analyze_sentiment( + self, + document, + encoding_type=None, + retry=google.api_core.gapic_v1.method.DEFAULT, + timeout=google.api_core.gapic_v1.method.DEFAULT, + metadata=None, + ): """ Analyzes the sentiment of the provided text. @@ -211,30 +216,31 @@ def analyze_sentiment(self, ValueError: If the parameters are invalid. """ # Wrap the transport method to add retry and timeout logic. - if 'analyze_sentiment' not in self._inner_api_calls: + if "analyze_sentiment" not in self._inner_api_calls: self._inner_api_calls[ - 'analyze_sentiment'] = google.api_core.gapic_v1.method.wrap_method( - self.transport.analyze_sentiment, - default_retry=self._method_configs['AnalyzeSentiment']. - retry, - default_timeout=self._method_configs['AnalyzeSentiment']. - timeout, - client_info=self._client_info, - ) + "analyze_sentiment" + ] = google.api_core.gapic_v1.method.wrap_method( + self.transport.analyze_sentiment, + default_retry=self._method_configs["AnalyzeSentiment"].retry, + default_timeout=self._method_configs["AnalyzeSentiment"].timeout, + client_info=self._client_info, + ) request = language_service_pb2.AnalyzeSentimentRequest( - document=document, - encoding_type=encoding_type, + document=document, encoding_type=encoding_type + ) + return self._inner_api_calls["analyze_sentiment"]( + request, retry=retry, timeout=timeout, metadata=metadata ) - return self._inner_api_calls['analyze_sentiment']( - request, retry=retry, timeout=timeout, metadata=metadata) - - def analyze_entities(self, - document, - encoding_type=None, - retry=google.api_core.gapic_v1.method.DEFAULT, - timeout=google.api_core.gapic_v1.method.DEFAULT, - metadata=None): + + def analyze_entities( + self, + document, + encoding_type=None, + retry=google.api_core.gapic_v1.method.DEFAULT, + timeout=google.api_core.gapic_v1.method.DEFAULT, + metadata=None, + ): """ Finds named entities (currently proper names and common nouns) in the text along with entity types, salience, mentions for each entity, and @@ -276,31 +282,31 @@ def analyze_entities(self, ValueError: If the parameters are invalid. """ # Wrap the transport method to add retry and timeout logic. - if 'analyze_entities' not in self._inner_api_calls: + if "analyze_entities" not in self._inner_api_calls: self._inner_api_calls[ - 'analyze_entities'] = google.api_core.gapic_v1.method.wrap_method( - self.transport.analyze_entities, - default_retry=self._method_configs['AnalyzeEntities']. - retry, - default_timeout=self._method_configs['AnalyzeEntities']. - timeout, - client_info=self._client_info, - ) + "analyze_entities" + ] = google.api_core.gapic_v1.method.wrap_method( + self.transport.analyze_entities, + default_retry=self._method_configs["AnalyzeEntities"].retry, + default_timeout=self._method_configs["AnalyzeEntities"].timeout, + client_info=self._client_info, + ) request = language_service_pb2.AnalyzeEntitiesRequest( - document=document, - encoding_type=encoding_type, + document=document, encoding_type=encoding_type + ) + return self._inner_api_calls["analyze_entities"]( + request, retry=retry, timeout=timeout, metadata=metadata ) - return self._inner_api_calls['analyze_entities']( - request, retry=retry, timeout=timeout, metadata=metadata) def analyze_entity_sentiment( - self, - document, - encoding_type=None, - retry=google.api_core.gapic_v1.method.DEFAULT, - timeout=google.api_core.gapic_v1.method.DEFAULT, - metadata=None): + self, + document, + encoding_type=None, + retry=google.api_core.gapic_v1.method.DEFAULT, + timeout=google.api_core.gapic_v1.method.DEFAULT, + metadata=None, + ): """ Finds entities, similar to ``AnalyzeEntities`` in the text and analyzes sentiment associated with each entity and its mentions. @@ -341,30 +347,31 @@ def analyze_entity_sentiment( ValueError: If the parameters are invalid. """ # Wrap the transport method to add retry and timeout logic. - if 'analyze_entity_sentiment' not in self._inner_api_calls: + if "analyze_entity_sentiment" not in self._inner_api_calls: self._inner_api_calls[ - 'analyze_entity_sentiment'] = google.api_core.gapic_v1.method.wrap_method( - self.transport.analyze_entity_sentiment, - default_retry=self. - _method_configs['AnalyzeEntitySentiment'].retry, - default_timeout=self. - _method_configs['AnalyzeEntitySentiment'].timeout, - client_info=self._client_info, - ) + "analyze_entity_sentiment" + ] = google.api_core.gapic_v1.method.wrap_method( + self.transport.analyze_entity_sentiment, + default_retry=self._method_configs["AnalyzeEntitySentiment"].retry, + default_timeout=self._method_configs["AnalyzeEntitySentiment"].timeout, + client_info=self._client_info, + ) request = language_service_pb2.AnalyzeEntitySentimentRequest( - document=document, - encoding_type=encoding_type, + document=document, encoding_type=encoding_type ) - return self._inner_api_calls['analyze_entity_sentiment']( - request, retry=retry, timeout=timeout, metadata=metadata) - - def analyze_syntax(self, - document, - encoding_type=None, - retry=google.api_core.gapic_v1.method.DEFAULT, - timeout=google.api_core.gapic_v1.method.DEFAULT, - metadata=None): + return self._inner_api_calls["analyze_entity_sentiment"]( + request, retry=retry, timeout=timeout, metadata=metadata + ) + + def analyze_syntax( + self, + document, + encoding_type=None, + retry=google.api_core.gapic_v1.method.DEFAULT, + timeout=google.api_core.gapic_v1.method.DEFAULT, + metadata=None, + ): """ Analyzes the syntax of the text and provides sentence boundaries and tokenization along with part of speech tags, dependency trees, and other @@ -406,28 +413,30 @@ def analyze_syntax(self, ValueError: If the parameters are invalid. """ # Wrap the transport method to add retry and timeout logic. - if 'analyze_syntax' not in self._inner_api_calls: + if "analyze_syntax" not in self._inner_api_calls: self._inner_api_calls[ - 'analyze_syntax'] = google.api_core.gapic_v1.method.wrap_method( - self.transport.analyze_syntax, - default_retry=self._method_configs['AnalyzeSyntax'].retry, - default_timeout=self._method_configs['AnalyzeSyntax']. - timeout, - client_info=self._client_info, - ) + "analyze_syntax" + ] = google.api_core.gapic_v1.method.wrap_method( + self.transport.analyze_syntax, + default_retry=self._method_configs["AnalyzeSyntax"].retry, + default_timeout=self._method_configs["AnalyzeSyntax"].timeout, + client_info=self._client_info, + ) request = language_service_pb2.AnalyzeSyntaxRequest( - document=document, - encoding_type=encoding_type, + document=document, encoding_type=encoding_type ) - return self._inner_api_calls['analyze_syntax']( - request, retry=retry, timeout=timeout, metadata=metadata) - - def classify_text(self, - document, - retry=google.api_core.gapic_v1.method.DEFAULT, - timeout=google.api_core.gapic_v1.method.DEFAULT, - metadata=None): + return self._inner_api_calls["analyze_syntax"]( + request, retry=retry, timeout=timeout, metadata=metadata + ) + + def classify_text( + self, + document, + retry=google.api_core.gapic_v1.method.DEFAULT, + timeout=google.api_core.gapic_v1.method.DEFAULT, + metadata=None, + ): """ Classifies a document into categories. @@ -466,27 +475,30 @@ def classify_text(self, ValueError: If the parameters are invalid. """ # Wrap the transport method to add retry and timeout logic. - if 'classify_text' not in self._inner_api_calls: + if "classify_text" not in self._inner_api_calls: self._inner_api_calls[ - 'classify_text'] = google.api_core.gapic_v1.method.wrap_method( - self.transport.classify_text, - default_retry=self._method_configs['ClassifyText'].retry, - default_timeout=self._method_configs['ClassifyText']. - timeout, - client_info=self._client_info, - ) + "classify_text" + ] = google.api_core.gapic_v1.method.wrap_method( + self.transport.classify_text, + default_retry=self._method_configs["ClassifyText"].retry, + default_timeout=self._method_configs["ClassifyText"].timeout, + client_info=self._client_info, + ) + + request = language_service_pb2.ClassifyTextRequest(document=document) + return self._inner_api_calls["classify_text"]( + request, retry=retry, timeout=timeout, metadata=metadata + ) - request = language_service_pb2.ClassifyTextRequest(document=document, ) - return self._inner_api_calls['classify_text']( - request, retry=retry, timeout=timeout, metadata=metadata) - - def annotate_text(self, - document, - features, - encoding_type=None, - retry=google.api_core.gapic_v1.method.DEFAULT, - timeout=google.api_core.gapic_v1.method.DEFAULT, - metadata=None): + def annotate_text( + self, + document, + features, + encoding_type=None, + retry=google.api_core.gapic_v1.method.DEFAULT, + timeout=google.api_core.gapic_v1.method.DEFAULT, + metadata=None, + ): """ A convenience method that provides all syntax, sentiment, entity, and classification features in one call. @@ -534,20 +546,19 @@ def annotate_text(self, ValueError: If the parameters are invalid. """ # Wrap the transport method to add retry and timeout logic. - if 'annotate_text' not in self._inner_api_calls: + if "annotate_text" not in self._inner_api_calls: self._inner_api_calls[ - 'annotate_text'] = google.api_core.gapic_v1.method.wrap_method( - self.transport.annotate_text, - default_retry=self._method_configs['AnnotateText'].retry, - default_timeout=self._method_configs['AnnotateText']. - timeout, - client_info=self._client_info, - ) + "annotate_text" + ] = google.api_core.gapic_v1.method.wrap_method( + self.transport.annotate_text, + default_retry=self._method_configs["AnnotateText"].retry, + default_timeout=self._method_configs["AnnotateText"].timeout, + client_info=self._client_info, + ) request = language_service_pb2.AnnotateTextRequest( - document=document, - features=features, - encoding_type=encoding_type, + document=document, features=features, encoding_type=encoding_type + ) + return self._inner_api_calls["annotate_text"]( + request, retry=retry, timeout=timeout, metadata=metadata ) - return self._inner_api_calls['annotate_text']( - request, retry=retry, timeout=timeout, metadata=metadata) diff --git a/packages/google-cloud-language/google/cloud/language_v1beta2/gapic/language_service_client_config.py b/packages/google-cloud-language/google/cloud/language_v1beta2/gapic/language_service_client_config.py index f3473d4a2667..97ab1aa63434 100644 --- a/packages/google-cloud-language/google/cloud/language_v1beta2/gapic/language_service_client_config.py +++ b/packages/google-cloud-language/google/cloud/language_v1beta2/gapic/language_service_client_config.py @@ -3,7 +3,7 @@ "google.cloud.language.v1beta2.LanguageService": { "retry_codes": { "idempotent": ["DEADLINE_EXCEEDED", "UNAVAILABLE"], - "non_idempotent": [] + "non_idempotent": [], }, "retry_params": { "default": { @@ -13,41 +13,41 @@ "initial_rpc_timeout_millis": 60000, "rpc_timeout_multiplier": 1.0, "max_rpc_timeout_millis": 60000, - "total_timeout_millis": 600000 + "total_timeout_millis": 600000, } }, "methods": { "AnalyzeSentiment": { "timeout_millis": 30000, "retry_codes_name": "idempotent", - "retry_params_name": "default" + "retry_params_name": "default", }, "AnalyzeEntities": { "timeout_millis": 30000, "retry_codes_name": "idempotent", - "retry_params_name": "default" + "retry_params_name": "default", }, "AnalyzeEntitySentiment": { "timeout_millis": 30000, "retry_codes_name": "idempotent", - "retry_params_name": "default" + "retry_params_name": "default", }, "AnalyzeSyntax": { "timeout_millis": 30000, "retry_codes_name": "idempotent", - "retry_params_name": "default" + "retry_params_name": "default", }, "ClassifyText": { "timeout_millis": 30000, "retry_codes_name": "idempotent", - "retry_params_name": "default" + "retry_params_name": "default", }, "AnnotateText": { "timeout_millis": 30000, "retry_codes_name": "idempotent", - "retry_params_name": "default" - } - } + "retry_params_name": "default", + }, + }, } } } diff --git a/packages/google-cloud-language/google/cloud/language_v1beta2/gapic/transports/language_service_grpc_transport.py b/packages/google-cloud-language/google/cloud/language_v1beta2/gapic/transports/language_service_grpc_transport.py index a8527b3a0a76..624e0f05c7e8 100644 --- a/packages/google-cloud-language/google/cloud/language_v1beta2/gapic/transports/language_service_grpc_transport.py +++ b/packages/google-cloud-language/google/cloud/language_v1beta2/gapic/transports/language_service_grpc_transport.py @@ -27,14 +27,14 @@ class LanguageServiceGrpcTransport(object): which can be used to take advantage of advanced features of gRPC. """ + # The scopes needed to make gRPC calls to all of the methods defined # in this service. - _OAUTH_SCOPES = ('https://www.googleapis.com/auth/cloud-platform', ) + _OAUTH_SCOPES = ("https://www.googleapis.com/auth/cloud-platform",) - def __init__(self, - channel=None, - credentials=None, - address='language.googleapis.com:443'): + def __init__( + self, channel=None, credentials=None, address="language.googleapis.com:443" + ): """Instantiate the transport class. Args: @@ -52,29 +52,25 @@ def __init__(self, # exception (channels come with credentials baked in already). if channel is not None and credentials is not None: raise ValueError( - 'The `channel` and `credentials` arguments are mutually ' - 'exclusive.', ) + "The `channel` and `credentials` arguments are mutually " "exclusive." + ) # Create the channel. if channel is None: - channel = self.create_channel( - address=address, - credentials=credentials, - ) + channel = self.create_channel(address=address, credentials=credentials) self._channel = channel # gRPC uses objects called "stubs" that are bound to the # channel and provide a basic method for each RPC. self._stubs = { - 'language_service_stub': - language_service_pb2_grpc.LanguageServiceStub(channel), + "language_service_stub": language_service_pb2_grpc.LanguageServiceStub( + channel + ) } @classmethod - def create_channel(cls, - address='language.googleapis.com:443', - credentials=None): + def create_channel(cls, address="language.googleapis.com:443", credentials=None): """Create and return a gRPC channel object. Args: @@ -89,9 +85,7 @@ def create_channel(cls, grpc.Channel: A gRPC channel object. """ return google.api_core.grpc_helpers.create_channel( - address, - credentials=credentials, - scopes=cls._OAUTH_SCOPES, + address, credentials=credentials, scopes=cls._OAUTH_SCOPES ) @property @@ -114,7 +108,7 @@ def analyze_sentiment(self): deserialized request object and returns a deserialized response object. """ - return self._stubs['language_service_stub'].AnalyzeSentiment + return self._stubs["language_service_stub"].AnalyzeSentiment @property def analyze_entities(self): @@ -129,7 +123,7 @@ def analyze_entities(self): deserialized request object and returns a deserialized response object. """ - return self._stubs['language_service_stub'].AnalyzeEntities + return self._stubs["language_service_stub"].AnalyzeEntities @property def analyze_entity_sentiment(self): @@ -143,7 +137,7 @@ def analyze_entity_sentiment(self): deserialized request object and returns a deserialized response object. """ - return self._stubs['language_service_stub'].AnalyzeEntitySentiment + return self._stubs["language_service_stub"].AnalyzeEntitySentiment @property def analyze_syntax(self): @@ -158,7 +152,7 @@ def analyze_syntax(self): deserialized request object and returns a deserialized response object. """ - return self._stubs['language_service_stub'].AnalyzeSyntax + return self._stubs["language_service_stub"].AnalyzeSyntax @property def classify_text(self): @@ -171,7 +165,7 @@ def classify_text(self): deserialized request object and returns a deserialized response object. """ - return self._stubs['language_service_stub'].ClassifyText + return self._stubs["language_service_stub"].ClassifyText @property def annotate_text(self): @@ -185,4 +179,4 @@ def annotate_text(self): deserialized request object and returns a deserialized response object. """ - return self._stubs['language_service_stub'].AnnotateText + return self._stubs["language_service_stub"].AnnotateText diff --git a/packages/google-cloud-language/google/cloud/language_v1beta2/types.py b/packages/google-cloud-language/google/cloud/language_v1beta2/types.py index f17b5a59dd96..1a33a23ef337 100644 --- a/packages/google-cloud-language/google/cloud/language_v1beta2/types.py +++ b/packages/google-cloud-language/google/cloud/language_v1beta2/types.py @@ -37,9 +37,7 @@ status_pb2, ] -_local_modules = [ - language_service_pb2, -] +_local_modules = [language_service_pb2] names = [] @@ -50,7 +48,7 @@ for module in _local_modules: for name, message in get_messages(module).items(): - message.__module__ = 'google.cloud.language_v1beta2.types' + message.__module__ = "google.cloud.language_v1beta2.types" setattr(sys.modules[__name__], name, message) names.append(name) diff --git a/packages/google-cloud-language/tests/system/gapic/v1/test_system_language_service_v1.py b/packages/google-cloud-language/tests/system/gapic/v1/test_system_language_service_v1.py index cd0be245b24a..cc5b439d4779 100644 --- a/packages/google-cloud-language/tests/system/gapic/v1/test_system_language_service_v1.py +++ b/packages/google-cloud-language/tests/system/gapic/v1/test_system_language_service_v1.py @@ -25,7 +25,7 @@ class TestSystemLanguageService(object): def test_analyze_sentiment(self): client = language_v1.LanguageServiceClient() - content = 'Hello, world!' + content = "Hello, world!" type_ = enums.Document.Type.PLAIN_TEXT - document = {'content': content, 'type': type_} + document = {"content": content, "type": type_} response = client.analyze_sentiment(document) diff --git a/packages/google-cloud-language/tests/system/gapic/v1beta2/test_system_language_service_v1beta2.py b/packages/google-cloud-language/tests/system/gapic/v1beta2/test_system_language_service_v1beta2.py index 751b3a568081..ec87655305de 100644 --- a/packages/google-cloud-language/tests/system/gapic/v1beta2/test_system_language_service_v1beta2.py +++ b/packages/google-cloud-language/tests/system/gapic/v1beta2/test_system_language_service_v1beta2.py @@ -25,7 +25,7 @@ class TestSystemLanguageService(object): def test_analyze_sentiment(self): client = language_v1beta2.LanguageServiceClient() - content = 'Hello, world!' + content = "Hello, world!" type_ = enums.Document.Type.PLAIN_TEXT - document = {'content': content, 'type': type_} + document = {"content": content, "type": type_} response = client.analyze_sentiment(document) diff --git a/packages/google-cloud-language/tests/unit/gapic/v1/test_language_service_client_v1.py b/packages/google-cloud-language/tests/unit/gapic/v1/test_language_service_client_v1.py index 6d2da21a14ba..c6cd31615f08 100644 --- a/packages/google-cloud-language/tests/unit/gapic/v1/test_language_service_client_v1.py +++ b/packages/google-cloud-language/tests/unit/gapic/v1/test_language_service_client_v1.py @@ -50,10 +50,7 @@ def __init__(self, responses=[]): self.responses = responses self.requests = [] - def unary_unary(self, - method, - request_serializer=None, - response_deserializer=None): + def unary_unary(self, method, request_serializer=None, response_deserializer=None): return MultiCallableStub(method, self) @@ -64,14 +61,15 @@ class CustomException(Exception): class TestLanguageServiceClient(object): def test_analyze_sentiment(self): # Setup Expected Response - language = 'language-1613589672' - expected_response = {'language': language} + language = "language-1613589672" + expected_response = {"language": language} expected_response = language_service_pb2.AnalyzeSentimentResponse( - **expected_response) + **expected_response + ) # Mock the API response channel = ChannelStub(responses=[expected_response]) - patch = mock.patch('google.api_core.grpc_helpers.create_channel') + patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = language_v1.LanguageServiceClient() @@ -84,14 +82,15 @@ def test_analyze_sentiment(self): assert len(channel.requests) == 1 expected_request = language_service_pb2.AnalyzeSentimentRequest( - document=document) + document=document + ) actual_request = channel.requests[0][1] assert expected_request == actual_request def test_analyze_sentiment_exception(self): # Mock the API response channel = ChannelStub(responses=[CustomException()]) - patch = mock.patch('google.api_core.grpc_helpers.create_channel') + patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = language_v1.LanguageServiceClient() @@ -104,14 +103,15 @@ def test_analyze_sentiment_exception(self): def test_analyze_entities(self): # Setup Expected Response - language = 'language-1613589672' - expected_response = {'language': language} + language = "language-1613589672" + expected_response = {"language": language} expected_response = language_service_pb2.AnalyzeEntitiesResponse( - **expected_response) + **expected_response + ) # Mock the API response channel = ChannelStub(responses=[expected_response]) - patch = mock.patch('google.api_core.grpc_helpers.create_channel') + patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = language_v1.LanguageServiceClient() @@ -124,14 +124,15 @@ def test_analyze_entities(self): assert len(channel.requests) == 1 expected_request = language_service_pb2.AnalyzeEntitiesRequest( - document=document) + document=document + ) actual_request = channel.requests[0][1] assert expected_request == actual_request def test_analyze_entities_exception(self): # Mock the API response channel = ChannelStub(responses=[CustomException()]) - patch = mock.patch('google.api_core.grpc_helpers.create_channel') + patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = language_v1.LanguageServiceClient() @@ -144,14 +145,15 @@ def test_analyze_entities_exception(self): def test_analyze_entity_sentiment(self): # Setup Expected Response - language = 'language-1613589672' - expected_response = {'language': language} + language = "language-1613589672" + expected_response = {"language": language} expected_response = language_service_pb2.AnalyzeEntitySentimentResponse( - **expected_response) + **expected_response + ) # Mock the API response channel = ChannelStub(responses=[expected_response]) - patch = mock.patch('google.api_core.grpc_helpers.create_channel') + patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = language_v1.LanguageServiceClient() @@ -164,14 +166,15 @@ def test_analyze_entity_sentiment(self): assert len(channel.requests) == 1 expected_request = language_service_pb2.AnalyzeEntitySentimentRequest( - document=document) + document=document + ) actual_request = channel.requests[0][1] assert expected_request == actual_request def test_analyze_entity_sentiment_exception(self): # Mock the API response channel = ChannelStub(responses=[CustomException()]) - patch = mock.patch('google.api_core.grpc_helpers.create_channel') + patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = language_v1.LanguageServiceClient() @@ -184,14 +187,15 @@ def test_analyze_entity_sentiment_exception(self): def test_analyze_syntax(self): # Setup Expected Response - language = 'language-1613589672' - expected_response = {'language': language} + language = "language-1613589672" + expected_response = {"language": language} expected_response = language_service_pb2.AnalyzeSyntaxResponse( - **expected_response) + **expected_response + ) # Mock the API response channel = ChannelStub(responses=[expected_response]) - patch = mock.patch('google.api_core.grpc_helpers.create_channel') + patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = language_v1.LanguageServiceClient() @@ -203,15 +207,14 @@ def test_analyze_syntax(self): assert expected_response == response assert len(channel.requests) == 1 - expected_request = language_service_pb2.AnalyzeSyntaxRequest( - document=document) + expected_request = language_service_pb2.AnalyzeSyntaxRequest(document=document) actual_request = channel.requests[0][1] assert expected_request == actual_request def test_analyze_syntax_exception(self): # Mock the API response channel = ChannelStub(responses=[CustomException()]) - patch = mock.patch('google.api_core.grpc_helpers.create_channel') + patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = language_v1.LanguageServiceClient() @@ -226,11 +229,12 @@ def test_classify_text(self): # Setup Expected Response expected_response = {} expected_response = language_service_pb2.ClassifyTextResponse( - **expected_response) + **expected_response + ) # Mock the API response channel = ChannelStub(responses=[expected_response]) - patch = mock.patch('google.api_core.grpc_helpers.create_channel') + patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = language_v1.LanguageServiceClient() @@ -242,15 +246,14 @@ def test_classify_text(self): assert expected_response == response assert len(channel.requests) == 1 - expected_request = language_service_pb2.ClassifyTextRequest( - document=document) + expected_request = language_service_pb2.ClassifyTextRequest(document=document) actual_request = channel.requests[0][1] assert expected_request == actual_request def test_classify_text_exception(self): # Mock the API response channel = ChannelStub(responses=[CustomException()]) - patch = mock.patch('google.api_core.grpc_helpers.create_channel') + patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = language_v1.LanguageServiceClient() @@ -263,14 +266,15 @@ def test_classify_text_exception(self): def test_annotate_text(self): # Setup Expected Response - language = 'language-1613589672' - expected_response = {'language': language} + language = "language-1613589672" + expected_response = {"language": language} expected_response = language_service_pb2.AnnotateTextResponse( - **expected_response) + **expected_response + ) # Mock the API response channel = ChannelStub(responses=[expected_response]) - patch = mock.patch('google.api_core.grpc_helpers.create_channel') + patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = language_v1.LanguageServiceClient() @@ -284,14 +288,15 @@ def test_annotate_text(self): assert len(channel.requests) == 1 expected_request = language_service_pb2.AnnotateTextRequest( - document=document, features=features) + document=document, features=features + ) actual_request = channel.requests[0][1] assert expected_request == actual_request def test_annotate_text_exception(self): # Mock the API response channel = ChannelStub(responses=[CustomException()]) - patch = mock.patch('google.api_core.grpc_helpers.create_channel') + patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = language_v1.LanguageServiceClient() diff --git a/packages/google-cloud-language/tests/unit/gapic/v1beta2/test_language_service_client_v1beta2.py b/packages/google-cloud-language/tests/unit/gapic/v1beta2/test_language_service_client_v1beta2.py index 920ee01b15b9..90a30b642aa2 100644 --- a/packages/google-cloud-language/tests/unit/gapic/v1beta2/test_language_service_client_v1beta2.py +++ b/packages/google-cloud-language/tests/unit/gapic/v1beta2/test_language_service_client_v1beta2.py @@ -50,10 +50,7 @@ def __init__(self, responses=[]): self.responses = responses self.requests = [] - def unary_unary(self, - method, - request_serializer=None, - response_deserializer=None): + def unary_unary(self, method, request_serializer=None, response_deserializer=None): return MultiCallableStub(method, self) @@ -64,14 +61,15 @@ class CustomException(Exception): class TestLanguageServiceClient(object): def test_analyze_sentiment(self): # Setup Expected Response - language = 'language-1613589672' - expected_response = {'language': language} + language = "language-1613589672" + expected_response = {"language": language} expected_response = language_service_pb2.AnalyzeSentimentResponse( - **expected_response) + **expected_response + ) # Mock the API response channel = ChannelStub(responses=[expected_response]) - patch = mock.patch('google.api_core.grpc_helpers.create_channel') + patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = language_v1beta2.LanguageServiceClient() @@ -84,14 +82,15 @@ def test_analyze_sentiment(self): assert len(channel.requests) == 1 expected_request = language_service_pb2.AnalyzeSentimentRequest( - document=document) + document=document + ) actual_request = channel.requests[0][1] assert expected_request == actual_request def test_analyze_sentiment_exception(self): # Mock the API response channel = ChannelStub(responses=[CustomException()]) - patch = mock.patch('google.api_core.grpc_helpers.create_channel') + patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = language_v1beta2.LanguageServiceClient() @@ -104,14 +103,15 @@ def test_analyze_sentiment_exception(self): def test_analyze_entities(self): # Setup Expected Response - language = 'language-1613589672' - expected_response = {'language': language} + language = "language-1613589672" + expected_response = {"language": language} expected_response = language_service_pb2.AnalyzeEntitiesResponse( - **expected_response) + **expected_response + ) # Mock the API response channel = ChannelStub(responses=[expected_response]) - patch = mock.patch('google.api_core.grpc_helpers.create_channel') + patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = language_v1beta2.LanguageServiceClient() @@ -124,14 +124,15 @@ def test_analyze_entities(self): assert len(channel.requests) == 1 expected_request = language_service_pb2.AnalyzeEntitiesRequest( - document=document) + document=document + ) actual_request = channel.requests[0][1] assert expected_request == actual_request def test_analyze_entities_exception(self): # Mock the API response channel = ChannelStub(responses=[CustomException()]) - patch = mock.patch('google.api_core.grpc_helpers.create_channel') + patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = language_v1beta2.LanguageServiceClient() @@ -144,14 +145,15 @@ def test_analyze_entities_exception(self): def test_analyze_entity_sentiment(self): # Setup Expected Response - language = 'language-1613589672' - expected_response = {'language': language} + language = "language-1613589672" + expected_response = {"language": language} expected_response = language_service_pb2.AnalyzeEntitySentimentResponse( - **expected_response) + **expected_response + ) # Mock the API response channel = ChannelStub(responses=[expected_response]) - patch = mock.patch('google.api_core.grpc_helpers.create_channel') + patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = language_v1beta2.LanguageServiceClient() @@ -164,14 +166,15 @@ def test_analyze_entity_sentiment(self): assert len(channel.requests) == 1 expected_request = language_service_pb2.AnalyzeEntitySentimentRequest( - document=document) + document=document + ) actual_request = channel.requests[0][1] assert expected_request == actual_request def test_analyze_entity_sentiment_exception(self): # Mock the API response channel = ChannelStub(responses=[CustomException()]) - patch = mock.patch('google.api_core.grpc_helpers.create_channel') + patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = language_v1beta2.LanguageServiceClient() @@ -184,14 +187,15 @@ def test_analyze_entity_sentiment_exception(self): def test_analyze_syntax(self): # Setup Expected Response - language = 'language-1613589672' - expected_response = {'language': language} + language = "language-1613589672" + expected_response = {"language": language} expected_response = language_service_pb2.AnalyzeSyntaxResponse( - **expected_response) + **expected_response + ) # Mock the API response channel = ChannelStub(responses=[expected_response]) - patch = mock.patch('google.api_core.grpc_helpers.create_channel') + patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = language_v1beta2.LanguageServiceClient() @@ -203,15 +207,14 @@ def test_analyze_syntax(self): assert expected_response == response assert len(channel.requests) == 1 - expected_request = language_service_pb2.AnalyzeSyntaxRequest( - document=document) + expected_request = language_service_pb2.AnalyzeSyntaxRequest(document=document) actual_request = channel.requests[0][1] assert expected_request == actual_request def test_analyze_syntax_exception(self): # Mock the API response channel = ChannelStub(responses=[CustomException()]) - patch = mock.patch('google.api_core.grpc_helpers.create_channel') + patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = language_v1beta2.LanguageServiceClient() @@ -226,11 +229,12 @@ def test_classify_text(self): # Setup Expected Response expected_response = {} expected_response = language_service_pb2.ClassifyTextResponse( - **expected_response) + **expected_response + ) # Mock the API response channel = ChannelStub(responses=[expected_response]) - patch = mock.patch('google.api_core.grpc_helpers.create_channel') + patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = language_v1beta2.LanguageServiceClient() @@ -242,15 +246,14 @@ def test_classify_text(self): assert expected_response == response assert len(channel.requests) == 1 - expected_request = language_service_pb2.ClassifyTextRequest( - document=document) + expected_request = language_service_pb2.ClassifyTextRequest(document=document) actual_request = channel.requests[0][1] assert expected_request == actual_request def test_classify_text_exception(self): # Mock the API response channel = ChannelStub(responses=[CustomException()]) - patch = mock.patch('google.api_core.grpc_helpers.create_channel') + patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = language_v1beta2.LanguageServiceClient() @@ -263,14 +266,15 @@ def test_classify_text_exception(self): def test_annotate_text(self): # Setup Expected Response - language = 'language-1613589672' - expected_response = {'language': language} + language = "language-1613589672" + expected_response = {"language": language} expected_response = language_service_pb2.AnnotateTextResponse( - **expected_response) + **expected_response + ) # Mock the API response channel = ChannelStub(responses=[expected_response]) - patch = mock.patch('google.api_core.grpc_helpers.create_channel') + patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = language_v1beta2.LanguageServiceClient() @@ -284,14 +288,15 @@ def test_annotate_text(self): assert len(channel.requests) == 1 expected_request = language_service_pb2.AnnotateTextRequest( - document=document, features=features) + document=document, features=features + ) actual_request = channel.requests[0][1] assert expected_request == actual_request def test_annotate_text_exception(self): # Mock the API response channel = ChannelStub(responses=[CustomException()]) - patch = mock.patch('google.api_core.grpc_helpers.create_channel') + patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = language_v1beta2.LanguageServiceClient()