diff --git a/videointelligence/samples/quickstart/noxfile.py b/videointelligence/samples/quickstart/noxfile.py index b90eef00f2d9..ab2c49227c3b 100644 --- a/videointelligence/samples/quickstart/noxfile.py +++ b/videointelligence/samples/quickstart/noxfile.py @@ -37,28 +37,25 @@ TEST_CONFIG = { # You can opt out from the test for specific Python versions. - 'ignored_versions': ["2.7"], - + "ignored_versions": ["2.7"], # Old samples are opted out of enforcing Python type hints # All new samples should feature them - 'enforce_type_hints': False, - + "enforce_type_hints": False, # An envvar key for determining the project id to use. Change it # to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a # build specific Cloud project. You can also use your own string # to use your own Cloud project. - 'gcloud_project_env': 'GOOGLE_CLOUD_PROJECT', + "gcloud_project_env": "GOOGLE_CLOUD_PROJECT", # 'gcloud_project_env': 'BUILD_SPECIFIC_GCLOUD_PROJECT', - # A dictionary you want to inject into your test. Don't put any # secrets here. These values will override predefined values. - 'envs': {}, + "envs": {}, } try: # Ensure we can import noxfile_config in the project's directory. - sys.path.append('.') + sys.path.append(".") from noxfile_config import TEST_CONFIG_OVERRIDE except ImportError as e: print("No user noxfile_config found: detail: {}".format(e)) @@ -73,12 +70,12 @@ def get_pytest_env_vars(): ret = {} # Override the GCLOUD_PROJECT and the alias. - env_key = TEST_CONFIG['gcloud_project_env'] + env_key = TEST_CONFIG["gcloud_project_env"] # This should error out if not set. - ret['GOOGLE_CLOUD_PROJECT'] = os.environ[env_key] + ret["GOOGLE_CLOUD_PROJECT"] = os.environ[env_key] # Apply user supplied envs. - ret.update(TEST_CONFIG['envs']) + ret.update(TEST_CONFIG["envs"]) return ret @@ -87,7 +84,7 @@ def get_pytest_env_vars(): ALL_VERSIONS = ["2.7", "3.6", "3.7", "3.8"] # Any default versions that should be ignored. -IGNORED_VERSIONS = TEST_CONFIG['ignored_versions'] +IGNORED_VERSIONS = TEST_CONFIG["ignored_versions"] TESTED_VERSIONS = sorted([v for v in ALL_VERSIONS if v not in IGNORED_VERSIONS]) @@ -136,7 +133,7 @@ def _determine_local_import_names(start_dir): @nox.session def lint(session): - if not TEST_CONFIG['enforce_type_hints']: + if not TEST_CONFIG["enforce_type_hints"]: session.install("flake8", "flake8-import-order") else: session.install("flake8", "flake8-import-order", "flake8-annotations") @@ -145,9 +142,11 @@ def lint(session): args = FLAKE8_COMMON_ARGS + [ "--application-import-names", ",".join(local_names), - "." + ".", ] session.run("flake8", *args) + + # # Black # @@ -160,6 +159,7 @@ def blacken(session): session.run("black", *python_files) + # # Sample Tests # @@ -199,9 +199,9 @@ def py(session): if session.python in TESTED_VERSIONS: _session_tests(session) else: - session.skip("SKIPPED: {} tests are disabled for this sample.".format( - session.python - )) + session.skip( + "SKIPPED: {} tests are disabled for this sample.".format(session.python) + ) # diff --git a/videointelligence/samples/quickstart/quickstart.py b/videointelligence/samples/quickstart/quickstart.py index 109038c53d00..19d126f01cb3 100644 --- a/videointelligence/samples/quickstart/quickstart.py +++ b/videointelligence/samples/quickstart/quickstart.py @@ -30,33 +30,38 @@ def run_quickstart(): video_client = videointelligence.VideoIntelligenceServiceClient() features = [videointelligence.enums.Feature.LABEL_DETECTION] operation = video_client.annotate_video( - 'gs://cloud-samples-data/video/cat.mp4', features=features) - print('\nProcessing video for label annotations:') + "gs://cloud-samples-data/video/cat.mp4", features=features + ) + print("\nProcessing video for label annotations:") result = operation.result(timeout=120) - print('\nFinished processing.') + print("\nFinished processing.") # first result is retrieved because a single video was processed segment_labels = result.annotation_results[0].segment_label_annotations for i, segment_label in enumerate(segment_labels): - print('Video label description: {}'.format( - segment_label.entity.description)) + print("Video label description: {}".format(segment_label.entity.description)) for category_entity in segment_label.category_entities: - print('\tLabel category description: {}'.format( - category_entity.description)) + print( + "\tLabel category description: {}".format(category_entity.description) + ) for i, segment in enumerate(segment_label.segments): - start_time = (segment.segment.start_time_offset.seconds + - segment.segment.start_time_offset.nanos / 1e9) - end_time = (segment.segment.end_time_offset.seconds + - segment.segment.end_time_offset.nanos / 1e9) - positions = '{}s to {}s'.format(start_time, end_time) + start_time = ( + segment.segment.start_time_offset.seconds + + segment.segment.start_time_offset.nanos / 1e9 + ) + end_time = ( + segment.segment.end_time_offset.seconds + + segment.segment.end_time_offset.nanos / 1e9 + ) + positions = "{}s to {}s".format(start_time, end_time) confidence = segment.confidence - print('\tSegment {}: {}'.format(i, positions)) - print('\tConfidence: {}'.format(confidence)) - print('\n') + print("\tSegment {}: {}".format(i, positions)) + print("\tConfidence: {}".format(confidence)) + print("\n") # [END video_quickstart] -if __name__ == '__main__': +if __name__ == "__main__": run_quickstart() diff --git a/videointelligence/samples/quickstart/quickstart_test.py b/videointelligence/samples/quickstart/quickstart_test.py index 1d1534c46cfe..53c11242957b 100644 --- a/videointelligence/samples/quickstart/quickstart_test.py +++ b/videointelligence/samples/quickstart/quickstart_test.py @@ -23,4 +23,4 @@ def test_quickstart(capsys): quickstart.run_quickstart() out, _ = capsys.readouterr() - assert 'Video label description: cat' in out + assert "Video label description: cat" in out