From 71c0b61a620b4ee6ba34179209c2a85fa0509b13 Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Sat, 26 Sep 2020 13:42:40 +1000 Subject: [PATCH 1/3] include tests in pypi package This commit adds the tests directory when packaging up for pypi. This is in response to a request from @pacoesteban (GitHub user) who is the maintainer for the OpenBSD port of ephemetoot. --- README.md | 2 ++ pyproject.toml | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a1078cd..9b3f1eb 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,8 @@ You can use `ephemetoot` to delete [Mastodon](https://github.com/tootsuite/masto * they are individually listed to be kept ## Contributing +ephemetoot is packaged using `poetry` and tested using `pytest`. + For all bugs, suggestions, pull requests or other contributions, please check the [contributing guide](./docs/contributing.md). ## License diff --git a/pyproject.toml b/pyproject.toml index d7971f6..9b0f324 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "ephemetoot" -version = "3.1.0" +version = "3.1.1-alpha.1" description = "A command line tool to delete your old toots" authors = ["Hugh Rundle "] license = "GPL-3.0-or-later" @@ -15,6 +15,7 @@ classifiers = [ ] include = [ "LICENSE", + "tests" ] [tool.poetry.dependencies] From 039a142c24192935fa92d76c7dacff7502fa5b18 Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Fri, 12 Feb 2021 21:11:25 +1100 Subject: [PATCH 2/3] Add default values to functions Aimed to be a fix for #66 (concat incompatible type errors under certain conditions) --- ephemetoot/ephemetoot.py | 8 ++++---- tests/test_ephemetoot.py | 24 +++++++++++------------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/ephemetoot/ephemetoot.py b/ephemetoot/ephemetoot.py index 1426182..1395dd5 100644 --- a/ephemetoot/ephemetoot.py +++ b/ephemetoot/ephemetoot.py @@ -380,9 +380,9 @@ def print_rate_limit_message(mastodon): ) -def retry_on_error(options, mastodon, toot, attempts): +def retry_on_error(options, mastodon, toot, attempts=0): - if attempts < 6: + if attempts < 6: try: console_print( "Attempt " + str(attempts) + " at " + datestamp_now(), options, False @@ -396,7 +396,7 @@ def retry_on_error(options, mastodon, toot, attempts): raise TimeoutError("Gave up after 5 attempts") -def process_toot(config, options, mastodon, deleted_count, toot): +def process_toot(config, options, mastodon, toot, deleted_count=0): keep_pinned = "keep_pinned" in config and config["keep_pinned"] toots_to_keep = config["toots_to_keep"] if "toots_to_keep" in config else [] @@ -531,7 +531,7 @@ def check_batch(config, options, mastodon, user_id, timeline, deleted_count=0): try: for toot in timeline: # process_toot returns the value of the deleted_count so we can keep track here - deleted_count = process_toot(config, options, mastodon, deleted_count, toot) + deleted_count = process_toot(config, options, mastodon, toot, deleted_count) # the account_statuses call is paginated with a 40-toot limit # get the id of the last toot to include as 'max_id' in the next API call. diff --git a/tests/test_ephemetoot.py b/tests/test_ephemetoot.py index 86070a6..f817b18 100644 --- a/tests/test_ephemetoot.py +++ b/tests/test_ephemetoot.py @@ -233,7 +233,7 @@ def test_check_batch(capfd, monkeypatch): # this simulates what would happen if the toot was being deleted monkeypatch.setattr( "ephemetoot.ephemetoot.process_toot", - lambda config, options, mastodon, deleted_count, toot: deleted_count + 1, + lambda config, options, mastodon, toot, deleted_count: deleted_count + 1, ) # run check_batch ephemetoot.check_batch(config, options, mastodon, user_id, timeline, 0) @@ -249,7 +249,7 @@ def test_check_batch_quiet(capfd, monkeypatch): timeline = mastodon.account_statuses(user_id=user_id, limit=2, max_id=0) monkeypatch.setattr( "ephemetoot.ephemetoot.process_toot", - lambda config, options, mastodon, deleted_count, toot: deleted_count + 1, + lambda config, options, mastodon, toot, deleted_count: deleted_count + 1, ) ephemetoot.check_batch(config, options, mastodon, user_id, timeline, 0) # deleted_count should be 10 @@ -265,7 +265,7 @@ def test_check_batch_quiet_no_toots(capfd, monkeypatch): timeline = mastodon.account_statuses(user_id=user_id, limit=2, max_id=10) monkeypatch.setattr( "ephemetoot.ephemetoot.process_toot", - lambda config, options, mastodon, deleted_count, toot: deleted_count + 1, + lambda config, options, mastodon, toot, deleted_count: deleted_count + 1, ) # run check_batch ephemetoot.check_batch(config, options, mastodon, user_id, timeline, 0) @@ -281,7 +281,7 @@ def test_check_batch_qq(capfd, monkeypatch): timeline = mastodon.account_statuses(user_id=user_id, limit=2, max_id=0) monkeypatch.setattr( "ephemetoot.ephemetoot.process_toot", - lambda config, options, mastodon, deleted_count, toot: deleted_count + 1, + lambda config, options, mastodon, toot, deleted_count: deleted_count + 1, ) ephemetoot.check_batch(config, options, mastodon, user_id, timeline, 0) # deleted_count should be 10 and message printed since there was a delete @@ -297,7 +297,7 @@ def test_check_batch_qq_no_deletes(capfd, monkeypatch): # simulate no deletes occuring monkeypatch.setattr( "ephemetoot.ephemetoot.process_toot", - lambda config, options, mastodon, deleted_count, toot: 0, + lambda config, options, mastodon, toot, deleted_count: 0, ) # run check_batch ephemetoot.check_batch(config, options, mastodon, user_id, timeline, 0) @@ -313,7 +313,7 @@ def test_check_batch_qqq(capfd, monkeypatch): timeline = mastodon.account_statuses(user_id=user_id, limit=2, max_id=0) monkeypatch.setattr( "ephemetoot.ephemetoot.process_toot", - lambda config, options, mastodon, deleted_count, toot: deleted_count + 1, + lambda config, options, mastodon, toot, deleted_count: deleted_count + 1, ) # run check_batch ephemetoot.check_batch(config, options, mastodon, user_id, timeline, 0) @@ -377,7 +377,6 @@ def test_init_archive_path(tmpdir): os.path.join(good_path, "/bad/path/"), "Archive path", None ) ok = ephemetoot.sanitise_input(good_path, "Archive path", None) - also_ok = ephemetoot.sanitise_input("~/Desktop", "Archive path", None) assert ok == "ok" assert wrong == "That directory does not exist, please try again" @@ -423,7 +422,6 @@ def test_init_sanitise_tag_list(): def test_init_sanitise_url(): tags = ("\033[96m", "\033[2m", "\033[0m") wrong = ephemetoot.sanitise_input("http://example.social", "Base URL", tags) - also_wrong = ephemetoot.sanitise_input("http://example.social", "Base URL", tags) ok = ephemetoot.sanitise_input("example.social", "Base URL", tags) assert ( @@ -476,7 +474,7 @@ def test_process_toot(capfd, tmpdir, monkeypatch): toot_dict["visibility"] = "public" toot_dict["reblog"] = False toot = dict2obj(toot_dict) - ephemetoot.process_toot(config_file, options, mastodon, 0, toot) + ephemetoot.process_toot(config_file, options, mastodon, toot, 0) assert ( capfd.readouterr().out == "❌ deleting toot 104136090490756999 tooted 09 May 2020\n" @@ -492,7 +490,7 @@ def test_process_toot_pinned(capfd, tmpdir): mastodon = Mocktodon() toot_dict["pinned"] = True toot = dict2obj(toot_dict) - ephemetoot.process_toot(config_file, options, mastodon, 0, toot) + ephemetoot.process_toot(config_file, options, mastodon, toot, 0) assert capfd.readouterr().out == "📌 skipping pinned toot - 104136090490756999\n" @@ -506,7 +504,7 @@ def test_process_toot_saved(capfd, tmpdir): mastodon = Mocktodon() toot_dict["pinned"] = False toot = dict2obj(toot_dict) - ephemetoot.process_toot(config_file, options, mastodon, 0, toot) + ephemetoot.process_toot(config_file, options, mastodon, toot, 0) assert capfd.readouterr().out == "💾 skipping saved toot - 104136090490756999\n" @@ -522,7 +520,7 @@ def test_process_toot_visibility(capfd, tmpdir): toot_dict["pinned"] = False # is true above so make false toot_dict["visibility"] = "testing" toot = dict2obj(toot_dict) - ephemetoot.process_toot(config_file, options, mastodon, 0, toot) + ephemetoot.process_toot(config_file, options, mastodon, toot, 0) assert capfd.readouterr().out == "👀 skipping testing toot - 104136090490756999\n" @@ -540,7 +538,7 @@ def test_process_toot_hashtag(capfd, tmpdir, monkeypatch): toot_dict["reblog"] = True toot = dict2obj(toot_dict) - ephemetoot.process_toot(config_file, options, mastodon, 0, toot) + ephemetoot.process_toot(config_file, options, mastodon, toot, 0) assert ( capfd.readouterr().out == "👎 unboosting toot 104136090490756999 boosted 09 May 2020\n" From 3816e2ed7231ddf5906139536555d70259dbe562 Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Fri, 12 Feb 2021 21:16:12 +1100 Subject: [PATCH 3/3] bump version to 3.1.1 alpha1 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 9b0f324..dbd8ec0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "ephemetoot" -version = "3.1.1-alpha.1" +version = "3.1.1a1" description = "A command line tool to delete your old toots" authors = ["Hugh Rundle "] license = "GPL-3.0-or-later"