Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests #530

Merged
merged 14 commits into from
Jan 2, 2024
Merged

Tests #530

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,15 @@ jobs:
run: |
python Otherfiles/requirements-splitter.py
pip install --upgrade --upgrade-strategy=only-if-needed -r test-requirements.txt
- name: Test with pytest
- name: Test with pytest (Basic)
run: |
python -m pytest --cov=pycm --cov-report=term
python -m pytest --cov=pycm --cov-report=term --ignore-glob=Test/plot_test.py
- name: Plot requirements Installation
run: |
pip install --upgrade --upgrade-strategy=only-if-needed -r plot-requirements.txt
- name: Test with pytest (+Plot)
run: |
python -m pytest --cov=pycm --cov-report=term --ignore-glob=Test/plot_error_test.py
- name: Version check
run: |
python Otherfiles/version_check.py
Expand Down
13 changes: 12 additions & 1 deletion Otherfiles/requirements-splitter.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
# -*- coding: utf-8 -*-
"""Requirements splitter."""

PLOT_LIB_LIST = ["matplotlib", "seaborn"]
test_req = ""
plot_req = ""

with open('dev-requirements.txt', 'r') as f:
for line in f:
if '==' not in line:
plot_lib_flag = False
for lib in PLOT_LIB_LIST:
if line.find(lib) != -1:
plot_lib_flag = True
plot_req += line
break
if '==' not in line and not plot_lib_flag:
test_req += line

with open('test-requirements.txt', 'w') as f:
f.write(test_req)

with open('plot-requirements.txt', 'w') as f:
f.write(plot_req)
9 changes: 9 additions & 0 deletions Test/function_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,20 @@
...
>>> online_help(4)
...
>>> from pycm.pycm_output import *
>>> from pycm.pycm_overall_func import *
>>> from pycm.pycm_class_func import *
>>> from pycm.pycm_ci import *
>>> from pycm.pycm_interpret import *
>>> from pycm.pycm_util import *
>>> color_check("red")
[255, 0, 0]
>>> color_check((255,2,2))
[255, 2, 2]
>>> color_check(None)
[0, 0, 0]
>>> color_check("wrong_color")
[0, 0, 0]
>>> inv_erf(-1)
'None'
>>> inv_erf(1)
Expand Down
12 changes: 12 additions & 0 deletions Test/output_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
>>> save_stat=cm.save_stat("test_filtered3", address=False, overall_param=["Kappa", "Scott PI"], class_param=["TPR", "TNR", "ACC", "AUC"], class_name=[])
>>> save_stat=={'Status': True, 'Message': None}
True
>>> save_stat=cm.save_stat("test_filtered4", address=False, overall_param=["Wrong_param"], class_param=["Wrong_param"], class_name=["L1", "L2"])
>>> save_stat=={'Status': True, 'Message': None}
True
>>> large_cm = ConfusionMatrix(list(range(20)), list(range(20)))
>>> save_stat = large_cm.save_stat("test_large", address=False)
>>> save_stat == {'Status': True, 'Message': None}
Expand Down Expand Up @@ -59,6 +62,9 @@
>>> save_stat=cm.save_html("test_filtered5", address=False, overall_param=[], class_param=["TPR", "TNR", "ACC", "AUC"], class_name=[100])
>>> save_stat=={'Status': True, 'Message': None}
True
>>> save_stat=cm.save_html("test_filtered6", address=False, overall_param=["Wrong_param"], class_param=["Wrong_param"], class_name=[100])
>>> save_stat=={'Status': True, 'Message': None}
True
>>> save_stat=cm.save_html("test_colored", address=False, color=(130, 100, 200))
>>> save_stat=={'Status': True, 'Message': None}
True
Expand Down Expand Up @@ -96,6 +102,9 @@
>>> save_stat=cm.save_csv("test_filtered4", address=False, class_param=[], class_name=[100], matrix_save=False)
>>> save_stat=={'Status': True, 'Message': None}
True
>>> save_stat=cm.save_csv("test_filtered5", address=False, class_param=["Wrong_param"], class_name=[100], matrix_save=False)
>>> save_stat=={'Status': True, 'Message': None}
True
>>> save_stat=cm.save_csv("/asdasd, qweqwe.eo/", address=True)
>>> save_stat=={'Status': False, 'Message': "[Errno 2] No such file or directory: '/asdasd, qweqwe.eo/.csv'"}
True
Expand Down Expand Up @@ -754,6 +763,7 @@
>>> os.remove("test_filtered3.html")
>>> os.remove("test_filtered4.html")
>>> os.remove("test_filtered5.html")
>>> os.remove("test_filtered6.html")
>>> os.remove("test_long_name.html")
>>> os.remove("test_shortener.html")
>>> os.remove("test_alt.html")
Expand All @@ -763,9 +773,11 @@
>>> os.remove("test_filtered2.csv")
>>> os.remove("test_filtered3.csv")
>>> os.remove("test_filtered4.csv")
>>> os.remove("test_filtered5.csv")
>>> os.remove("test_summary.csv")
>>> os.remove("test_filtered2.pycm")
>>> os.remove("test_filtered3.pycm")
>>> os.remove("test_filtered4.pycm")
>>> os.remove("test2.obj")
>>> os.remove("test3.obj")
>>> os.remove("test3_np.obj")
Expand Down
2 changes: 2 additions & 0 deletions Test/overall_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,8 @@
>>> cm.normalized_matrix == cm.normalized_table
True
>>> assert isclose(cm.Y["L2"], 0.2222222222222221, abs_tol=ABS_TOL, rel_tol=REL_TOL)
>>> assert isclose(cm.CI("TPR")["L2"][0], 0.2721655269759087, abs_tol=ABS_TOL, rel_tol=REL_TOL)
>>> assert isclose(cm.CI("TPR", binom_method=None)["L2"][0], 0.2721655269759087, abs_tol=ABS_TOL, rel_tol=REL_TOL)
>>> import numpy as np
>>> y_test = np.array([600, 200, 200, 200, 200, 200, 200, 200, 500, 500, 500, 200, 200, 200, 200, 200, 200, 200, 200, 200])
>>> y_test_copy = np.array([600, 200, 200, 200, 200, 200, 200, 200, 500, 500, 500, 200, 200, 200, 200, 200, 200, 200, 200, 200])
Expand Down
31 changes: 31 additions & 0 deletions Test/plot_error_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# -*- coding: utf-8 -*-
"""
>>> from pycm import *
>>> import numpy as np
>>> y_act = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2]
>>> y_pre = [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 2, 0, 1, 2, 2, 2, 2]
>>> cm = ConfusionMatrix(y_act, y_pre)
>>> cm.print_matrix()
Predict 0 1 2
Actual
0 9 3 0
<BLANKLINE>
1 3 5 1
<BLANKLINE>
2 1 1 4
<BLANKLINE>
<BLANKLINE>
>>> ax = cm.plot()
Traceback (most recent call last):
...
pycm.pycm_error.pycmPlotError: Error in importing matplotlib module. Please install it using this command: pip install matplotlib
>>> ax = cm.plot(plot_lib='seaborn')
Traceback (most recent call last):
...
pycm.pycm_error.pycmPlotError: Error in importing seaborn module. Please install it using this command: pip install seaborn
>>> crv = Curve(actual_vector = np.array([1, 1, 2, 2]), probs = np.array([[0.1, 0.9], [0.4, 0.6], [0.35, 0.65], [0.8, 0.2]]), classes=[2, 1])
>>> ax = crv.plot(classes=[1])
Traceback (most recent call last):
...
pycm.pycm_error.pycmPlotError: Error in importing matplotlib module. Please install it using this command: pip install matplotlib
"""
2 changes: 1 addition & 1 deletion pytest.ini
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# content of pytest.ini
[pytest]
addopts = --doctest-modules --ignore=Otherfiles
addopts = --doctest-modules --ignore=Otherfiles --cov-append
doctest_optionflags= NORMALIZE_WHITESPACE IGNORE_EXCEPTION_DETAIL
Loading