-
Notifications
You must be signed in to change notification settings - Fork 3
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 #10 from jdebacker/testing
Add additional unit tests and GH Action to run tests
- Loading branch information
Showing
6 changed files
with
156 additions
and
1 deletion.
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,44 @@ | ||
name: Build and test [Python 3.7, 3.8, 3.9] | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python-version: [3.7, 3.8, 3.9] | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
with: | ||
persist-credentials: false | ||
|
||
- name: Setup Miniconda using Python ${{ matrix.python-version }} | ||
uses: conda-incubator/setup-miniconda@v2 | ||
with: | ||
activate-environment: ogmys-dev | ||
environment-file: environment.yml | ||
python-version: ${{ matrix.python-version }} | ||
auto-activate-base: false | ||
|
||
- name: Build | ||
shell: bash -l {0} | ||
run: | | ||
pip install -e . | ||
pip install pytest-cov | ||
pip install pytest-pycodestyle | ||
- name: Test | ||
shell: bash -l {0} | ||
working-directory: ./ | ||
run: | | ||
pytest -m 'not local and not regression' --cov=./ --cov-report=xml | ||
- name: Upload coverage to Codecov | ||
uses: codecov/codecov-action@v2 | ||
with: | ||
files: ./coverage.xml | ||
flags: unittests | ||
name: codecov-umbrella | ||
fail_ci_if_error: true | ||
verbose: 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,14 @@ | ||
name: Check Black formatting | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
lint: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-python@v2 | ||
- uses: psf/black@stable | ||
with: | ||
options: "-l 79 --check" | ||
src: "." |
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,47 @@ | ||
""" | ||
Tests of calibrate.py module | ||
""" | ||
|
||
import pytest | ||
import numpy as np | ||
import os | ||
import ogcore | ||
from ogmys.calibrate import Calibration | ||
|
||
CUR_PATH = os.path.abspath(os.path.dirname(__file__)) | ||
|
||
|
||
def test_calibrate(): | ||
p = ogcore.Specifications() | ||
_ = Calibration(p) | ||
|
||
|
||
def test_read_tax_func_estimate_error(): | ||
with pytest.raises(RuntimeError): | ||
p = ogcore.Specifications() | ||
tax_func_path = os.path.join( | ||
CUR_PATH, "test_io_data", "TxFuncEst_policy.pkl" | ||
) | ||
c = Calibration(p) | ||
_, _ = c.read_tax_func_estimate(p, tax_func_path) | ||
|
||
|
||
def test_read_tax_func_estimate(): | ||
p = ogcore.Specifications() | ||
p.BW = 11 | ||
tax_func_path = os.path.join( | ||
CUR_PATH, "test_io_data", "TxFuncEst_policy.pkl" | ||
) | ||
c = Calibration(p) | ||
dict_params, _ = c.read_tax_func_estimate(p, tax_func_path) | ||
print("Dict keys = ", dict_params.keys()) | ||
|
||
assert isinstance(dict_params["tfunc_etr_params_S"], np.ndarray) | ||
|
||
|
||
def test_get_dict(): | ||
p = ogcore.Specifications() | ||
c = Calibration(p) | ||
c_dict = c.get_dict() | ||
|
||
assert isinstance(c_dict, dict) |
Binary file not shown.
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,43 @@ | ||
""" | ||
This model tests whether using the `OG-MYS/examples/run_og_mys.py` | ||
work by making sure that it does not break (is still running) after | ||
5 minutes (300 seconds). | ||
""" | ||
import multiprocessing | ||
import time | ||
import os | ||
import sys | ||
import importlib.util | ||
from pathlib import Path | ||
import pytest | ||
|
||
|
||
def call_run_og_mys(): | ||
cur_path = os.path.split(os.path.abspath(__file__))[0] | ||
path = Path(cur_path) | ||
roe_fldr = os.path.join(path.parent.parent, "examples") | ||
roe_file_path = os.path.join(roe_fldr, "run_og_mys.py") | ||
spec = importlib.util.spec_from_file_location( | ||
"run_og_mys.py", roe_file_path | ||
) | ||
roe_module = importlib.util.module_from_spec(spec) | ||
sys.modules["run_og_mys.py"] = roe_module | ||
spec.loader.exec_module(roe_module) | ||
roe_module.main() | ||
|
||
|
||
@pytest.mark.local | ||
def test_run_og_mys(f=call_run_og_mys): | ||
p = multiprocessing.Process(target=f, name="run_og_mys", args=()) | ||
p.start() | ||
time.sleep(300) | ||
if p.is_alive(): | ||
p.terminate() | ||
p.join() | ||
timetest = True | ||
else: | ||
print("run_og_mys.py did not run for minimum time") | ||
timetest = False | ||
print("timetest ==", timetest) | ||
|
||
assert timetest |