Skip to content

Commit 827cbf7

Browse files
authored
test: invalid config path (#89)
* test: invalid config path * tests: main function
1 parent 09431b0 commit 827cbf7

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

tests/test_waybar_crypto.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from unittest import mock
66
import logging
77
import configparser
8+
import json
89

910
from waybar_crypto import (
1011
API_KEY_ENV,
@@ -20,6 +21,7 @@
2021
ResponseQuotesLatest,
2122
WaybarCrypto,
2223
WaybarCryptoException,
24+
main,
2325
parse_args,
2426
read_config,
2527
)
@@ -362,6 +364,11 @@ def test_read_config_no_api_key():
362364
_ = read_config(tmp_config_path)
363365

364366

367+
def test_read_config_invalid_path():
368+
with pytest.raises(WaybarCryptoException):
369+
_ = read_config("/invalid/config.ini")
370+
371+
365372
class TestWaybarCrypto:
366373
"""Tests for the WaybarCrypto."""
367374

@@ -422,3 +429,21 @@ def test_no_api_key(self, config: Config):
422429
with pytest.raises(NoApiKeyException):
423430
config["general"]["api_key"] = ""
424431
_ = WaybarCrypto(config)
432+
433+
434+
@pytest.mark.skipif(API_KEY is None, reason=f"test API key not provided in '{TEST_API_KEY_ENV}'")
435+
@mock.patch.dict(os.environ, {API_KEY_ENV: API_KEY})
436+
@mock.patch("sys.argv", ["waybar_crypto.py", "--config-path", "./config.ini.example"])
437+
def test_main(capsys):
438+
main()
439+
captured = capsys.readouterr()
440+
waybar_obj = json.loads(captured.out)
441+
assert "text" in waybar_obj
442+
assert "tooltip" in waybar_obj
443+
assert "class" in waybar_obj
444+
445+
446+
@mock.patch("sys.argv", ["waybar_crypto.py", "--config-path", "/invalid/config.ini"])
447+
def test_main_config_path_invalid():
448+
with pytest.raises(WaybarCryptoException):
449+
main()

0 commit comments

Comments
 (0)