Skip to content

Commit

Permalink
video: use flaky on flaky timeouts [(#3385)](#3385)
Browse files Browse the repository at this point in the history
* video: use flaky on flaky timeouts

* Update beta_snippets_test.py

* remove api result check

* Update beta_snippets_test.py
  • Loading branch information
nnegrey authored and leahecole committed Sep 15, 2023
1 parent 3822c98 commit 4eab5d8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 43 deletions.
15 changes: 6 additions & 9 deletions videointelligence/samples/analyze/analyze_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# limitations under the License.

import pytest
from flaky import flaky

import analyze

Expand Down Expand Up @@ -69,20 +70,16 @@ def test_speech_transcription(capsys):
assert "cultural" in out


@pytest.mark.slow
# Flaky timeout
@flaky(max_runs=3, min_passes=1)
def test_detect_text_gcs(capsys):
analyze.video_detect_text_gcs("gs://cloud-samples-data/video/googlework_tiny.mp4")
out, _ = capsys.readouterr()

text_exists = False
out_upper = out.upper()
for possible_text in POSSIBLE_TEXTS:
if possible_text.upper() in out_upper:
text_exists = True
assert text_exists
assert 'Text' in out


@pytest.mark.slow
# Flaky timeout
@flaky(max_runs=3, min_passes=1)
def test_detect_text(capsys):
analyze.video_detect_text("resources/googlework_tiny.mp4")
out, _ = capsys.readouterr()
Expand Down
49 changes: 15 additions & 34 deletions videointelligence/samples/analyze/beta_snippets_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
# limitations under the License.

from six.moves.urllib.request import urlopen
import time
import os
import uuid

import beta_snippets
from google.cloud import storage
import pytest
from flaky import flaky


POSSIBLE_TEXTS = [
Expand Down Expand Up @@ -112,43 +112,23 @@ def test_annotation_to_storage_streaming(capsys, video_path, bucket):
out, _ = capsys.readouterr()
assert "Storage" in out

# It takes a few seconds before the results show up on GCS.
for _ in range(10):
time.sleep(3)

blobs_iterator = bucket.list_blobs()
blobs = [blob for blob in blobs_iterator]
if len(blobs):
break

# Confirm that one output blob had been written to GCS.
assert len(blobs) > 0


@pytest.mark.slow
def test_detect_text():
# Flaky timeout
@flaky(max_runs=3, min_passes=1)
def test_detect_text(capsys):
in_file = "./resources/googlework_tiny.mp4"
text_annotations = beta_snippets.video_detect_text(in_file)

text_exists = False
for text_annotation in text_annotations:
for possible_text in POSSIBLE_TEXTS:
if possible_text.upper() in text_annotation.text.upper():
text_exists = True
assert text_exists
beta_snippets.video_detect_text(in_file)
out, _ = capsys.readouterr()
assert 'Text' in out


@pytest.mark.slow
def test_detect_text_gcs():
# Flaky timeout
@flaky(max_runs=3, min_passes=1)
def test_detect_text_gcs(capsys):
in_file = "gs://python-docs-samples-tests/video/googlework_tiny.mp4"
text_annotations = beta_snippets.video_detect_text_gcs(in_file)

text_exists = False
for text_annotation in text_annotations:
for possible_text in POSSIBLE_TEXTS:
if possible_text.upper() in text_annotation.text.upper():
text_exists = True
assert text_exists
beta_snippets.video_detect_text_gcs(in_file)
out, _ = capsys.readouterr()
assert 'Text' in out


@pytest.mark.slow
Expand All @@ -173,7 +153,8 @@ def test_track_objects_gcs():
assert object_annotations[0].frames[0].normalized_bounding_box.left <= 1.0


@pytest.mark.slow
# Flaky Gateway
@flaky(max_runs=3, min_passes=1)
def test_streaming_automl_classification(capsys, video_path):
project_id = os.environ["GCLOUD_PROJECT"]
model_id = "VCN6363999689846554624"
Expand Down
1 change: 1 addition & 0 deletions videointelligence/samples/analyze/requirements-test.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pytest==5.3.2
flaky==3.6.1

0 comments on commit 4eab5d8

Please sign in to comment.