Skip to content

Commit

Permalink
test: invalid config path (#89)
Browse files Browse the repository at this point in the history
* test: invalid config path

* tests: main function
  • Loading branch information
chadsr authored May 27, 2024
1 parent 09431b0 commit 827cbf7
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions tests/test_waybar_crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from unittest import mock
import logging
import configparser
import json

from waybar_crypto import (
API_KEY_ENV,
Expand All @@ -20,6 +21,7 @@
ResponseQuotesLatest,
WaybarCrypto,
WaybarCryptoException,
main,
parse_args,
read_config,
)
Expand Down Expand Up @@ -362,6 +364,11 @@ def test_read_config_no_api_key():
_ = read_config(tmp_config_path)


def test_read_config_invalid_path():
with pytest.raises(WaybarCryptoException):
_ = read_config("/invalid/config.ini")


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

Expand Down Expand Up @@ -422,3 +429,21 @@ def test_no_api_key(self, config: Config):
with pytest.raises(NoApiKeyException):
config["general"]["api_key"] = ""
_ = WaybarCrypto(config)


@pytest.mark.skipif(API_KEY is None, reason=f"test API key not provided in '{TEST_API_KEY_ENV}'")
@mock.patch.dict(os.environ, {API_KEY_ENV: API_KEY})
@mock.patch("sys.argv", ["waybar_crypto.py", "--config-path", "./config.ini.example"])
def test_main(capsys):
main()
captured = capsys.readouterr()
waybar_obj = json.loads(captured.out)
assert "text" in waybar_obj
assert "tooltip" in waybar_obj
assert "class" in waybar_obj


@mock.patch("sys.argv", ["waybar_crypto.py", "--config-path", "/invalid/config.ini"])
def test_main_config_path_invalid():
with pytest.raises(WaybarCryptoException):
main()

0 comments on commit 827cbf7

Please sign in to comment.