Skip to content

Rebased pytest branch #285

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

Merged
merged 1 commit into from
Apr 14, 2023
Merged
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
21 changes: 21 additions & 0 deletions pysimplesql/pysimplesql.py
Original file line number Diff line number Diff line change
Expand Up @@ -3905,6 +3905,24 @@ def __init__(self, title: str, config: dict = None):
f"config may only contain keys: {default_config.keys()}"
)

for k in ["bar", "red", "green", "blue"]:
if k in config and not all(isinstance(v, (int, float)) for v in config[k]):
raise ValueError(f"values for {k} component must all be numeric")
required_keys = {"value_start", "value_range", "period", "offset"}
if k in config and not required_keys.issubset(set(config.keys())):
raise ValueError(f"{k} must contain all of {required_keys}")

if "phrases" in config:
if type(config["phrases"]) is not list:
raise ValueError("phrases must be a list")
if not all(isinstance(v, str) for v in config["phrases"]):
raise ValueError("phrases must be a list of strings")

if "phrase_delay" in config and not all(
isinstance(v, (int, float)) for v in config["phrase_delay"]
): # noqa SIM102
raise ValueError("phrase_delay must be numeric")

self.config = {**default_config, **config}

self.title = title
Expand All @@ -3930,6 +3948,9 @@ def run(self, fn: callable, *args, **kwargs):
Runs the function in a separate co-routine, while animating the progress bar in
another.
"""
if not callable(fn):
raise ValueError("fn must be a callable")

return asyncio.run(self._dispatch(fn, *args, **kwargs))

def close(self):
Expand Down
23 changes: 22 additions & 1 deletion tests/progressanimate_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,29 @@ def test_config():
ss.ProgressAnimate("Test", config=True)
# What if the user does supply a dict, but it doesn't have the right keys?
with pytest.raises(NotImplementedError):
# Purposely fail by
# Purposely fail by using unsupported key
config = {
"sound_effect": "beep",
}
ss.ProgressAnimate("Test", config=config)
# What if supplies a correct key, but does not have required subdict keys?
with pytest.raises(ValueError):
# purposely omit the offset
config = {
"red": {"value_start": 0, "value_range": 100, "period": 2},
}
ss.ProgressAnimate("Test", config=config)
# What if the user does supply a dict, but it doesn't have the right values?
with pytest.raises(ValueError):
# Purposely fail by using unsupported value
config = {
"red": {"value_start": True, "value_range": "A", "period": 2, "offset": 0},
"phrases": [True, 0, 3.14, "This one is good though"],
}
ss.ProgressAnimate("Test", config=config)


def test_run():
with pytest.raises(ValueError):
pa = ss.ProgressAnimate("Test")
pa.run(True)