diff --git a/packages/google-cloud-language/samples/snippets/cloud-client/snippets_test.py b/packages/google-cloud-language/samples/snippets/cloud-client/snippets_test.py index 47050e44e23c..080d5dd5d5bb 100644 --- a/packages/google-cloud-language/samples/snippets/cloud-client/snippets_test.py +++ b/packages/google-cloud-language/samples/snippets/cloud-client/snippets_test.py @@ -12,49 +12,47 @@ # See the License for the specific language governing permissions and # limitations under the License. +import os import snippets +BUCKET = os.environ['CLOUD_STORAGE_BUCKET'] +TEST_FILE_URL = 'gs://{}/text.txt'.format(BUCKET) -def test_sentiment_text(cloud_config, capsys): + +def test_sentiment_text(capsys): snippets.sentiment_text('President Obama is speaking at the White House.') out, _ = capsys.readouterr() assert 'Score: 0.2' in out -def test_sentiment_file(cloud_config, capsys): - cloud_storage_input_uri = 'gs://{}/text.txt'.format( - cloud_config.storage_bucket) - snippets.sentiment_file(cloud_storage_input_uri) +def test_sentiment_file(capsys): + snippets.sentiment_file(TEST_FILE_URL) out, _ = capsys.readouterr() assert 'Score: 0.2' in out -def test_entities_text(cloud_config, capsys): +def test_entities_text(capsys): snippets.entities_text('President Obama is speaking at the White House.') out, _ = capsys.readouterr() assert 'name' in out assert ': Obama' in out -def test_entities_file(cloud_config, capsys): - cloud_storage_input_uri = 'gs://{}/text.txt'.format( - cloud_config.storage_bucket) - snippets.entities_file(cloud_storage_input_uri) +def test_entities_file(capsys): + snippets.entities_file(TEST_FILE_URL) out, _ = capsys.readouterr() assert 'name' in out assert ': Obama' in out -def test_syntax_text(cloud_config, capsys): +def test_syntax_text(capsys): snippets.syntax_text('President Obama is speaking at the White House.') out, _ = capsys.readouterr() assert 'NOUN: President' in out -def test_syntax_file(cloud_config, capsys): - cloud_storage_input_uri = 'gs://{}/text.txt'.format( - cloud_config.storage_bucket) - snippets.syntax_file(cloud_storage_input_uri) +def test_syntax_file(capsys): + snippets.syntax_file(TEST_FILE_URL) out, _ = capsys.readouterr() assert 'NOUN: President' in out diff --git a/packages/google-cloud-language/samples/snippets/ocr_nl/main_test.py b/packages/google-cloud-language/samples/snippets/ocr_nl/main_test.py index e5a9962e1e25..832483ca5317 100755 --- a/packages/google-cloud-language/samples/snippets/ocr_nl/main_test.py +++ b/packages/google-cloud-language/samples/snippets/ocr_nl/main_test.py @@ -13,15 +13,14 @@ # See the License for the specific language governing permissions and # limitations under the License. -"""Tests for main.""" - +import os import re import zipfile import main - -_TEST_IMAGE_URI = 'gs://{}/language/image8.png' +BUCKET = os.environ['CLOUD_STORAGE_BUCKET'] +TEST_IMAGE_URI = 'gs://{}/language/image8.png'.format(BUCKET) def test_batch_empty(): @@ -36,10 +35,10 @@ def test_batch_single(): assert batched == ((1,),) -def test_single_image_returns_text(cloud_config): +def test_single_image_returns_text(): vision_api_client = main.VisionApi() - image_path = _TEST_IMAGE_URI.format(cloud_config.storage_bucket) + image_path = TEST_IMAGE_URI texts = vision_api_client.detect_text([image_path]) assert image_path in texts @@ -66,9 +65,9 @@ def test_text_returns_entities(): assert wurl == 'http://en.wikipedia.org/wiki/Sherlock_Holmes' -def test_entities_list(cloud_config): +def test_entities_list(): vision_api_client = main.VisionApi() - image_path = _TEST_IMAGE_URI.format(cloud_config.storage_bucket) + image_path = TEST_IMAGE_URI texts = vision_api_client.detect_text([image_path]) locale, document = main.extract_description(texts[image_path]) text_analyzer = main.TextAnalyzer()