Skip to content

Commit

Permalink
safer and cheaper tests for large jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
qmac committed Mar 28, 2018
1 parent 0777014 commit fa01a71
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
11 changes: 5 additions & 6 deletions pliers/tests/extractors/api/test_clarifai_extractors.py
Expand Up @@ -51,20 +51,19 @@ def test_clarifai_api_extractor_batch():
@pytest.mark.skipif("'CLARIFAI_API_KEY' not in os.environ")
def test_clarifai_api_extractor_large():
default = config.get_option('allow_large_jobs')
default_large = config.get_option('large_job')
config.set_option('allow_large_jobs', False)
config.set_option('large_job', 1)

ext = ClarifaiAPIExtractor()
video = VideoStim(join(get_test_data_path(), 'video', 'small.mp4'))
with pytest.raises(ValueError):
merge_results(ext.transform(video))

images = [ImageStim(join(get_test_data_path(), 'image', 'apple.jpg'))] * 101
images = [ImageStim(join(get_test_data_path(), 'image', 'apple.jpg'))] * 2
with pytest.raises(ValueError):
merge_results(ext.transform(images))

config.set_option('allow_large_jobs', True)
results = merge_results(ext.transform(images))
assert 'ClarifaiAPIExtractor#apple' in results.columns
assert results.shape == (1, 29) # not 101 cause all the same instance
assert results.shape == (1, 29) # not 2 cause all the same instance

config.set_option('allow_large_jobs', default)
config.set_option('large_job', default_large)
8 changes: 5 additions & 3 deletions pliers/tests/extractors/api/test_google_extractors.py
Expand Up @@ -160,17 +160,19 @@ def test_google_vision_api_web_entities():
@pytest.mark.skipif("'GOOGLE_APPLICATION_CREDENTIALS' not in os.environ")
def test_google_vision_api_extractor_large():
default = config.get_option('allow_large_jobs')
default_large = config.get_option('large_job')
config.set_option('allow_large_jobs', False)
config.set_option('large_job', 1)

ext = GoogleVisionAPILabelExtractor()

images = [ImageStim(join(get_test_data_path(), 'image', 'apple.jpg'))] * 101
images = [ImageStim(join(get_test_data_path(), 'image', 'apple.jpg'))] * 2
with pytest.raises(ValueError):
merge_results(ext.transform(images))

config.set_option('allow_large_jobs', True)
results = merge_results(ext.transform(images))
assert 'GoogleVisionAPILabelExtractor#apple' in results.columns
assert results.shape == (1, 16) # not 101 cause all the same instance
assert results.shape == (1, 16) # not 2 cause all the same instance

config.set_option('allow_large_jobs', default)
config.set_option('large_job', default_large)
10 changes: 7 additions & 3 deletions pliers/tests/extractors/api/test_indico_extractors.py
Expand Up @@ -90,20 +90,24 @@ def test_indico_api_image_extractor():
@pytest.mark.skipif("'INDICO_APP_KEY' not in os.environ")
def test_indico_api_extractor_large():
default = config.get_option('allow_large_jobs')
default_large = config.get_option('large_job')
config.set_option('allow_large_jobs', False)
config.set_option('large_job', 1)

ext = IndicoAPIImageExtractor(models=['fer', 'content_filtering'])
ext = IndicoAPIImageExtractor(models=['fer'])

images = [ImageStim(join(IMAGE_DIR, 'apple.jpg'))] * 101
images = [ImageStim(join(IMAGE_DIR, 'apple.jpg'))] * 2
with pytest.raises(ValueError):
merge_results(ext.transform(images))

config.set_option('allow_large_jobs', True)

results = merge_results(ext.transform(images))
assert 'IndicoAPIImageExtractor#fer_Neutral' in results.columns
assert results.shape == (1, 16) # not 101 cause all the same instance
assert results.shape == (1, 15) # not 2 rows cause all the same instance

config.set_option('allow_large_jobs', default)
config.set_option('large_job', default_large)


@pytest.mark.skipif("'INDICO_APP_KEY' not in os.environ")
Expand Down

0 comments on commit fa01a71

Please sign in to comment.