Skip to content

Commit d29cfc0

Browse files
authored
Merge pull request #285 from PySimpleSQL/pytest-rebased
Rebased pytest branch
2 parents 4a04456 + a7cfde8 commit d29cfc0

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

pysimplesql/pysimplesql.py

+21
Original file line numberDiff line numberDiff line change
@@ -3905,6 +3905,24 @@ def __init__(self, title: str, config: dict = None):
39053905
f"config may only contain keys: {default_config.keys()}"
39063906
)
39073907

3908+
for k in ["bar", "red", "green", "blue"]:
3909+
if k in config and not all(isinstance(v, (int, float)) for v in config[k]):
3910+
raise ValueError(f"values for {k} component must all be numeric")
3911+
required_keys = {"value_start", "value_range", "period", "offset"}
3912+
if k in config and not required_keys.issubset(set(config.keys())):
3913+
raise ValueError(f"{k} must contain all of {required_keys}")
3914+
3915+
if "phrases" in config:
3916+
if type(config["phrases"]) is not list:
3917+
raise ValueError("phrases must be a list")
3918+
if not all(isinstance(v, str) for v in config["phrases"]):
3919+
raise ValueError("phrases must be a list of strings")
3920+
3921+
if "phrase_delay" in config and not all(
3922+
isinstance(v, (int, float)) for v in config["phrase_delay"]
3923+
): # noqa SIM102
3924+
raise ValueError("phrase_delay must be numeric")
3925+
39083926
self.config = {**default_config, **config}
39093927

39103928
self.title = title
@@ -3930,6 +3948,9 @@ def run(self, fn: callable, *args, **kwargs):
39303948
Runs the function in a separate co-routine, while animating the progress bar in
39313949
another.
39323950
"""
3951+
if not callable(fn):
3952+
raise ValueError("fn must be a callable")
3953+
39333954
return asyncio.run(self._dispatch(fn, *args, **kwargs))
39343955

39353956
def close(self):

tests/progressanimate_test.py

+22-1
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,29 @@ def test_config():
4242
ss.ProgressAnimate("Test", config=True)
4343
# What if the user does supply a dict, but it doesn't have the right keys?
4444
with pytest.raises(NotImplementedError):
45-
# Purposely fail by
45+
# Purposely fail by using unsupported key
4646
config = {
4747
"sound_effect": "beep",
4848
}
4949
ss.ProgressAnimate("Test", config=config)
50+
# What if supplies a correct key, but does not have required subdict keys?
51+
with pytest.raises(ValueError):
52+
# purposely omit the offset
53+
config = {
54+
"red": {"value_start": 0, "value_range": 100, "period": 2},
55+
}
56+
ss.ProgressAnimate("Test", config=config)
57+
# What if the user does supply a dict, but it doesn't have the right values?
58+
with pytest.raises(ValueError):
59+
# Purposely fail by using unsupported value
60+
config = {
61+
"red": {"value_start": True, "value_range": "A", "period": 2, "offset": 0},
62+
"phrases": [True, 0, 3.14, "This one is good though"],
63+
}
64+
ss.ProgressAnimate("Test", config=config)
65+
66+
67+
def test_run():
68+
with pytest.raises(ValueError):
69+
pa = ss.ProgressAnimate("Test")
70+
pa.run(True)

0 commit comments

Comments
 (0)