diff --git a/vision/cloud-client/detect/detect_test.py b/vision/cloud-client/detect/detect_test.py index 588f86fec57..9f8c9f4f3cb 100644 --- a/vision/cloud-client/detect/detect_test.py +++ b/vision/cloud-client/detect/detect_test.py @@ -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) @@ -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 @@ -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): @@ -80,7 +83,7 @@ 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 @@ -88,8 +91,8 @@ def test_faces_uri(capsys): 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 @@ -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): @@ -128,7 +132,7 @@ 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 @@ -136,8 +140,9 @@ def test_safe_search_uri(capsys): 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 @@ -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 @@ -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 @@ -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): @@ -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): @@ -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 @@ -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 @@ -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() @@ -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): @@ -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() diff --git a/vision/cloud-client/web/web_detect_test.py b/vision/cloud-client/web/web_detect_test.py index 6b5553c97ae..3a0ea54840f 100644 --- a/vision/cloud-client/web/web_detect_test.py +++ b/vision/cloud-client/web/web_detect_test.py @@ -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):