-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
81 additions
and
22 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,31 @@ | ||
name: VLM Unit Tests | ||
|
||
# Run the test suite on pushes (incl. merges) to master and dev | ||
# Run the test suite when a PR is opened, pushed to, or reopened | ||
on: | ||
push: | ||
branches: | ||
- master | ||
- dev | ||
paths: | ||
- 'vlm/**' | ||
pull_request: | ||
types: [opened, synchronize, reopened] | ||
paths: | ||
- 'vlm/**' | ||
|
||
jobs: | ||
vlm: | ||
runs-on: ubuntu-latest | ||
container: hailgenetics/hail:0.2.128 | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Install dependencies | ||
run: | | ||
python3 -m pip install --upgrade pip wheel | ||
pip install -r vlm/requirements-test.txt | ||
- name: Run coverage tests | ||
run: | | ||
coverage run --source="./vlm" --omit="./vlm/__main__.py" -m pytest vlm/ | ||
coverage report --fail-under=99 |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from aiohttp.test_utils import AioHTTPTestCase | ||
|
||
from vlm.web_app import init_web_app | ||
|
||
|
||
class VlmTestCase(AioHTTPTestCase): | ||
|
||
async def get_application(self): | ||
return await init_web_app() | ||
|
||
async def test_status(self): | ||
async with self.client.request('GET', '/status') as resp: | ||
self.assertEqual(resp.status, 200) | ||
resp_json = await resp.json() | ||
self.assertDictEqual(resp_json, {'success': 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from aiohttp import web | ||
import logging | ||
import traceback | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def _handle_exception(e, request): | ||
logger.error(f'{request.headers.get("From")} "{e}"') | ||
raise e | ||
|
||
|
||
@web.middleware | ||
async def error_middleware(request, handler): | ||
try: | ||
return await handler(request) | ||
except web.HTTPError as e: | ||
_handle_exception(e, request) | ||
except Exception as e: | ||
error_reason = f'{e}: {traceback.format_exc()}' | ||
_handle_exception(web.HTTPInternalServerError(reason=error_reason), request) | ||
|
||
|
||
async def status(request: web.Request) -> web.Response: | ||
return web.json_response({'success': True}) | ||
|
||
|
||
async def init_web_app(): | ||
app = web.Application(middlewares=[error_middleware], client_max_size=(1024 ** 2) * 10) | ||
app.add_routes([ | ||
web.get('/status', status), | ||
]) | ||
return app |