Skip to content

Commit f52aa10

Browse files
Jon Wayne Parrottbusunkim96
Jon Wayne Parrott
authored andcommitted
Remove resource [(#890)](#890)
* Remove resource fixture * Remove remote resource
1 parent e216689 commit f52aa10

File tree

3 files changed

+25
-13
lines changed

3 files changed

+25
-13
lines changed

language/snippets/ocr_nl/main_test.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,14 @@
1717
import re
1818
import zipfile
1919

20+
import requests
21+
2022
import main
2123

2224
BUCKET = os.environ['CLOUD_STORAGE_BUCKET']
2325
TEST_IMAGE_URI = 'gs://{}/language/image8.png'.format(BUCKET)
26+
OCR_IMAGES_URI = 'http://storage.googleapis.com/{}/{}'.format(
27+
BUCKET, 'language/ocr_nl-images-small.zip')
2428

2529

2630
def test_batch_empty():
@@ -79,14 +83,16 @@ def test_entities_list():
7983
assert wurl == 'http://en.wikipedia.org/wiki/Mr_Bennet'
8084

8185

82-
def test_main(remote_resource, tmpdir, capsys):
86+
def test_main(tmpdir, capsys):
8387
images_path = str(tmpdir.mkdir('images'))
8488

8589
# First, pull down some test data
86-
zip_path = remote_resource('language/ocr_nl-images-small.zip', tmpdir)
90+
response = requests.get(OCR_IMAGES_URI)
91+
images_file = tmpdir.join('images.zip')
92+
images_file.write_binary(response.content)
8793

8894
# Extract it to the image directory
89-
with zipfile.ZipFile(zip_path) as zfile:
95+
with zipfile.ZipFile(str(images_file)) as zfile:
9096
zfile.extractall(images_path)
9197

9298
main.main(images_path, str(tmpdir.join('ocr_nl.db')))

language/snippets/sentiment/sentiment_analysis_test.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,37 +11,40 @@
1111
# See the License for the specific language governing permissions and
1212
# limitations under the License.
1313

14+
import os
1415
import re
1516

1617
from sentiment_analysis import analyze
1718

19+
RESOURCES = os.path.join(os.path.dirname(__file__), 'resources')
1820

19-
def test_pos(resource, capsys):
20-
analyze(resource('pos.txt'))
21+
22+
def test_pos(capsys):
23+
analyze(os.path.join(RESOURCES, 'pos.txt'))
2124
out, err = capsys.readouterr()
2225
score = float(re.search('score of (.+?) with', out).group(1))
2326
magnitude = float(re.search('magnitude of (.+?)', out).group(1))
2427
assert score * magnitude > 0
2528

2629

27-
def test_neg(resource, capsys):
28-
analyze(resource('neg.txt'))
30+
def test_neg(capsys):
31+
analyze(os.path.join(RESOURCES, 'neg.txt'))
2932
out, err = capsys.readouterr()
3033
score = float(re.search('score of (.+?) with', out).group(1))
3134
magnitude = float(re.search('magnitude of (.+?)', out).group(1))
3235
assert score * magnitude < 0
3336

3437

35-
def test_mixed(resource, capsys):
36-
analyze(resource('mixed.txt'))
38+
def test_mixed(capsys):
39+
analyze(os.path.join(RESOURCES, 'mixed.txt'))
3740
out, err = capsys.readouterr()
3841
score = float(re.search('score of (.+?) with', out).group(1))
3942
assert score <= 0.3
4043
assert score >= -0.3
4144

4245

43-
def test_neutral(resource, capsys):
44-
analyze(resource('neutral.txt'))
46+
def test_neutral(capsys):
47+
analyze(os.path.join(RESOURCES, 'neutral.txt'))
4548
out, err = capsys.readouterr()
4649
magnitude = float(re.search('magnitude of (.+?)', out).group(1))
4750
assert magnitude <= 2.0

language/snippets/syntax_triples/main_test.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import os
1516
import re
1617

1718
import main
1819

20+
RESOURCES = os.path.join(os.path.dirname(__file__), 'resources')
21+
1922

2023
def test_dependents():
2124
text = "I am eating a delicious banana"
@@ -41,8 +44,8 @@ def test_find_triples():
4144
assert (1, 2, 5) == triple
4245

4346

44-
def test_obama_example(resource, capsys):
45-
main.main(resource('obama_wikipedia.txt'))
47+
def test_obama_example(capsys):
48+
main.main(os.path.join(RESOURCES, 'obama_wikipedia.txt'))
4649
stdout, _ = capsys.readouterr()
4750
lines = stdout.split('\n')
4851
assert re.match(

0 commit comments

Comments
 (0)