Skip to content

Commit

Permalink
adding helper function for printing and asserting outcome of each test
Browse files Browse the repository at this point in the history
  • Loading branch information
dvatterott committed Jan 4, 2019
1 parent bf216ec commit 45fca9b
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 1 deletion.
7 changes: 7 additions & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,10 @@ CategoricalEvaluator
:members:
:inherited-members:
:show-inheritance:

Utilities
---------
.. automodule:: predeval.utilities
:members:
:inherited-members:
:show-inheritance:
8 changes: 8 additions & 0 deletions docs/source/predeval.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ predeval.parent module
:inherited-members:
:show-inheritance:

predeval.utilities module
----------------------

.. automodule:: predeval.utilities
:members:
:inherited-members:
:show-inheritance:


Module contents
---------------
Expand Down
5 changes: 4 additions & 1 deletion predeval/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@

from .continuous import ContinuousEvaluator
from .categorical import CategoricalEvaluator
from .utilities import evaluate_tests

__all__ = ['ContinuousEvaluator', 'CategoricalEvaluator']
__all__ = ['ContinuousEvaluator',
'CategoricalEvaluator',
'evaluate_tests']
17 changes: 17 additions & 0 deletions predeval/parent.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,23 @@
class ParentPredEval(object):
"""
Parent Class for evaluator classes.
...
Parameters
----------
ref_data : list of int or float or np.array
This the reference data for all tests. All future data will be compared to this data.
verbose : bool, optional
Whether tests should print their output. Default is true
Attributes
----------
verbose : bool
Whether or not tests will print output.
ref_data : : list of int or float or np.array
This the reference data for all tests. All future data will be compared to this data.
"""
__metaclass__ = ABCMeta

Expand Down
34 changes: 34 additions & 0 deletions predeval/utilities.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""Library of classes for evaluating continuous model outputs."""

__author__ = 'Dan Vatterott'
__license__ = 'MIT'


def evaluate_tests(test_ouputs, assert_test=False, verbose=True):
"""Check whether the data passed evaluation tests.
Parameters
----------
test_ouputs : list of tuples
Each tuple has a string a boolean. The string describes the test.
The boolean describes the outcome. True is a pass and False is a fail.
This is the output of the check_data method.
assert_test : bool
Whether to assert the test passed. Default is False.
verbose : bool
Whether to print whether each test was passed or not.
Returns
-------
None
"""
for test_name, test_val in test_ouputs:
if test_val:
if verbose:
print('Passed {} test.'.format(test_name))
else:
if verbose:
print('Failed {} test.'.format(test_name))
if assert_test:
assert test_val, 'Error. Failed {} test.'

0 comments on commit 45fca9b

Please sign in to comment.