Skip to content

Commit

Permalink
Update MIBI consumer to inherit from ImageFileConsumer. (#119)
Browse files Browse the repository at this point in the history
* Improved testing coverage using fakeredis and pytest-mock (#117)

* install pytest-mock and replace monkeypatching with `mock` library.

* move testing reqs into requirements-test.txt and add 3.8 to test suite.

* update RedisClient tests to use fakeredis.

* directly patch boto3.client

* no need to alias google.cloud.storage in imports.

* Fix storage tests to use a Singleton dummy class instead of global variables.

* proper string fomatting using {} instead of %s

* move DummyStorage and DummyRedis into utils/testing_utils.py to DRY out the tests

* Update tests to use fakeredis client and fewer global variables.

* use save_output for ImageConsumer and MibiConsumer.

pass save_name into the function directly instead of calling HGETALL inside the save_output function.

* inherit from ImageFileConsumer to make better use of the pre/post-process functions.

* add keys for the mibi pre and postprocessing.

* adapt the mibi consumer tests to use the testing_utils.py helpers.

* remove unused imports.

* Fix a few license URLs. (#118)
  • Loading branch information
willgraf committed Jul 10, 2020
1 parent 4620f36 commit efb92c1
Show file tree
Hide file tree
Showing 19 changed files with 1,046 additions and 1,382 deletions.
2 changes: 1 addition & 1 deletion .coveragerc
Expand Up @@ -15,4 +15,4 @@ show_missing = True
omit =
**/*_test.py
redis_consumer/pbs/*
redis_consumer/grpc_clients.py
redis_consumer/testing_utils.py
4 changes: 2 additions & 2 deletions .travis.yml
@@ -1,4 +1,3 @@
sudo: true
dist: xenial

git:
Expand All @@ -11,12 +10,13 @@ python:
- 3.5
- 3.6
- 3.7
- 3.8

cache: pip

install:
- travis_retry pip install -r requirements.txt
- travis_retry pip install pytest pytest-cov==2.5.1 pytest-pep8 coveralls
- travis_retry pip install -r requirements-test.txt
# install documentation requirements
- if [[ "$TRAVIS_PYTHON_VERSION" == "3.7" ]]; then
travis_retry pip install -r docs/rtd-requirements.txt;
Expand Down
13 changes: 6 additions & 7 deletions redis_consumer/consumers/base_consumer.py
Expand Up @@ -121,7 +121,7 @@ def get_redis_hash(self):
# Update redis with failed status
self.update_key(redis_hash, {
'status': self.failed_status,
'reason': 'Invalid filetype for "%s" job.'.format(self.queue),
'reason': 'Invalid filetype for "{}" job.'.format(self.queue),
})

def _handle_error(self, err, redis_hash):
Expand Down Expand Up @@ -496,9 +496,10 @@ def predict(self, image, model_name, model_version, untile=True):

# TODO: generalize for more than a single input.
if len(model_metadata) > 1:
raise ValueError('Model %s:%s has %s required inputs but was only '
'given %s inputs.', model_name, model_version,
len(model_metadata), len(image))
raise ValueError('Model {}:{} has {} required inputs but was only '
'given {} inputs.'.format(
model_name, model_version,
len(model_metadata), len(image)))
model_metadata = model_metadata[0]

model_input_name = model_metadata['in_tensor_name']
Expand Down Expand Up @@ -552,11 +553,9 @@ def predict(self, image, model_name, model_version, untile=True):

return image

def save_output(self, image, redis_hash, fname, scale):
hvals = self.redis.hgetall(redis_hash)
def save_output(self, image, redis_hash, save_name, scale):
with utils.get_tempdir() as tempdir:
# Save each result channel as an image file
save_name = hvals.get('original_name', fname)
subdir = os.path.dirname(save_name.replace(tempdir, ''))
name = os.path.splitext(os.path.basename(save_name))[0]

Expand Down

0 comments on commit efb92c1

Please sign in to comment.