Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
additional fixes, wire in cloud-samples-data into detect tests.
  • Loading branch information
shollyman committed Feb 6, 2019
commit b918ae3be4dd5e19d0989fda1e295e5c23faea45
55 changes: 29 additions & 26 deletions vision/cloud-client/detect/detect_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import detect

ASSET_BUCKET = "cloud-samples-data"

BUCKET = os.environ['CLOUD_STORAGE_BUCKET']
OUTPUT_PREFIX = 'OCR_PDF_TEST_OUTPUT'
GCS_SOURCE_URI = 'gs://{}/HodgeConj.pdf'.format(BUCKET)
GCS_DESTINATION_URI = 'gs://{}/{}/'.format(BUCKET, OUTPUT_PREFIX)
Expand All @@ -34,15 +36,15 @@ def test_labels(capsys):


def test_labels_uri(capsys):
file_name = 'gs://{}/vision/wakeupcat.jpg'.format(BUCKET)
file_name = 'gs://{}/vision/wakeupcat.jpg'.format(ASSET_BUCKET)
detect.detect_labels_uri(file_name)
out, _ = capsys.readouterr()
assert 'Labels' in out


def test_labels_http(capsys):
uri = 'https://storage-download.googleapis.com/{}/vision/label/wakeupcat.jpg'
detect.detect_labels_uri(uri.format(BUCKET))
detect.detect_labels_uri(uri.format(ASSET_BUCKET))
out, _ = capsys.readouterr()
assert 'Labels' in out

Expand All @@ -57,15 +59,15 @@ def test_landmarks(capsys):


def test_landmarks_uri(capsys):
file_name = 'gs://{}/vision/landmark.jpg'.format(BUCKET)
file_name = 'gs://{}/vision/landmark/pofa.jpg'.format(ASSET_BUCKET)
detect.detect_landmarks_uri(file_name)
out, _ = capsys.readouterr()
assert 'palace' in out.lower()


def test_landmarks_http(capsys):
uri = 'https://storage-download.googleapis.com/{}/vision/landmark/pofa.jpg'
detect.detect_landmarks_uri(uri.format(BUCKET))
detect.detect_landmarks_uri(uri.format(ASSET_BUCKET))
out, _ = capsys.readouterr()
assert 'palace' in out.lower()

Expand All @@ -80,7 +82,7 @@ def test_faces(capsys):


def test_faces_uri(capsys):
file_name = 'gs://{}/vision/face/face_no_surprise.jpg'.format(BUCKET)
file_name = 'gs://{}/vision/face/face_no_surprise.jpg'.format(ASSET_BUCKET)
detect.detect_faces_uri(file_name)
out, _ = capsys.readouterr()
assert 'POSSIBLE' in out
Expand All @@ -89,7 +91,7 @@ def test_faces_uri(capsys):
def test_faces_http(capsys):
uri = ('https://storage-download.googleapis.com/{}/vision/' +
'face/face_no_surprise.jpg')
detect.detect_faces_uri(uri.format(BUCKET))
detect.detect_faces_uri(uri.format(ASSET_BUCKET))
out, _ = capsys.readouterr()
assert 'POSSIBLE' in out

Expand All @@ -104,15 +106,15 @@ def test_logos(capsys):


def test_logos_uri(capsys):
file_name = 'gs://{}/vision/logo/logo_google.png'.format(BUCKET)
file_name = 'gs://{}/vision/logo/logo_google.png'.format(ASSET_BUCKET)
detect.detect_logos_uri(file_name)
out, _ = capsys.readouterr()
assert 'google' in out.lower()


def test_logos_http(capsys):
uri = 'https://storage-download.googleapis.com/{}/vision/logo/logo_google.png'
detect.detect_logos_uri(uri.format(BUCKET))
detect.detect_logos_uri(uri.format(ASSET_BUCKET))
out, _ = capsys.readouterr()
assert 'google' in out.lower()

Expand All @@ -128,7 +130,7 @@ def test_safe_search(capsys):


def test_safe_search_uri(capsys):
file_name = 'gs://{}/vision/label/wakeupcat.jpg'.format(BUCKET)
file_name = 'gs://{}/vision/label/wakeupcat.jpg'.format(ASSET_BUCKET)
detect.detect_safe_search_uri(file_name)
out, _ = capsys.readouterr()
assert 'VERY_LIKELY' in out
Expand All @@ -137,7 +139,7 @@ def test_safe_search_uri(capsys):

def test_safe_search_http(capsys):
uri = 'https://storage-download.googleapis.com/{}/vision/label/wakeupcat.jpg'
detect.detect_safe_search_uri(uri.format(BUCKET))
detect.detect_safe_search_uri(uri.format(ASSET_BUCKET))
out, _ = capsys.readouterr()
assert 'VERY_LIKELY' in out
assert 'racy: ' in out
Expand All @@ -153,15 +155,15 @@ def test_detect_text(capsys):


def test_detect_text_uri(capsys):
file_name = 'gs://{}/vision/text/screen.jpg'.format(BUCKET)
file_name = 'gs://{}/vision/text/screen.jpg'.format(ASSET_BUCKET)
detect.detect_text_uri(file_name)
out, _ = capsys.readouterr()
assert '37%' in out


def test_detect_text_http(capsys):
uri = 'https://storage-download.googleapis.com/{}/vision/text/screen.jpg'
detect.detect_text_uri(uri.format(BUCKET))
detect.detect_text_uri(uri.format(ASSET_BUCKET))
out, _ = capsys.readouterr()
assert '37%' in out

Expand All @@ -176,15 +178,15 @@ def test_detect_properties(capsys):


def test_detect_properties_uri(capsys):
file_name = 'gs://{}/vision/landmark/pofa.jpg'.format(BUCKET)
file_name = 'gs://{}/vision/landmark/pofa.jpg'.format(ASSET_BUCKET)
detect.detect_properties_uri(file_name)
out, _ = capsys.readouterr()
assert 'frac' in out


def test_detect_properties_http(capsys):
uri = 'https://storage-download.googleapis.com/{}/vision/landmark/pofa.jpg'
detect.detect_properties_uri(uri.format(BUCKET))
detect.detect_properties_uri(uri.format(ASSET_BUCKET))
out, _ = capsys.readouterr()
assert 'frac' in out

Expand All @@ -200,15 +202,15 @@ def test_detect_web(capsys):


def test_detect_web_uri(capsys):
file_name = 'gs://{}/vision/landmark/pofa.jpg'.format(BUCKET)
file_name = 'gs://{}/vision/landmark/pofa.jpg'.format(ASSET_BUCKET)
detect.detect_web_uri(file_name)
out, _ = capsys.readouterr()
assert 'best guess label: palace of fine arts' in out.lower()


def test_detect_web_http(capsys):
uri = 'https://storage-download.googleapis.com/{}/vision/landmark/pofa.jpg'
detect.detect_web_uri(uri.format(BUCKET))
detect.detect_web_uri(uri.format(ASSET_BUCKET))
out, _ = capsys.readouterr()
assert 'best guess label: palace of fine arts' in out.lower()

Expand All @@ -224,32 +226,32 @@ def test_detect_web_with_geo(capsys):


def test_detect_web_with_geo_uri(capsys):
file_name = 'gs://{}/vision/web/city.jpg'.format(BUCKET)
file_name = 'gs://{}/vision/web/city.jpg'.format(ASSET_BUCKET)
detect.web_entities_include_geo_results_uri(file_name)
out, _ = capsys.readouterr()
out = out.lower()
assert 'zepra' in out or 'electra Tower' in out
assert 'zepra' in out or 'electra tower' in out


def test_detect_document(capsys):
file_name = os.path.join(
os.path.dirname(__file__),
'resources/text/screen.jpg')
'resources/text.jpg')
detect.detect_document(file_name)
out, _ = capsys.readouterr()
assert 'class' in out


def test_detect_document_uri(capsys):
file_name = 'gs://{}/vision/text/screen.jpg'.format(BUCKET)
file_name = 'gs://{}/vision/text/screen.jpg'.format(ASSET_BUCKET)
detect.detect_document_uri(file_name)
out, _ = capsys.readouterr()
assert 'class' in out


def test_detect_document_http(capsys):
uri = 'https://storage-download.googleapis.com/{}/vision/text/screen.jpg'
detect.detect_document_uri(uri.format(BUCKET))
detect.detect_document_uri(uri.format(ASSET_BUCKET))
out, _ = capsys.readouterr()
assert 'class' in out

Expand All @@ -264,15 +266,15 @@ def test_detect_crop_hints(capsys):


def test_detect_crop_hints_uri(capsys):
file_name = 'gs://{}/vision/label/wakeupcat.jpg'.format(BUCKET)
file_name = 'gs://{}/vision/label/wakeupcat.jpg'.format(ASSET_BUCKET)
detect.detect_crop_hints_uri(file_name)
out, _ = capsys.readouterr()
assert 'bounds: (0,0)' in out


def test_detect_crop_hints_http(capsys):
uri = 'https://storage-download.googleapis.com/{}/vision/label/wakeupcat.jpg'
detect.detect_crop_hints_uri(uri.format(BUCKET))
detect.detect_crop_hints_uri(uri.format(ASSET_BUCKET))
out, _ = capsys.readouterr()
assert 'bounds: (0,0)' in out

Expand All @@ -286,13 +288,14 @@ def test_async_detect_document(capsys):

assert len(list(bucket.list_blobs(prefix=OUTPUT_PREFIX))) == 0

uri = 'gs://{}/vision/document/custom_0773375000.pdf'.format(ASSET_BUCKET)
detect.async_detect_document(
gcs_source_uri=GCS_SOURCE_URI,
gcs_source_uri=uri,
gcs_destination_uri=GCS_DESTINATION_URI)
out, _ = capsys.readouterr()

assert 'Hodge conjecture' in out
assert len(list(bucket.list_blobs(prefix=OUTPUT_PREFIX))) == 3
assert 'OIL, GAS AND MINERAL LEASE' in out
assert len(list(bucket.list_blobs(prefix=OUTPUT_PREFIX))) > 0

for blob in bucket.list_blobs(prefix=OUTPUT_PREFIX):
blob.delete()
Expand Down