Skip to content

Commit 0231a6b

Browse files
committed
Added tests to ensure branch coverage
1 parent d85be3a commit 0231a6b

File tree

2 files changed

+43
-5
lines changed

2 files changed

+43
-5
lines changed

eda_utils_py/eda_utils_py.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,20 +85,20 @@ def cor_map(dataframe, num_col, col_scheme = 'purpleorange'):
8585

8686
# Tests whether input data is of pd.DataFrame type
8787
if not isinstance(dataframe, pd.DataFrame):
88-
raise Exception("The input dataframe must be of pd.DataFrame type")
88+
raise TypeError("The input dataframe must be of pd.DataFrame type")
8989

9090
# Tests whether input num_col is of type list
9191
if not isinstance(num_col, list):
92-
raise Exception("The input num_col must be of type list")
92+
raise TypeError("The input num_col must be of type list")
9393

9494
# Tests whether values of num_col is of type str
9595
for x in num_col:
9696
if not isinstance(x, str):
97-
raise Exception("The type of values in num_col must all be str")
97+
raise TypeError("The type of values in num_col must all be str")
9898

9999
# Tests whether input col_scheme is of type str
100100
if not isinstance(col_scheme, str):
101-
raise Exception("col_scheme must be of type str")
101+
raise TypeError("col_scheme must be of type str")
102102

103103
# Tests whether col_scheme is one of three possible options
104104
if col_scheme not in ('purpleorange', 'blueorange', 'redblue'):

tests/test_eda_utils_py.py

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from eda_utils_py import __version__
22
from eda_utils_py import eda_utils_py
3+
from pytest import raises
34
import pandas as pd
45

56
def test_version():
@@ -42,4 +43,41 @@ def test_cor_map():
4243
# Tests whether axes is using correct calculated var column as reference
4344
assert plot_dict['layer'][0]['encoding']['x']['field'] == 'var1', "x should be referring to var1"
4445
assert plot_dict['layer'][0]['encoding']['y']['field'] == 'var2', "y should be referring to var2"
45-
46+
47+
48+
# Testing the Exception Errors
49+
data2 = data.copy().to_csv()
50+
51+
num_col_test1 = (1, 2, 3, 4)
52+
num_col_test2 = [1, 2, 3, 'SepalLengthCm']
53+
num_col_test3 = ['hi', 'hey', 'hi']
54+
num_col_test4 = ['SepalLengthCm', 'SepalWidthCm', 'PetalWidthCm', 'Species']
55+
col_scheme_test = 3
56+
57+
# Tests whether data is not of dataframe raises TypeError
58+
with raises(TypeError):
59+
eda_utils_py.cor_map(data2, num_col_test)
60+
61+
# Tests whether num_col is of not type list raises TypeError
62+
with raises(TypeError):
63+
eda_utils_py.cor_map(data, num_col_test1)
64+
65+
# Tests whether contents of num_col is notof type str raises TypeError
66+
with raises(TypeError):
67+
eda_utils_py.cor_map(data, num_col_test2)
68+
69+
# Tests whether inputting unallowed col_scheme raises Exception
70+
with raises(Exception):
71+
eda_utils_py.cor_map(data, num_col_test, 'bluegreen')
72+
73+
# Tests whether inputting unallowed col_scheme raises TypeError
74+
with raises(TypeError):
75+
eda_utils_py.cor_map(data, num_col_test, col_scheme_test)
76+
77+
# Tests whether columns do not exist in raises Exception
78+
with raises(Exception):
79+
eda_utils_py.cor_map(data, num_col_test3)
80+
81+
# Tests whether if not all columns in num_col is numeric raises Exception
82+
with raises(Exception):
83+
eda_utils_py.cor_map(data, num_col_test4)

0 commit comments

Comments
 (0)