Skip to content

Commit

Permalink
Merge pull request #4 from oda-hub/unit-tests
Browse files Browse the repository at this point in the history
Unit tests
  • Loading branch information
volodymyrss committed Apr 28, 2021
2 parents fcb60bb + 8d2cd74 commit 55e69c9
Show file tree
Hide file tree
Showing 9 changed files with 162 additions and 16 deletions.
18 changes: 18 additions & 0 deletions .github/styles/vocab.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
gitlab
github
redmine
bugfix
hotfix
bugfixes
mattermost
calver
astro
codecov
Volodymyr
Savchenko
Tramacere
Versoix
Chemin
cdci
antares
config
26 changes: 26 additions & 0 deletions .github/workflows/prose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Prose Linting
on: [push]

jobs:
prose:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@master

- name: Vale
uses: errata-ai/vale-action@v1.2.0
with:
# Optional
styles: |
https://github.com/errata-ai/Microsoft/releases/latest/download/Microsoft.zip
https://github.com/errata-ai/write-good/releases/latest/download/write-good.zip
# Optional
config: https://raw.githubusercontent.com/errata-ai/vale/master/.vale.ini

# Optional
files: '["README.md"]'
env:
# Required
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
55 changes: 55 additions & 0 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Python application

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]



jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest mypy pylint coverage
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics || echo "failed lint"
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics || echo "failed second lint"
- name: PyLint - more lint
run: |
pylint -E dispatcher_plugin_antares || echo 'this is fine!'
- name: MyPy
run: |
mypy dispatcher_plugin_antares --ignore-missing-imports || echo 'this is fine too!'
- name: Test with pytest
run: |
python -m coverage run --source=dispatcher_plugin_antares -m pytest tests -sv --full-trace --log-cli-level=DEBUG
# I wonder how this interacts with the Github App. But this is not only for PR. Also this does not always work
- name: Codecov
uses: codecov/codecov-action@v1.3.1
with:
token: ${{ secrets.CODECOV_TOKEN }}
verbose: true
19 changes: 7 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,23 @@
ANTARES cdci plugin
ANTARES ODA plugin
==========================================
*ANTARES plugin for cdci_data_analysis*


What's the license?
-------------------

ANTARES cdci plugin is distributed under the terms of The MIT License.
ANTARES plugin is distributed under the terms of The MIT License.

Who's responsible?
-------------------
Andrea Tramacere
Denys Savchenko, Andrea Tramacere

ISDC Data Centre for Astrophysics, Astronomy Department of the University of Geneva, Chemin d'Ecogia 16, CH-1290 Versoix, Switzerland
Astronomy Department of the University of Geneva, Chemin d'Ecogia 16, CH-1290 Versoix, Switzerland

Configuration for deployment
----------------------------
- copy the conf_file from 'cdci_antares_plugin/config_dir/data_server_conf.yml' and place in given directory
- set the env var `CDCI_ANTARES_PLUGIN_CONF_FILE` to the path of the file conf_file
- edit the in conf_file the two keys:
- copy the `conf_file` from `dispatcher_plugin_antares/config_dir/data_server_conf.yml' and place in given directory
- set the environment variable `CDCI_ANTARES_PLUGIN_CONF_FILE` to the path of the file conf_file
- edit the in `conf_file` the key:
- `data_server_url:`

these two keys must correspond to those in the antares-backend conf_file ie:

- `data_server_url:` -> `url:`

respectively
3 changes: 2 additions & 1 deletion dispatcher_plugin_antares/antares_dataserver_dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ def test_communication(self, max_trial=10, sleep_s=1,logger=None):
print('status_code',res.status_code)
if res.status_code !=200:
no_connection =True
e = ConnectionError(f"Backend connection failed: {res.status_code}")
else:
no_connection=False

Expand All @@ -214,7 +215,7 @@ def test_communication(self, max_trial=10, sleep_s=1,logger=None):
query_out.set_failed(message,
message='connection_status=%s' % connection_status_message,
logger=logger,
excep=e, # may be referenced before assignment
excep=e,
e_message=message,
debug_message=debug_message)

Expand Down
1 change: 1 addition & 0 deletions dispatcher_plugin_antares/config_dir/data_server_conf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ instruments:
antares:
data_server_url: http://localhost:5002
data_server_port: 5002
dummy_cache: dangerously-not-set-to-anything-useful


6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cdci_data_analysis
#pandas
# move to master or pypi later
-e git+https://github.com/oda-hub/dispatcher-app@reusable-fixture#egg=cdci_data_analysis
astropy
simple_logger
numpy
numpy
7 changes: 7 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# we could make a plugin, but it's more effort

from cdci_data_analysis.pytest_fixtures import (
dispatcher_live_fixture,
dispatcher_test_conf,
app
)
43 changes: 43 additions & 0 deletions tests/test_plugin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import requests
import time
import json
import logging

import pytest


logger = logging.getLogger(__name__)

default_params = dict(
query_status="new",
query_type="Real",
instrument="antares",
product_type="antares_spectrum",
T1="2008-03-19T06:11:11.0",
T2="2008-03-19T06:12:11.0",
async_dispatcher=False,
)

def test_discover_plugin():
import cdci_data_analysis.plugins.importer as importer

assert 'dispatcher_plugin_antares' in importer.cdci_plugins_dict.keys()


@pytest.mark.xfail
def test_default(dispatcher_live_fixture):
server = dispatcher_live_fixture

logger.info("constructed server: %s", server)
c = requests.get(server + "/run_analysis",
params = default_params)

logger.info("content: %s", c.text)
jdata = c.json()
logger.info(json.dumps(jdata, indent=4, sort_keys=True))
logger.info(jdata)
assert c.status_code == 200

assert jdata['job_status'] == 'done'


0 comments on commit 55e69c9

Please sign in to comment.