Skip to content

Commit c291a5b

Browse files
committed
Update unit tests for all possible keyword inputs.
1 parent 1eda8ac commit c291a5b

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

pyspi/utils.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,11 @@ def filter_spis(keywords, output_name=None, configfile=None):
158158
FileNotFoundError: If the specified `configfile` or the default `config.yaml` is not found.
159159
IOError: If there's an error reading the YAML file.
160160
"""
161+
# handle invalid keyword input
162+
if not keywords:
163+
raise ValueError("At least one keyword must be provided.")
164+
if not all(isinstance(keyword, str) for keyword in keywords):
165+
raise ValueError("All keywords must be strings.")
161166
if not isinstance(keywords, list):
162167
raise ValueError("Keywords must be provided as a list of strings.")
163168

tests/test_utils.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,16 @@ def mock_yaml_content():
1717

1818
def test_filter_spis_invalid_keywords():
1919
"""Pass in a dataype other than a list for the keywords"""
20-
with pytest.raises(ValueError) as e:
20+
with pytest.raises(ValueError) as excinfo:
2121
filter_spis(keywords="linear", configfile="pyspi/config.yaml")
22+
assert "Keywords must be provided as a list of strings" in str(excinfo.value)
23+
# check for passing in an empty list
24+
with pytest.raises(ValueError) as excinfo:
25+
filter_spis(keywords=[], configfile="pyspi/config.yaml")
26+
assert "At least one keyword must be provided" in str(excinfo.value)
27+
with pytest.raises(ValueError) as excinfo:
28+
filter_spis(keywords=[4], configfile="pyspi/config.yaml")
29+
assert "All keywords must be strings" in str(excinfo.value)
2230

2331
def test_filter_spis_with_invalid_config():
2432
"""Pass in an invalid/missing config file"""

0 commit comments

Comments
 (0)