-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from KSUSeniorProject-MathLearningMachine/add-…
…basic-tests Add basic tests
- Loading branch information
Showing
6 changed files
with
132 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: Docker Image CI | ||
|
||
on: | ||
push: | ||
branches: [ development ] | ||
pull_request: | ||
branches: [ development ] | ||
|
||
jobs: | ||
|
||
build: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Update the environment files | ||
run: | | ||
echo "MATHPIX_APP_KEY=${{ secrets.MATHPIX_APP_KEY }}" >> mathpix-variables.env | ||
echo "MATHPIX_APP_ID=${{ secrets.MATHPIX_APP_ID }}" >> mathpix-variables.env | ||
- name: Build the Docker image | ||
run: | | ||
docker-compose build | ||
- name: Run the test suite | ||
run: | | ||
docker-compose run flask bash -c "cd /app/flask/flaskapp && python -m pytest" | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import pytest | ||
|
||
from flaskapp import app as flask_app | ||
|
||
@pytest.fixture | ||
def app(): | ||
yield flask_app | ||
|
||
|
||
@pytest.fixture | ||
def client(app): | ||
return app.test_client() |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import jsonschema | ||
from jsonschema import validate | ||
|
||
def test_home_page(client, app): | ||
"""A basic test to ensure the home page is functioning correctly""" | ||
res = client.get('/') | ||
assert b'Hello, World!' == res.data | ||
|
||
|
||
def test_mathpix_ocr(client, app): | ||
with open('tests/imagetest.txt', 'r') as file: | ||
image = file.read().replace('\n', '') | ||
|
||
response_schema = { | ||
"type": "object", | ||
"properties": { | ||
"confidence": {"type": "number"}, | ||
"latex_styled": {"type": "string"}, | ||
"request_id": {"type": "string"}, | ||
}, | ||
} | ||
res = client.post('/mathpix-ocr', json={ | ||
'b64_img': image | ||
}) | ||
|
||
assert True == validate_json(instance=res.get_json(), schema=response_schema) | ||
|
||
|
||
def test_solve_image(client, app): | ||
with open('tests/imagetest.txt', 'r') as file: | ||
image = file.read().replace('\n', '') | ||
|
||
response_schema = { | ||
"type": "object", | ||
"properties": { | ||
"confidence": {"type": "number"}, | ||
"input_detected": {"type": "string"}, | ||
"solved": {"type": "string"}, | ||
}, | ||
} | ||
|
||
res = client.post('/solve-image', json={ | ||
'b64_img': image | ||
}) | ||
|
||
assert True == validate_json(instance=res.get_json(), schema=response_schema) | ||
assert r'F(0)=x' == res.get_json()['input_detected'] | ||
assert r'F{\left(0 \right)} = x' == res.get_json()['solved'] | ||
|
||
|
||
def test_solve_latex(client, app): | ||
response_schema = { | ||
"type": "object", | ||
"properties": { | ||
"solved": {"type": "string"}, | ||
}, | ||
} | ||
|
||
res = client.post('/solve-latex', json={ | ||
'latex': r'F(x)=2+2' | ||
}) | ||
|
||
assert True == validate_json(instance=res.get_json(), schema=response_schema) | ||
assert r'F{\left(x \right)} = 4' == res.get_json()['solved'] | ||
|
||
|
||
def validate_json(instance, schema): | ||
try: | ||
validate(instance, schema) | ||
except jsonschema.exceptions.ValidationError as err: | ||
return False | ||
return True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,32 @@ | ||
antlr4-python3-runtime==4.8 | ||
attrs==20.2.0 | ||
certifi==2020.6.20 | ||
chardet==3.0.4 | ||
click==7.1.2 | ||
Flask==1.1.2 | ||
hypothesis==5.33.0 | ||
idna==2.10 | ||
importlib-metadata==1.7.0 | ||
iniconfig==1.0.1 | ||
itsdangerous==1.1.0 | ||
Jinja2==2.11.2 | ||
jsonschema==3.2.0 | ||
latex2sympy==1.0.3 | ||
MarkupSafe==1.1.1 | ||
more-itertools==8.5.0 | ||
mpmath==1.1.0 | ||
packaging==20.4 | ||
pathlib2==2.3.5 | ||
pkg-resources==0.0.0 | ||
pluggy==0.13.1 | ||
py==1.9.0 | ||
pyparsing==2.4.7 | ||
pyrsistent==0.17.3 | ||
pytest==6.0.1 | ||
requests==2.24.0 | ||
six==1.15.0 | ||
sortedcontainers==2.2.2 | ||
sympy==1.6.2 | ||
toml==0.10.1 | ||
urllib3==1.25.10 | ||
Werkzeug==1.0.1 | ||
zipp==3.1.0 | ||
requests==2.24.0 | ||
sympy==1.6.2 | ||
latex2sympy==1.0.3 | ||
antlr4-python3-runtime==4.8 |