Skip to content

Commit d195f84

Browse files
authored
Merge pull request #124 from AstuteSource/increase-testcoverage
Increase test coverage
2 parents d33c0e4 + 72e094f commit d195f84

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

tests/test_checks.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77

88
from chasten.checks import (
99
check_match_count,
10+
extract_description,
1011
extract_min_max,
1112
is_in_closed_interval,
13+
make_checks_status_message,
1214
)
1315
from chasten.validate import JSON_SCHEMA_CHECKS
1416

@@ -59,6 +61,41 @@ def test_extract_min_max_missing():
5961
assert max_count is None
6062

6163

64+
def test_extract_description():
65+
"""Confirm that if a description exists, it is properly retrieved."""
66+
check = {
67+
"name": "test",
68+
"description": "described test",
69+
"count": {
70+
"min": 1,
71+
},
72+
}
73+
assert "described test" == extract_description(check)
74+
75+
76+
def test_extract_desription_none():
77+
"""Confirm that if a description does not exist, an empty string is returned."""
78+
check = {
79+
"name": "test",
80+
"count": {
81+
"min": 1,
82+
},
83+
}
84+
assert "" == extract_description(check)
85+
86+
87+
@pytest.mark.parametrize(
88+
"bool_status,expected",
89+
[
90+
(True, ":smiley: Did the check pass? Yes"),
91+
(False, ":worried: Did the check pass? No"),
92+
],
93+
)
94+
def test_make_checks_status_message(bool_status: bool, expected: str):
95+
"""Confirms the output matches the expected message."""
96+
assert make_checks_status_message(bool_status) == expected
97+
98+
6299
@given(st.dictionaries(st.text(), st.integers()))
63100
@pytest.mark.fuzz
64101
def test_extract_min_max_hypothesis(check):
@@ -89,6 +126,8 @@ def test_integers(check):
89126
(1, None, None, True),
90127
(5, 6, 4, False),
91128
(1, 4, 6, False),
129+
(1, 2, None, False),
130+
(3, None, 2, False),
92131
],
93132
)
94133
def test_check_match_count_expected(count, min_value, max_value, expected):

tests/test_database.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""Pytest test suite for the database module."""
2+
3+
import os
4+
5+
from chasten import database
6+
7+
8+
def test_create_chasten_view():
9+
"""Confirm that the function creating and viewing an example database does not crash"""
10+
# define the variable name for the example database
11+
chasten_database_name: str = ".example_database"
12+
# create the database with example name
13+
# run the view command with a set SQL query
14+
database.create_chasten_view(chasten_database_name)
15+
# remove the example variable made
16+
os.remove(".example_database")

tests/test_filesystem.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def test_invalid_directory() -> None:
2525
directory = pathlib.Path(directory_str)
2626
confirmation = filesystem.confirm_valid_directory(directory)
2727
assert confirmation is False
28+
assert filesystem.confirm_valid_directory(None) is False
2829

2930

3031
def test_valid_file() -> None:
@@ -41,6 +42,7 @@ def test_invalid_file() -> None:
4142
this_file_not = pathlib.Path(file_str)
4243
confirmation = filesystem.confirm_valid_file(this_file_not)
4344
assert confirmation is False
45+
assert filesystem.confirm_valid_file(None) is False
4446

4547

4648
@given(directory=strategies.builds(pathlib.Path))

0 commit comments

Comments
 (0)