From c6b9087f5177491dfbd52a36a4c01702de42d381 Mon Sep 17 00:00:00 2001 From: Zdenek Styblik Date: Sun, 30 Jun 2024 22:24:12 +0200 Subject: [PATCH] fixup some cleanup --- gh2slack.py | 5 +++-- phpbb2slack.py | 9 +++++---- tests/test_gh2slack.py | 5 +++-- tests/test_phpbb2slack.py | 9 +++++---- tests/test_rss2irc.py | 14 +++++++------- tests/test_rss2slack.py | 5 +++-- 6 files changed, 26 insertions(+), 21 deletions(-) diff --git a/gh2slack.py b/gh2slack.py index aa74bae..3a9989c 100755 --- a/gh2slack.py +++ b/gh2slack.py @@ -18,6 +18,7 @@ import rss2irc # noqa: I202 import rss2slack +from lib import CachedData from lib import config_options ALIASES = { @@ -304,7 +305,7 @@ def parse_args() -> argparse.Namespace: def process_page_items( logger: logging.Logger, - cache: rss2irc.CachedData, + cache: CachedData, pages: List, expiration: int, repository_url: str, @@ -348,7 +349,7 @@ def process_page_items( return to_publish -def scrub_items(logger: logging.Logger, cache: rss2irc.CachedData) -> None: +def scrub_items(logger: logging.Logger, cache: CachedData) -> None: """Scrub cache and remove expired items.""" time_now = int(time.time()) for key in list(cache.items.keys()): diff --git a/phpbb2slack.py b/phpbb2slack.py index 9452e20..00c502f 100755 --- a/phpbb2slack.py +++ b/phpbb2slack.py @@ -14,7 +14,8 @@ import feedparser import rss2irc # noqa: I202 -import rss2slack +import rss2slack # noqa: I202 +from lib import CachedData # noqa: I202 CACHE_EXPIRATION = 86400 # seconds HTTP_TIMEOUT = 30 # seconds @@ -274,7 +275,7 @@ def parse_news(data: str, authors: List[str]) -> Dict: def prune_news( logger: logging.Logger, - cache: rss2irc.CachedData, + cache: CachedData, news: Dict[str, Dict], expiration: int = CACHE_EXPIRATION, ) -> None: @@ -292,7 +293,7 @@ def prune_news( news.pop(key) -def scrub_items(logger: logging.Logger, cache: rss2irc.CachedData) -> None: +def scrub_items(logger: logging.Logger, cache: CachedData) -> None: """Scrub cache and remove expired items.""" time_now = int(time.time()) for key in list(cache.items.keys()): @@ -312,7 +313,7 @@ def scrub_items(logger: logging.Logger, cache: rss2irc.CachedData) -> None: def update_items_expiration( - cache: rss2irc.CachedData, news: Dict, expiration: int + cache: CachedData, news: Dict, expiration: int ) -> None: """Update cache contents.""" item_expiration = int(time.time()) + expiration diff --git a/tests/test_gh2slack.py b/tests/test_gh2slack.py index ce27125..815f531 100644 --- a/tests/test_gh2slack.py +++ b/tests/test_gh2slack.py @@ -14,6 +14,7 @@ import gh2slack # noqa:I100,I202 import rss2irc # noqa:I100,I202 +from lib import CachedData # noqa:I100,I202 SCRIPT_PATH = os.path.dirname(os.path.realpath(__file__)) @@ -351,7 +352,7 @@ def test_process_page_items(): ], ] repository_url = "http://example.com" - cache = rss2irc.CachedData( + cache = CachedData( items={ "http://example.com/bar": { "expiration": 0, @@ -391,7 +392,7 @@ def test_process_page_items(): def test_scrub_items(): """Test scrub_items().""" item_expiration = int(time.time()) + 60 - test_cache = rss2irc.CachedData( + test_cache = CachedData( items={ "foo": { "expiration": item_expiration, diff --git a/tests/test_phpbb2slack.py b/tests/test_phpbb2slack.py index 5084322..f46222f 100644 --- a/tests/test_phpbb2slack.py +++ b/tests/test_phpbb2slack.py @@ -12,6 +12,7 @@ import phpbb2slack # noqa:I100,I202 import rss2irc +from lib import CachedData from lib import config_options ITEM_EXPIRATION = int(time.time()) @@ -157,7 +158,7 @@ def test_main_ideal( ) fixture_http_server.capture_requests = True - cache = rss2irc.CachedData() + cache = CachedData() source1 = cache.get_source_by_url(rss_url) source1.http_etag = "" source1.http_last_modified = "" @@ -264,7 +265,7 @@ def test_main_cache_hit( ) fixture_http_server.capture_requests = True - cache = rss2irc.CachedData() + cache = CachedData() source1 = cache.get_source_by_url(rss_url) source1.http_etag = "pytest_etag" source1.http_last_modified = "pytest_lm" @@ -361,7 +362,7 @@ def test_parse_news(): "cache,expected_cache", [ ( - rss2irc.CachedData( + CachedData( items={ "foo": { "expiration": get_item_expiration() + 60, @@ -402,7 +403,7 @@ def test_scrub_items(cache, expected_cache): "comments_cnt": 20, }, }, - rss2irc.CachedData( + CachedData( items={ "http://example.com": { "expiration": 0, diff --git a/tests/test_rss2irc.py b/tests/test_rss2irc.py index 85f862d..0103f99 100644 --- a/tests/test_rss2irc.py +++ b/tests/test_rss2irc.py @@ -10,9 +10,9 @@ import pytest import rss2irc # noqa:I202 -from lib import CachedData -from lib import config_options -from lib import HTTPSource +from lib import CachedData # noqa:I202 +from lib import config_options # noqa:I202 +from lib import HTTPSource # noqa:I202 SCRIPT_PATH = os.path.dirname(os.path.realpath(__file__)) @@ -182,7 +182,7 @@ def test_main_ideal( {"ETag": "pytest_etag", "Last-Modified": "pytest_lm"}, ) - cache = rss2irc.CachedData() + cache = CachedData() source1 = cache.get_source_by_url(rss_url) source1.http_etag = "" source1.http_last_modified = "" @@ -284,7 +284,7 @@ def test_main_cache_operations( {"ETag": "pytest_etag", "Last-Modified": "pytest_lm"}, ) - cache = rss2irc.CachedData() + cache = CachedData() cache.items[cache_key] = frozen_ts + 60 cache.items["https://expired.example.com"] = 123456 source1 = cache.get_source_by_url(rss_url) @@ -379,7 +379,7 @@ def test_main_cache_hit( }, ) - cache = rss2irc.CachedData() + cache = CachedData() source1 = cache.get_source_by_url(rss_url) source1.http_etag = "pytest_etag" source1.http_last_modified = "pytest_last_modified" @@ -472,7 +472,7 @@ def test_scrub_items(): logger.disabled = True item_expiration = int(time.time()) + 60 - test_cache = rss2irc.CachedData( + test_cache = CachedData( items={ "foo": item_expiration, "bar": int(time.time()) - 3600, diff --git a/tests/test_rss2slack.py b/tests/test_rss2slack.py index 300f235..be91108 100644 --- a/tests/test_rss2slack.py +++ b/tests/test_rss2slack.py @@ -12,6 +12,7 @@ import rss2irc # noqa:I100,I202 import rss2slack # noqa:I100,I202 +from lib import CachedData from lib import config_options SCRIPT_PATH = os.path.dirname(os.path.realpath(__file__)) @@ -151,7 +152,7 @@ def test_main_ideal( ) fixture_http_server.capture_requests = True - cache = rss2irc.CachedData() + cache = CachedData() source1 = cache.get_source_by_url(rss_url) source1.http_etag = "" source1.http_last_modified = "" @@ -263,7 +264,7 @@ def test_main_cache_hit( ) fixture_http_server.capture_requests = True - cache = rss2irc.CachedData() + cache = CachedData() source1 = cache.get_source_by_url(rss_url) source1.http_etag = "pytest_etag" source1.http_last_modified = "pytest_lm"