Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vision API: further fixes. #2002

Merged
merged 7 commits into from
Feb 7, 2019
Merged
Show file tree
Hide file tree
Changes from 6 commits
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
103 changes: 56 additions & 47 deletions vision/cloud-client/detect/detect_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,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)
Expand All @@ -34,15 +36,16 @@ 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/wakeupcat.jpg'
detect.detect_labels_uri(uri.format(BUCKET))
uri = 'https://storage-download.googleapis.com/{}' \
'/vision/label/wakeupcat.jpg'
detect.detect_labels_uri(uri.format(ASSET_BUCKET))
out, _ = capsys.readouterr()
assert 'Labels' in out

Expand All @@ -53,21 +56,21 @@ def test_landmarks(capsys):
'resources/landmark.jpg')
detect.detect_landmarks(file_name)
out, _ = capsys.readouterr()
assert 'Palace' in out
assert 'palace' in out.lower()


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
assert 'palace' in out.lower()


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


def test_faces(capsys):
Expand All @@ -80,16 +83,16 @@ def test_faces(capsys):


def test_faces_uri(capsys):
file_name = 'gs://{}/vision/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


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

Expand All @@ -100,21 +103,22 @@ def test_logos(capsys):
'resources/logos.png')
detect.detect_logos(file_name)
out, _ = capsys.readouterr()
assert 'google' in out
assert 'google' in out.lower()


def test_logos_uri(capsys):
file_name = 'gs://{}/vision/logos.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
assert 'google' in out.lower()


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


def test_safe_search(capsys):
Expand All @@ -128,16 +132,17 @@ def test_safe_search(capsys):


def test_safe_search_uri(capsys):
file_name = 'gs://{}/vision/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
assert 'racy: ' in out


def test_safe_search_http(capsys):
uri = 'https://storage-download.googleapis.com/{}/vision/wakeupcat.jpg'
detect.detect_safe_search_uri(uri.format(BUCKET))
uri = 'https://storage-download.googleapis.com/{}' \
'/vision/label/wakeupcat.jpg'
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 +158,15 @@ def test_detect_text(capsys):


def test_detect_text_uri(capsys):
file_name = 'gs://{}/vision/text.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.jpg'
detect.detect_text_uri(uri.format(BUCKET))
uri = 'https://storage-download.googleapis.com/{}/vision/text/screen.jpg'
detect.detect_text_uri(uri.format(ASSET_BUCKET))
out, _ = capsys.readouterr()
assert '37%' in out

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


def test_detect_properties_uri(capsys):
file_name = 'gs://{}/vision/landmark.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.jpg'
detect.detect_properties_uri(uri.format(BUCKET))
uri = 'https://storage-download.googleapis.com/{}/vision/landmark/pofa.jpg'
detect.detect_properties_uri(uri.format(ASSET_BUCKET))
out, _ = capsys.readouterr()
assert 'frac' in out

Expand All @@ -196,21 +201,21 @@ def test_detect_web(capsys):
'resources/landmark.jpg')
detect.detect_web(file_name)
out, _ = capsys.readouterr()
assert 'Best guess label: palace of fine arts' in out
assert 'best guess label: palace of fine arts' in out.lower()


def test_detect_web_uri(capsys):
file_name = 'gs://{}/vision/landmark.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
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.jpg'
detect.detect_web_uri(uri.format(BUCKET))
uri = 'https://storage-download.googleapis.com/{}/vision/landmark/pofa.jpg'
detect.detect_web_uri(uri.format(ASSET_BUCKET))
out, _ = capsys.readouterr()
assert 'Best guess label: palace of fine arts' in out
assert 'best guess label: palace of fine arts' in out.lower()


def test_detect_web_with_geo(capsys):
Expand All @@ -219,14 +224,16 @@ def test_detect_web_with_geo(capsys):
'resources/city.jpg')
detect.web_entities_include_geo_results(file_name)
out, _ = capsys.readouterr()
assert 'Zepra' in out or 'Electra Tower' in out
out = out.lower()
assert 'zepra' in out or 'electra tower' in out


def test_detect_web_with_geo_uri(capsys):
file_name = 'gs://{}/vision/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()
assert 'Zepra' in out or 'Electra Tower' in out
out = out.lower()
assert 'zepra' in out or 'electra tower' in out


def test_detect_document(capsys):
Expand All @@ -239,15 +246,15 @@ def test_detect_document(capsys):


def test_detect_document_uri(capsys):
file_name = 'gs://{}/vision/text.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.jpg'
detect.detect_document_uri(uri.format(BUCKET))
uri = 'https://storage-download.googleapis.com/{}/vision/text/screen.jpg'
detect.detect_document_uri(uri.format(ASSET_BUCKET))
out, _ = capsys.readouterr()
assert 'class' in out

Expand All @@ -262,15 +269,16 @@ def test_detect_crop_hints(capsys):


def test_detect_crop_hints_uri(capsys):
file_name = 'gs://{}/vision/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/wakeupcat.jpg'
detect.detect_crop_hints_uri(uri.format(BUCKET))
uri = 'https://storage-download.googleapis.com/{}' \
'/vision/label/wakeupcat.jpg'
detect.detect_crop_hints_uri(uri.format(ASSET_BUCKET))
out, _ = capsys.readouterr()
assert 'bounds: (0,0)' in out

Expand All @@ -284,13 +292,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 All @@ -302,7 +311,7 @@ def test_localize_objects(capsys):
detect.localize_objects('resources/puppies.jpg')

out, _ = capsys.readouterr()
assert 'Dog' in out
assert 'dog' in out.lower()


def test_localize_objects_uri(capsys):
Expand All @@ -311,4 +320,4 @@ def test_localize_objects_uri(capsys):
detect.localize_objects_uri(uri)

out, _ = capsys.readouterr()
assert 'Dog' in out
assert 'dog' in out.lower()
13 changes: 6 additions & 7 deletions vision/cloud-client/web/web_detect_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,25 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import os

import web_detect

BUCKET = os.environ['CLOUD_STORAGE_BUCKET']
ASSET_BUCKET = "cloud-samples-data"


def test_detect_file(capsys):
file_name = ('../detect/resources/landmark.jpg')
web_detect.report(web_detect.annotate(file_name))
out, _ = capsys.readouterr()
assert 'Description: Palace of Fine Arts Theatre' in out
print(out)
assert 'description: palace of fine arts' in out.lower()


def test_detect_web_gsuri(capsys):
file_name = ('gs://{}/vision/landmark.jpg'.format(
BUCKET))
file_name = ('gs://{}/vision/landmark/pofa.jpg'.format(
ASSET_BUCKET))
web_detect.report(web_detect.annotate(file_name))
out, _ = capsys.readouterr()
assert 'Description: Palace of Fine Arts Theatre' in out
assert 'description: palace of fine arts' in out.lower()


def test_detect_web_http(capsys):
Expand Down