Skip to content

Commit

Permalink
Integration tests (IBM#7)
Browse files Browse the repository at this point in the history
* added integration tests and switched to max-base image

* corrected model name in .travis.yml
  • Loading branch information
bdwyer2 authored Aug 21, 2018
1 parent 0b0cea5 commit 1fdea32
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
README.md
Dockerfile
.git/
tests/
/.pytest_cache/
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,4 @@ ENV/

# mypy
.mypy_cache/
/.pytest_cache/
12 changes: 12 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
language: python
python:
- 3.6
services:
- docker
install:
- docker build -t max-breast-cancer-mitosis-detector .
- docker run -it -d -p 5000:5000 max-breast-cancer-mitosis-detector
before_script:
- pip install pytest pycurl
script:
- pytest tests/test.py
9 changes: 3 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
FROM continuumio/miniconda3
FROM codait/max-base

RUN apt-get update && apt-get install -y libopenslide0 gcc && rm -rf /var/lib/apt/lists/*

# Python package versions
ARG numpy_version=1.14.1
ARG tensorflow_version=1.9.0

RUN pip install --upgrade pip && \
pip install numpy==${numpy_version} && \
RUN pip install numpy==${numpy_version} && \
pip install Pillow && \
pip install h5py && \
pip install flask-restplus && \
pip install openslide-python && \
pip install tensorflow==${tensorflow_version}

RUN mkdir /workspace && \
cd /workspace && \
RUN cd /workspace && \
git clone https://github.com/codait/deep-histopath && \
cp -R deep-histopath/. .

Expand Down
45 changes: 45 additions & 0 deletions tests/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import pytest
import pycurl
import io
import json


def test_response():

# Test True

c = pycurl.Curl()
b = io.BytesIO()
c.setopt(pycurl.URL, 'http://localhost:5000/model/predict')
c.setopt(pycurl.HTTPHEADER, ['Accept:application/json', 'Content-Type: multipart/form-data'])
c.setopt(pycurl.HTTPPOST, [('image', (pycurl.FORM_FILE, "assets/true.png"))])
c.setopt(pycurl.WRITEFUNCTION, b.write)
c.perform()
assert c.getinfo(pycurl.RESPONSE_CODE) == 200
c.close()
response = b.getvalue()
response = json.loads(response)

assert response['status'] == 'ok'
assert response['predictions'][0]['probability'] > 0.5

# Test False

c = pycurl.Curl()
b = io.BytesIO()
c.setopt(pycurl.URL, 'http://localhost:5000/model/predict')
c.setopt(pycurl.HTTPHEADER, ['Accept:application/json', 'Content-Type: multipart/form-data'])
c.setopt(pycurl.HTTPPOST, [('image', (pycurl.FORM_FILE, "assets/false.png"))])
c.setopt(pycurl.WRITEFUNCTION, b.write)
c.perform()
assert c.getinfo(pycurl.RESPONSE_CODE) == 200
c.close()
response = b.getvalue()
response = json.loads(response)

assert response['status'] == 'ok'
assert response['predictions'][0]['probability'] < 0.5


if __name__ == '__main__':
pytest.main([__file__])

0 comments on commit 1fdea32

Please sign in to comment.