From 638cec15d921bcde8e1d44c2656e2cfcf2e871ba Mon Sep 17 00:00:00 2001 From: Chris Caron Date: Sat, 23 Aug 2025 13:02:19 -0400 Subject: [PATCH] fixed issue with windows/mac test cases --- apprise/config/base.py | 9 ++++++--- tests/test_config_base.py | 41 +++++++++++++++++++++++++++++++++++++- tests/test_plugin_email.py | 4 +++- 3 files changed, 49 insertions(+), 5 deletions(-) diff --git a/apprise/config/base.py b/apprise/config/base.py index a57ceef0..3f1980df 100644 --- a/apprise/config/base.py +++ b/apprise/config/base.py @@ -899,9 +899,8 @@ class ConfigBase(URLBase): tokens = result.get("asset", None) if tokens and isinstance(tokens, dict): raw_tz = tokens.get("timezone", tokens.get("tz")) - timezone = raw_tz.strip() if isinstance(raw_tz, str) else "" - if timezone: - default_timezone = zoneinfo(re.sub(r"[^\w/-]+", "", timezone)) + if isinstance(raw_tz, str): + default_timezone = zoneinfo(re.sub(r"[^\w/-]+", "", raw_tz)) if not default_timezone: ConfigBase.logger.warning( 'Ignored invalid timezone "%s"', raw_tz) @@ -909,6 +908,10 @@ class ConfigBase(URLBase): else: asset._tzinfo = default_timezone + elif raw_tz is not None: + ConfigBase.logger.warning( + 'Ignored invalid timezone "%r"', raw_tz) + # Iterate over remaining tokens for k, v in tokens.items(): if k.startswith("_") or k.endswith("_"): diff --git a/tests/test_config_base.py b/tests/test_config_base.py index 061d234e..f6420ce5 100644 --- a/tests/test_config_base.py +++ b/tests/test_config_base.py @@ -1625,7 +1625,9 @@ urls: asset = plugin.asset # tz was accepted and normalised - assert getattr(asset.tzinfo, "key", None) == "America/Toronto" + # lower() is required since Mac and Window are not case sensitive and will + # See output as it was passed in and not corrected per IANA + assert getattr(asset.tzinfo, "key", None).lower() == "america/toronto" # boolean coercion applied assert asset.secure_logging is True # None -> "" @@ -1666,3 +1668,40 @@ urls: # Compare offsets at a fixed instant instead of object identity dt = datetime(2024, 1, 1, 12, 0, tzinfo=_tz.utc) assert tzinfo.utcoffset(dt) is not None + + +@pytest.mark.parametrize("garbage_yaml", [ + "123", "3.1415", "true", "[UTC]", "{x: UTC}", +]) +def test_yaml_asset_tz_garbage_types_only(tmpdir, garbage_yaml): + """ + If only 'tz' is present and it is non-string, it is ignored. + We assert it didn't become a real IANA zone (e.g., Europe/London), + and that the tzinfo is usable. + """ + cfg = tmpdir.join("asset-tz-garbage-only.yml") + cfg.write( + f""" +version: 1 +asset: + tz: {garbage_yaml} # non-string -> warning path +urls: + - json://localhost +""" + ) + + base_asset = AppriseAsset(timezone="UTC") + ac = AppriseConfig(paths=str(cfg)) + servers = ac.servers(asset=base_asset) + assert len(servers) == 1 + + tzinfo = servers[0].asset.tzinfo + + # 1) Did not “accidentally” become a valid IANA from elsewhere. + assert getattr(tzinfo, "key", "").lower() != "europe/london" + + # 2) tzinfo is usable (offset resolves at a fixed instant). + dt = datetime(2024, 1, 1, 12, 0, tzinfo=_tz.utc) + assert tzinfo.utcoffset(dt) is not None + # also stable tzname resolution + assert isinstance(tzinfo.tzname(dt), str) diff --git a/tests/test_plugin_email.py b/tests/test_plugin_email.py index 018f0b1d..f1f9dab8 100644 --- a/tests/test_plugin_email.py +++ b/tests/test_plugin_email.py @@ -886,7 +886,9 @@ def test_plugin_email_timezone(mock_smtp): # as above obj = email.NotifyEmail(**results, asset=asset) # Defaults to our system - assert obj.tzinfo.key == "America/Vancouver" + # lower() is required since Mac and Window are not case sensitive and will + # See output as it was passed in and not corrected per IANA + assert obj.tzinfo.key.lower() == "america/vancouver" assert "tz=" not in obj.url() # Having ourselves a default variable also does not prevent