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 832483ca5317..afaf2e16576c 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 @@ -17,10 +17,14 @@ import re import zipfile +import requests + import main BUCKET = os.environ['CLOUD_STORAGE_BUCKET'] TEST_IMAGE_URI = 'gs://{}/language/image8.png'.format(BUCKET) +OCR_IMAGES_URI = 'http://storage.googleapis.com/{}/{}'.format( + BUCKET, 'language/ocr_nl-images-small.zip') def test_batch_empty(): @@ -79,14 +83,16 @@ def test_entities_list(): assert wurl == 'http://en.wikipedia.org/wiki/Mr_Bennet' -def test_main(remote_resource, tmpdir, capsys): +def test_main(tmpdir, capsys): images_path = str(tmpdir.mkdir('images')) # First, pull down some test data - zip_path = remote_resource('language/ocr_nl-images-small.zip', tmpdir) + response = requests.get(OCR_IMAGES_URI) + images_file = tmpdir.join('images.zip') + images_file.write_binary(response.content) # Extract it to the image directory - with zipfile.ZipFile(zip_path) as zfile: + with zipfile.ZipFile(str(images_file)) as zfile: zfile.extractall(images_path) main.main(images_path, str(tmpdir.join('ocr_nl.db'))) diff --git a/packages/google-cloud-language/samples/snippets/sentiment/sentiment_analysis_test.py b/packages/google-cloud-language/samples/snippets/sentiment/sentiment_analysis_test.py index 19ec86f17d5b..05d28ab27898 100644 --- a/packages/google-cloud-language/samples/snippets/sentiment/sentiment_analysis_test.py +++ b/packages/google-cloud-language/samples/snippets/sentiment/sentiment_analysis_test.py @@ -11,37 +11,40 @@ # See the License for the specific language governing permissions and # limitations under the License. +import os import re from sentiment_analysis import analyze +RESOURCES = os.path.join(os.path.dirname(__file__), 'resources') -def test_pos(resource, capsys): - analyze(resource('pos.txt')) + +def test_pos(capsys): + analyze(os.path.join(RESOURCES, 'pos.txt')) out, err = capsys.readouterr() score = float(re.search('score of (.+?) with', out).group(1)) magnitude = float(re.search('magnitude of (.+?)', out).group(1)) assert score * magnitude > 0 -def test_neg(resource, capsys): - analyze(resource('neg.txt')) +def test_neg(capsys): + analyze(os.path.join(RESOURCES, 'neg.txt')) out, err = capsys.readouterr() score = float(re.search('score of (.+?) with', out).group(1)) magnitude = float(re.search('magnitude of (.+?)', out).group(1)) assert score * magnitude < 0 -def test_mixed(resource, capsys): - analyze(resource('mixed.txt')) +def test_mixed(capsys): + analyze(os.path.join(RESOURCES, 'mixed.txt')) out, err = capsys.readouterr() score = float(re.search('score of (.+?) with', out).group(1)) assert score <= 0.3 assert score >= -0.3 -def test_neutral(resource, capsys): - analyze(resource('neutral.txt')) +def test_neutral(capsys): + analyze(os.path.join(RESOURCES, 'neutral.txt')) out, err = capsys.readouterr() magnitude = float(re.search('magnitude of (.+?)', out).group(1)) assert magnitude <= 2.0 diff --git a/packages/google-cloud-language/samples/snippets/syntax_triples/main_test.py b/packages/google-cloud-language/samples/snippets/syntax_triples/main_test.py index 62c2915da02e..6aa87818e35b 100755 --- a/packages/google-cloud-language/samples/snippets/syntax_triples/main_test.py +++ b/packages/google-cloud-language/samples/snippets/syntax_triples/main_test.py @@ -12,10 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. +import os import re import main +RESOURCES = os.path.join(os.path.dirname(__file__), 'resources') + def test_dependents(): text = "I am eating a delicious banana" @@ -41,8 +44,8 @@ def test_find_triples(): assert (1, 2, 5) == triple -def test_obama_example(resource, capsys): - main.main(resource('obama_wikipedia.txt')) +def test_obama_example(capsys): + main.main(os.path.join(RESOURCES, 'obama_wikipedia.txt')) stdout, _ = capsys.readouterr() lines = stdout.split('\n') assert re.match(