diff --git a/tests/test_waybar_crypto.py b/tests/test_waybar_crypto.py index 9b7ca1f..7466b1a 100644 --- a/tests/test_waybar_crypto.py +++ b/tests/test_waybar_crypto.py @@ -276,10 +276,8 @@ def test_read_config_min_precision(): tmp.flush() tmp_config_path = tmp.file.name - try: + with pytest.raises(WaybarCryptoException): _ = read_config(tmp_config_path) - except Exception as e: - assert isinstance(e, WaybarCryptoException) def test_read_config_display_options_single(): @@ -345,10 +343,23 @@ def test_read_config_display_invalid(): tmp.flush() tmp_config_path = tmp.file.name - try: + with pytest.raises(WaybarCryptoException): + _ = read_config(tmp_config_path) + + +def test_read_config_no_api_key(): + 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", "api_key", "") + + with tempfile.NamedTemporaryFile(mode="w") as tmp: + cfp.write(tmp) + tmp.flush() + tmp_config_path = tmp.file.name + + with pytest.raises(NoApiKeyException): _ = read_config(tmp_config_path) - except Exception as e: - assert isinstance(e, WaybarCryptoException) class TestWaybarCrypto: @@ -393,10 +404,8 @@ def test_get_coinmarketcap_latest(self): @mock.patch.dict(os.environ, {API_KEY_ENV: ""}) def test_get_coinmarketcap_latest_invalid_key(self, waybar_crypto: WaybarCrypto): - try: + with pytest.raises(CoinmarketcapApiException): _ = waybar_crypto.coinmarketcap_latest() - except Exception as e: - assert isinstance(e, CoinmarketcapApiException) def test_waybar_output(self, waybar_crypto: WaybarCrypto, quotes_latest: ResponseQuotesLatest): output = waybar_crypto.waybar_output(quotes_latest) @@ -410,8 +419,6 @@ def test_waybar_output(self, waybar_crypto: WaybarCrypto, quotes_latest: Respons @mock.patch.dict(os.environ, {API_KEY_ENV: ""}) def test_no_api_key(self, config: Config): - try: + with pytest.raises(NoApiKeyException): config["general"]["api_key"] = "" _ = WaybarCrypto(config) - except Exception as e: - assert isinstance(e, NoApiKeyException)