Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* Remove resource fixture

* Remove remote resource
  • Loading branch information
Jon Wayne Parrott authored and busunkim96 committed Sep 29, 2020
1 parent b012988 commit 4022dba
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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')))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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(
Expand Down

0 comments on commit 4022dba

Please sign in to comment.