diff --git a/documentai/snippets/batch_parse_form_v1beta2.py b/documentai/snippets/batch_parse_form_v1beta2.py index ae60fd6334ba..a3220b4aa5f9 100644 --- a/documentai/snippets/batch_parse_form_v1beta2.py +++ b/documentai/snippets/batch_parse_form_v1beta2.py @@ -24,7 +24,7 @@ def batch_parse_form( project_id="YOUR_PROJECT_ID", input_uri="gs://cloud-samples-data/documentai/form.pdf", destination_uri="gs://your-bucket-id/path/to/save/results/", - timeout=90 + timeout=90, ): """Parse a form""" diff --git a/documentai/snippets/batch_parse_form_v1beta2_test.py b/documentai/snippets/batch_parse_form_v1beta2_test.py index 6abd19a20559..f42cb249c040 100644 --- a/documentai/snippets/batch_parse_form_v1beta2_test.py +++ b/documentai/snippets/batch_parse_form_v1beta2_test.py @@ -41,6 +41,8 @@ def setup_teardown(): def test_batch_parse_form(capsys): - batch_parse_form_v1beta2.batch_parse_form(PROJECT_ID, INPUT_URI, BATCH_OUTPUT_URI, 120) + batch_parse_form_v1beta2.batch_parse_form( + PROJECT_ID, INPUT_URI, BATCH_OUTPUT_URI, 120 + ) out, _ = capsys.readouterr() assert "Output files" in out diff --git a/documentai/snippets/batch_parse_table_v1beta2.py b/documentai/snippets/batch_parse_table_v1beta2.py index f62495b4f340..16851437c14b 100644 --- a/documentai/snippets/batch_parse_table_v1beta2.py +++ b/documentai/snippets/batch_parse_table_v1beta2.py @@ -24,7 +24,7 @@ def batch_parse_table( project_id="YOUR_PROJECT_ID", input_uri="gs://cloud-samples-data/documentai/form.pdf", destination_uri="gs://your-bucket-id/path/to/save/results/", - timeout=90 + timeout=90, ): """Parse a form""" diff --git a/documentai/snippets/batch_parse_table_v1beta2_test.py b/documentai/snippets/batch_parse_table_v1beta2_test.py index aa8905208500..0818d8c00e0e 100644 --- a/documentai/snippets/batch_parse_table_v1beta2_test.py +++ b/documentai/snippets/batch_parse_table_v1beta2_test.py @@ -41,6 +41,8 @@ def setup_teardown(): def test_batch_parse_table(capsys): - batch_parse_table_v1beta2.batch_parse_table(PROJECT_ID, INPUT_URI, BATCH_OUTPUT_URI, 120) + batch_parse_table_v1beta2.batch_parse_table( + PROJECT_ID, INPUT_URI, BATCH_OUTPUT_URI, 120 + ) out, _ = capsys.readouterr() assert "Output files:" in out diff --git a/documentai/snippets/batch_process_documents_sample_v1beta3.py b/documentai/snippets/batch_process_documents_sample.py similarity index 100% rename from documentai/snippets/batch_process_documents_sample_v1beta3.py rename to documentai/snippets/batch_process_documents_sample.py diff --git a/documentai/snippets/batch_process_documents_sample_bad_input_v1beta3_test.py b/documentai/snippets/batch_process_documents_sample_bad_input_test.py similarity index 91% rename from documentai/snippets/batch_process_documents_sample_bad_input_v1beta3_test.py rename to documentai/snippets/batch_process_documents_sample_bad_input_test.py index e0a7e4689dde..77440c9c03c0 100644 --- a/documentai/snippets/batch_process_documents_sample_bad_input_v1beta3_test.py +++ b/documentai/snippets/batch_process_documents_sample_bad_input_test.py @@ -16,7 +16,7 @@ import os from uuid import uuid4 -from samples.snippets import batch_process_documents_sample_v1beta3 +from samples.snippets import batch_process_documents_sample location = "us" project_id = os.getenv("GOOGLE_CLOUD_PROJECT") @@ -29,7 +29,7 @@ def test_batch_process_documents_with_bad_input(capsys): try: - batch_process_documents_sample_v1beta3.batch_process_documents( + batch_process_documents_sample.batch_process_documents( project_id=project_id, location=location, processor_id=processor_id, diff --git a/documentai/snippets/batch_process_documents_sample_v1beta3_test.py b/documentai/snippets/batch_process_documents_sample_test.py similarity index 92% rename from documentai/snippets/batch_process_documents_sample_v1beta3_test.py rename to documentai/snippets/batch_process_documents_sample_test.py index dcb63567d035..7168d5a77fd4 100644 --- a/documentai/snippets/batch_process_documents_sample_v1beta3_test.py +++ b/documentai/snippets/batch_process_documents_sample_test.py @@ -21,7 +21,7 @@ import pytest -from samples.snippets import batch_process_documents_sample_v1beta3 +from samples.snippets import batch_process_documents_sample location = "us" project_id = os.environ["GOOGLE_CLOUD_PROJECT"] @@ -47,7 +47,7 @@ def test_bucket(): def test_batch_process_documents(capsys, test_bucket): - batch_process_documents_sample_v1beta3.batch_process_documents( + batch_process_documents_sample.batch_process_documents( project_id=project_id, location=location, processor_id=processor_id, diff --git a/documentai/snippets/noxfile.py b/documentai/snippets/noxfile.py index 97bf7da80e39..f2320ea0001c 100644 --- a/documentai/snippets/noxfile.py +++ b/documentai/snippets/noxfile.py @@ -38,28 +38,25 @@ TEST_CONFIG = { # You can opt out from the test for specific Python versions. - 'ignored_versions': ["2.7"], - + "ignored_versions": ["2.7"], # Old samples are opted out of enforcing Python type hints # All new samples should feature them - 'enforce_type_hints': False, - + "enforce_type_hints": False, # An envvar key for determining the project id to use. Change it # to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a # build specific Cloud project. You can also use your own string # to use your own Cloud project. - 'gcloud_project_env': 'GOOGLE_CLOUD_PROJECT', + "gcloud_project_env": "GOOGLE_CLOUD_PROJECT", # 'gcloud_project_env': 'BUILD_SPECIFIC_GCLOUD_PROJECT', - # A dictionary you want to inject into your test. Don't put any # secrets here. These values will override predefined values. - 'envs': {}, + "envs": {}, } try: # Ensure we can import noxfile_config in the project's directory. - sys.path.append('.') + sys.path.append(".") from noxfile_config import TEST_CONFIG_OVERRIDE except ImportError as e: print("No user noxfile_config found: detail: {}".format(e)) @@ -74,12 +71,12 @@ def get_pytest_env_vars() -> Dict[str, str]: ret = {} # Override the GCLOUD_PROJECT and the alias. - env_key = TEST_CONFIG['gcloud_project_env'] + env_key = TEST_CONFIG["gcloud_project_env"] # This should error out if not set. - ret['GOOGLE_CLOUD_PROJECT'] = os.environ[env_key] + ret["GOOGLE_CLOUD_PROJECT"] = os.environ[env_key] # Apply user supplied envs. - ret.update(TEST_CONFIG['envs']) + ret.update(TEST_CONFIG["envs"]) return ret @@ -88,7 +85,7 @@ def get_pytest_env_vars() -> Dict[str, str]: ALL_VERSIONS = ["2.7", "3.6", "3.7", "3.8", "3.9"] # Any default versions that should be ignored. -IGNORED_VERSIONS = TEST_CONFIG['ignored_versions'] +IGNORED_VERSIONS = TEST_CONFIG["ignored_versions"] TESTED_VERSIONS = sorted([v for v in ALL_VERSIONS if v not in IGNORED_VERSIONS]) @@ -137,7 +134,7 @@ def _determine_local_import_names(start_dir: str) -> List[str]: @nox.session def lint(session: nox.sessions.Session) -> None: - if not TEST_CONFIG['enforce_type_hints']: + if not TEST_CONFIG["enforce_type_hints"]: session.install("flake8", "flake8-import-order") else: session.install("flake8", "flake8-import-order", "flake8-annotations") @@ -146,9 +143,11 @@ def lint(session: nox.sessions.Session) -> None: args = FLAKE8_COMMON_ARGS + [ "--application-import-names", ",".join(local_names), - "." + ".", ] session.run("flake8", *args) + + # # Black # @@ -161,6 +160,7 @@ def blacken(session: nox.sessions.Session) -> None: session.run("black", *python_files) + # # Sample Tests # @@ -169,7 +169,9 @@ def blacken(session: nox.sessions.Session) -> None: PYTEST_COMMON_ARGS = ["--junitxml=sponge_log.xml"] -def _session_tests(session: nox.sessions.Session, post_install: Callable = None) -> None: +def _session_tests( + session: nox.sessions.Session, post_install: Callable = None +) -> None: """Runs py.test for a particular project.""" if os.path.exists("requirements.txt"): session.install("-r", "requirements.txt") @@ -200,9 +202,9 @@ def py(session: nox.sessions.Session) -> None: if session.python in TESTED_VERSIONS: _session_tests(session) else: - session.skip("SKIPPED: {} tests are disabled for this sample.".format( - session.python - )) + session.skip( + "SKIPPED: {} tests are disabled for this sample.".format(session.python) + ) # diff --git a/documentai/snippets/process_document_sample_v1beta3.py b/documentai/snippets/process_document_sample.py similarity index 96% rename from documentai/snippets/process_document_sample_v1beta3.py rename to documentai/snippets/process_document_sample.py index ab69d073e6d6..b9fbe87b6dd6 100644 --- a/documentai/snippets/process_document_sample_v1beta3.py +++ b/documentai/snippets/process_document_sample.py @@ -25,7 +25,7 @@ def process_document_sample( project_id: str, location: str, processor_id: str, file_path: str ): - from google.cloud import documentai_v1beta3 as documentai + from google.cloud import documentai_v1 as documentai # You must set the api_endpoint if you use a location other than 'us', e.g.: opts = {} @@ -46,7 +46,7 @@ def process_document_sample( document = {"content": image_content, "mime_type": "application/pdf"} # Configure the process request - request = {"name": name, "document": document} + request = {"name": name, "raw_document": document} # Recognizes text entities in the PDF document result = client.process_document(request=request) diff --git a/documentai/snippets/process_document_sample_v1beta3_test.py b/documentai/snippets/process_document_sample_test.py similarity index 88% rename from documentai/snippets/process_document_sample_v1beta3_test.py rename to documentai/snippets/process_document_sample_test.py index 58b11b22ba45..8fe188d8da8f 100644 --- a/documentai/snippets/process_document_sample_v1beta3_test.py +++ b/documentai/snippets/process_document_sample_test.py @@ -15,7 +15,7 @@ import os -from samples.snippets import process_document_sample_v1beta3 +from samples.snippets import process_document_sample location = "us" @@ -25,7 +25,7 @@ def test_process_documents(capsys): - process_document_sample_v1beta3.process_document_sample( + process_document_sample.process_document_sample( project_id=project_id, location=location, processor_id=processor_id, diff --git a/documentai/snippets/quickstart_sample_v1beta3.py b/documentai/snippets/quickstart_sample.py similarity index 96% rename from documentai/snippets/quickstart_sample_v1beta3.py rename to documentai/snippets/quickstart_sample.py index 884b412cf63c..2e4ef103e3f7 100644 --- a/documentai/snippets/quickstart_sample_v1beta3.py +++ b/documentai/snippets/quickstart_sample.py @@ -13,7 +13,7 @@ # limitations under the License. # -from google.cloud import documentai_v1beta3 as documentai +from google.cloud import documentai_v1 as documentai # [START documentai_quickstart] @@ -45,7 +45,7 @@ def quickstart(project_id: str, location: str, processor_id: str, file_path: str document = {"content": image_content, "mime_type": "application/pdf"} # Configure the process request - request = {"name": name, "document": document} + request = {"name": name, "raw_document": document} result = client.process_document(request=request) document = result.document diff --git a/documentai/snippets/quickstart_sample_v1beta3_test.py b/documentai/snippets/quickstart_sample_test.py similarity index 90% rename from documentai/snippets/quickstart_sample_v1beta3_test.py rename to documentai/snippets/quickstart_sample_test.py index 4badc1f7111a..afeeface72a6 100644 --- a/documentai/snippets/quickstart_sample_v1beta3_test.py +++ b/documentai/snippets/quickstart_sample_test.py @@ -15,7 +15,7 @@ import os -from samples.snippets import quickstart_sample_v1beta3 +from samples.snippets import quickstart_sample location = "us" project_id = os.environ["GOOGLE_CLOUD_PROJECT"] @@ -24,7 +24,7 @@ def test_quickstart(capsys): - quickstart_sample_v1beta3.quickstart( + quickstart_sample.quickstart( project_id=project_id, location=location, processor_id=processor_id,