Skip to content

Commit

Permalink
test: invalid display option (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
chadsr committed May 27, 2024
1 parent 63e0a42 commit baf36df
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
17 changes: 17 additions & 0 deletions tests/test_waybar_crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,23 @@ def test_read_config_default_display_options():
assert display_options == DEFAULT_DISPLAY_OPTIONS


def test_read_config_display_invalid():
with open(TEST_CONFIG_PATH, "r", encoding="utf-8") as f:
cfp = configparser.ConfigParser(allow_no_value=True, interpolation=None)
cfp.read_file(f)
cfp.set("general", "display", "notvalid")

with tempfile.NamedTemporaryFile(mode="w") as tmp:
cfp.write(tmp)
tmp.flush()
tmp_config_path = tmp.file.name

try:
_ = read_config(tmp_config_path)
except Exception as e:
assert isinstance(e, WaybarCryptoException)


class TestWaybarCrypto:
"""Tests for the WaybarCrypto."""

Expand Down
2 changes: 1 addition & 1 deletion waybar_crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def read_config(config_path: str) -> Config:

for display_option in display_options:
if display_option not in DEFAULT_DISPLAY_OPTIONS_FORMAT:
raise WaybarCryptoException(f"invalid display option '{display_option}")
raise WaybarCryptoException(f"invalid display option '{display_option}'")

display_options_format = DEFAULT_DISPLAY_OPTIONS_FORMAT
display_format_price = display_options_format["price"]
Expand Down

0 comments on commit baf36df

Please sign in to comment.