Skip to content

Commit 43f5dd9

Browse files
telpirionholtskinner
authored andcommitted
samples: more updates for v1 (#121)
* samples: more updates for v1 * fix: lint * fix: tests * fix: tests * fix: tests
1 parent 513026f commit 43f5dd9

12 files changed

+40
-34
lines changed

batch_parse_form_v1beta2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def batch_parse_form(
2424
project_id="YOUR_PROJECT_ID",
2525
input_uri="gs://cloud-samples-data/documentai/form.pdf",
2626
destination_uri="gs://your-bucket-id/path/to/save/results/",
27-
timeout=90
27+
timeout=90,
2828
):
2929
"""Parse a form"""
3030

batch_parse_form_v1beta2_test.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ def setup_teardown():
4141

4242

4343
def test_batch_parse_form(capsys):
44-
batch_parse_form_v1beta2.batch_parse_form(PROJECT_ID, INPUT_URI, BATCH_OUTPUT_URI, 120)
44+
batch_parse_form_v1beta2.batch_parse_form(
45+
PROJECT_ID, INPUT_URI, BATCH_OUTPUT_URI, 120
46+
)
4547
out, _ = capsys.readouterr()
4648
assert "Output files" in out

batch_parse_table_v1beta2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def batch_parse_table(
2424
project_id="YOUR_PROJECT_ID",
2525
input_uri="gs://cloud-samples-data/documentai/form.pdf",
2626
destination_uri="gs://your-bucket-id/path/to/save/results/",
27-
timeout=90
27+
timeout=90,
2828
):
2929
"""Parse a form"""
3030

batch_parse_table_v1beta2_test.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ def setup_teardown():
4141

4242

4343
def test_batch_parse_table(capsys):
44-
batch_parse_table_v1beta2.batch_parse_table(PROJECT_ID, INPUT_URI, BATCH_OUTPUT_URI, 120)
44+
batch_parse_table_v1beta2.batch_parse_table(
45+
PROJECT_ID, INPUT_URI, BATCH_OUTPUT_URI, 120
46+
)
4547
out, _ = capsys.readouterr()
4648
assert "Output files:" in out

batch_process_documents_sample_bad_input_v1beta3_test.py renamed to batch_process_documents_sample_bad_input_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import os
1717
from uuid import uuid4
1818

19-
from samples.snippets import batch_process_documents_sample_v1beta3
19+
from samples.snippets import batch_process_documents_sample
2020

2121
location = "us"
2222
project_id = os.getenv("GOOGLE_CLOUD_PROJECT")
@@ -29,7 +29,7 @@
2929

3030
def test_batch_process_documents_with_bad_input(capsys):
3131
try:
32-
batch_process_documents_sample_v1beta3.batch_process_documents(
32+
batch_process_documents_sample.batch_process_documents(
3333
project_id=project_id,
3434
location=location,
3535
processor_id=processor_id,

batch_process_documents_sample_v1beta3_test.py renamed to batch_process_documents_sample_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
import pytest
2323

24-
from samples.snippets import batch_process_documents_sample_v1beta3
24+
from samples.snippets import batch_process_documents_sample
2525

2626
location = "us"
2727
project_id = os.environ["GOOGLE_CLOUD_PROJECT"]
@@ -47,7 +47,7 @@ def test_bucket():
4747

4848

4949
def test_batch_process_documents(capsys, test_bucket):
50-
batch_process_documents_sample_v1beta3.batch_process_documents(
50+
batch_process_documents_sample.batch_process_documents(
5151
project_id=project_id,
5252
location=location,
5353
processor_id=processor_id,

noxfile.py

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,28 +38,25 @@
3838

3939
TEST_CONFIG = {
4040
# You can opt out from the test for specific Python versions.
41-
'ignored_versions': ["2.7"],
42-
41+
"ignored_versions": ["2.7"],
4342
# Old samples are opted out of enforcing Python type hints
4443
# All new samples should feature them
45-
'enforce_type_hints': False,
46-
44+
"enforce_type_hints": False,
4745
# An envvar key for determining the project id to use. Change it
4846
# to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a
4947
# build specific Cloud project. You can also use your own string
5048
# to use your own Cloud project.
51-
'gcloud_project_env': 'GOOGLE_CLOUD_PROJECT',
49+
"gcloud_project_env": "GOOGLE_CLOUD_PROJECT",
5250
# 'gcloud_project_env': 'BUILD_SPECIFIC_GCLOUD_PROJECT',
53-
5451
# A dictionary you want to inject into your test. Don't put any
5552
# secrets here. These values will override predefined values.
56-
'envs': {},
53+
"envs": {},
5754
}
5855

5956

6057
try:
6158
# Ensure we can import noxfile_config in the project's directory.
62-
sys.path.append('.')
59+
sys.path.append(".")
6360
from noxfile_config import TEST_CONFIG_OVERRIDE
6461
except ImportError as e:
6562
print("No user noxfile_config found: detail: {}".format(e))
@@ -74,12 +71,12 @@ def get_pytest_env_vars() -> Dict[str, str]:
7471
ret = {}
7572

7673
# Override the GCLOUD_PROJECT and the alias.
77-
env_key = TEST_CONFIG['gcloud_project_env']
74+
env_key = TEST_CONFIG["gcloud_project_env"]
7875
# This should error out if not set.
79-
ret['GOOGLE_CLOUD_PROJECT'] = os.environ[env_key]
76+
ret["GOOGLE_CLOUD_PROJECT"] = os.environ[env_key]
8077

8178
# Apply user supplied envs.
82-
ret.update(TEST_CONFIG['envs'])
79+
ret.update(TEST_CONFIG["envs"])
8380
return ret
8481

8582

@@ -88,7 +85,7 @@ def get_pytest_env_vars() -> Dict[str, str]:
8885
ALL_VERSIONS = ["2.7", "3.6", "3.7", "3.8", "3.9"]
8986

9087
# Any default versions that should be ignored.
91-
IGNORED_VERSIONS = TEST_CONFIG['ignored_versions']
88+
IGNORED_VERSIONS = TEST_CONFIG["ignored_versions"]
9289

9390
TESTED_VERSIONS = sorted([v for v in ALL_VERSIONS if v not in IGNORED_VERSIONS])
9491

@@ -137,7 +134,7 @@ def _determine_local_import_names(start_dir: str) -> List[str]:
137134

138135
@nox.session
139136
def lint(session: nox.sessions.Session) -> None:
140-
if not TEST_CONFIG['enforce_type_hints']:
137+
if not TEST_CONFIG["enforce_type_hints"]:
141138
session.install("flake8", "flake8-import-order")
142139
else:
143140
session.install("flake8", "flake8-import-order", "flake8-annotations")
@@ -146,9 +143,11 @@ def lint(session: nox.sessions.Session) -> None:
146143
args = FLAKE8_COMMON_ARGS + [
147144
"--application-import-names",
148145
",".join(local_names),
149-
"."
146+
".",
150147
]
151148
session.run("flake8", *args)
149+
150+
152151
#
153152
# Black
154153
#
@@ -161,6 +160,7 @@ def blacken(session: nox.sessions.Session) -> None:
161160

162161
session.run("black", *python_files)
163162

163+
164164
#
165165
# Sample Tests
166166
#
@@ -169,7 +169,9 @@ def blacken(session: nox.sessions.Session) -> None:
169169
PYTEST_COMMON_ARGS = ["--junitxml=sponge_log.xml"]
170170

171171

172-
def _session_tests(session: nox.sessions.Session, post_install: Callable = None) -> None:
172+
def _session_tests(
173+
session: nox.sessions.Session, post_install: Callable = None
174+
) -> None:
173175
"""Runs py.test for a particular project."""
174176
if os.path.exists("requirements.txt"):
175177
session.install("-r", "requirements.txt")
@@ -200,9 +202,9 @@ def py(session: nox.sessions.Session) -> None:
200202
if session.python in TESTED_VERSIONS:
201203
_session_tests(session)
202204
else:
203-
session.skip("SKIPPED: {} tests are disabled for this sample.".format(
204-
session.python
205-
))
205+
session.skip(
206+
"SKIPPED: {} tests are disabled for this sample.".format(session.python)
207+
)
206208

207209

208210
#

process_document_sample_v1beta3.py renamed to process_document_sample.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
def process_document_sample(
2626
project_id: str, location: str, processor_id: str, file_path: str
2727
):
28-
from google.cloud import documentai_v1beta3 as documentai
28+
from google.cloud import documentai_v1 as documentai
2929

3030
# You must set the api_endpoint if you use a location other than 'us', e.g.:
3131
opts = {}
@@ -46,7 +46,7 @@ def process_document_sample(
4646
document = {"content": image_content, "mime_type": "application/pdf"}
4747

4848
# Configure the process request
49-
request = {"name": name, "document": document}
49+
request = {"name": name, "raw_document": document}
5050

5151
# Recognizes text entities in the PDF document
5252
result = client.process_document(request=request)

process_document_sample_v1beta3_test.py renamed to process_document_sample_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
import os
1717

18-
from samples.snippets import process_document_sample_v1beta3
18+
from samples.snippets import process_document_sample
1919

2020

2121
location = "us"
@@ -25,7 +25,7 @@
2525

2626

2727
def test_process_documents(capsys):
28-
process_document_sample_v1beta3.process_document_sample(
28+
process_document_sample.process_document_sample(
2929
project_id=project_id,
3030
location=location,
3131
processor_id=processor_id,

quickstart_sample_v1beta3.py renamed to quickstart_sample.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414
#
1515

16-
from google.cloud import documentai_v1beta3 as documentai
16+
from google.cloud import documentai_v1 as documentai
1717

1818
# [START documentai_quickstart]
1919

@@ -45,7 +45,7 @@ def quickstart(project_id: str, location: str, processor_id: str, file_path: str
4545
document = {"content": image_content, "mime_type": "application/pdf"}
4646

4747
# Configure the process request
48-
request = {"name": name, "document": document}
48+
request = {"name": name, "raw_document": document}
4949

5050
result = client.process_document(request=request)
5151
document = result.document

quickstart_sample_v1beta3_test.py renamed to quickstart_sample_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
import os
1717

18-
from samples.snippets import quickstart_sample_v1beta3
18+
from samples.snippets import quickstart_sample
1919

2020
location = "us"
2121
project_id = os.environ["GOOGLE_CLOUD_PROJECT"]
@@ -24,7 +24,7 @@
2424

2525

2626
def test_quickstart(capsys):
27-
quickstart_sample_v1beta3.quickstart(
27+
quickstart_sample.quickstart(
2828
project_id=project_id,
2929
location=location,
3030
processor_id=processor_id,

0 commit comments

Comments
 (0)