From dc5a9ef497147a274a922ec4a8a1dd1d42b23fe9 Mon Sep 17 00:00:00 2001 From: OMEGARAZER <869111+OMEGARAZER@users.noreply.github.com> Date: Fri, 14 Oct 2022 18:15:49 -0400 Subject: [PATCH 1/4] link_to depreciation coverage Futureproof for link_to depreciation. https://bugs.python.org/issue39950 --- bdfr/downloader.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bdfr/downloader.py b/bdfr/downloader.py index 3b5a7e1..4f508fa 100644 --- a/bdfr/downloader.py +++ b/bdfr/downloader.py @@ -114,7 +114,10 @@ class RedditDownloader(RedditConnector): f'Resource hash {resource_hash} from submission {submission.id} downloaded elsewhere') return elif self.args.make_hard_links: - self.master_hash_list[resource_hash].link_to(destination) + try: + destination.hardlink_to(self.master_hash_list[resource_hash]) + except: + self.master_hash_list[resource_hash].link_to(destination) logger.info( f'Hard link made linking {destination} to {self.master_hash_list[resource_hash]}' f' in submission {submission.id}') From 3c7f85725eecff1cfc00458646311ec01c31b50a Mon Sep 17 00:00:00 2001 From: OMEGARAZER <869111+OMEGARAZER@users.noreply.github.com> Date: Tue, 8 Nov 2022 12:06:20 -0500 Subject: [PATCH 2/4] Narrow except Narrow except to AttributeError --- bdfr/downloader.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bdfr/downloader.py b/bdfr/downloader.py index 4f508fa..7709add 100644 --- a/bdfr/downloader.py +++ b/bdfr/downloader.py @@ -116,7 +116,7 @@ class RedditDownloader(RedditConnector): elif self.args.make_hard_links: try: destination.hardlink_to(self.master_hash_list[resource_hash]) - except: + except AttributeError: self.master_hash_list[resource_hash].link_to(destination) logger.info( f'Hard link made linking {destination} to {self.master_hash_list[resource_hash]}' From 77711c243a07a773bd2817c76dd3903a087b8035 Mon Sep 17 00:00:00 2001 From: OMEGARAZER <869111+OMEGARAZER@users.noreply.github.com> Date: Tue, 8 Nov 2022 13:54:18 -0500 Subject: [PATCH 3/4] Fix test for deleted user on post tested post now showing deleted as user causing tests to fail. Updated to working post. --- tests/test_file_name_formatter.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/tests/test_file_name_formatter.py b/tests/test_file_name_formatter.py index 21cb8a6..e7f1ebe 100644 --- a/tests/test_file_name_formatter.py +++ b/tests/test_file_name_formatter.py @@ -51,7 +51,7 @@ def do_test_path_equality(result: Path, expected: str) -> bool: @pytest.fixture(scope='session') def reddit_submission(reddit_instance: praw.Reddit) -> praw.models.Submission: - return reddit_instance.submission(id='lgilgt') + return reddit_instance.submission(id='w22m5l') @pytest.mark.parametrize(('test_format_string', 'expected'), ( @@ -86,12 +86,12 @@ def test_check_format_string_validity(test_string: str, expected: bool): @pytest.mark.online @pytest.mark.reddit @pytest.mark.parametrize(('test_format_string', 'expected'), ( - ('{SUBREDDIT}', 'Mindustry'), - ('{REDDITOR}', 'Gamer_player_boi'), - ('{POSTID}', 'lgilgt'), - ('{FLAIR}', 'Art'), - ('{SUBREDDIT}_{TITLE}', 'Mindustry_Toxopid that is NOT humane >:('), - ('{REDDITOR}_{TITLE}_{POSTID}', 'Gamer_player_boi_Toxopid that is NOT humane >:(_lgilgt') + ('{SUBREDDIT}', 'formula1'), + ('{REDDITOR}', 'Kirsty-Blue'), + ('{POSTID}', 'w22m5l'), + ('{FLAIR}', 'Social Media rall'), + ('{SUBREDDIT}_{TITLE}', 'formula1_George Russel acknowledges the Twitter trend about him'), + ('{REDDITOR}_{TITLE}_{POSTID}', 'Kirsty-Blue_George Russel acknowledges the Twitter trend about him_w22m5l') )) def test_format_name_real(test_format_string: str, expected: str, reddit_submission: praw.models.Submission): test_formatter = FileNameFormatter(test_format_string, '', '') @@ -105,17 +105,17 @@ def test_format_name_real(test_format_string: str, expected: str, reddit_submiss ( '{SUBREDDIT}', '{POSTID}', - 'test/Mindustry/lgilgt.png', + 'test/formula1/w22m5l.png', ), ( '{SUBREDDIT}', '{TITLE}_{POSTID}', - 'test/Mindustry/Toxopid that is NOT humane >:(_lgilgt.png', + 'test/formula1/George Russel acknowledges the Twitter trend about him_w22m5l.png', ), ( '{SUBREDDIT}', '{REDDITOR}_{TITLE}_{POSTID}', - 'test/Mindustry/Gamer_player_boi_Toxopid that is NOT humane >:(_lgilgt.png', + 'test/formula1/Kirsty-Blue_George Russel acknowledges the Twitter trend about him_w22m5l.png', ), )) def test_format_full( @@ -148,10 +148,10 @@ def test_format_full_conform( @pytest.mark.online @pytest.mark.reddit @pytest.mark.parametrize(('format_string_directory', 'format_string_file', 'index', 'expected'), ( - ('{SUBREDDIT}', '{POSTID}', None, 'test/Mindustry/lgilgt.png'), - ('{SUBREDDIT}', '{POSTID}', 1, 'test/Mindustry/lgilgt_1.png'), - ('{SUBREDDIT}', '{POSTID}', 2, 'test/Mindustry/lgilgt_2.png'), - ('{SUBREDDIT}', '{TITLE}_{POSTID}', 2, 'test/Mindustry/Toxopid that is NOT humane >:(_lgilgt_2.png'), + ('{SUBREDDIT}', '{POSTID}', None, 'test/formula1/w22m5l.png'), + ('{SUBREDDIT}', '{POSTID}', 1, 'test/formula1/w22m5l_1.png'), + ('{SUBREDDIT}', '{POSTID}', 2, 'test/formula1/w22m5l_2.png'), + ('{SUBREDDIT}', '{TITLE}_{POSTID}', 2, 'test/formula1/George Russel acknowledges the Twitter trend about him_w22m5l_2.png'), )) def test_format_full_with_index_suffix( format_string_directory: str, From f3c7d796aa764522567eb251d719555329b61a83 Mon Sep 17 00:00:00 2001 From: OMEGARAZER <869111+OMEGARAZER@users.noreply.github.com> Date: Tue, 8 Nov 2022 15:37:21 -0500 Subject: [PATCH 4/4] Update for other failing tests Seems there was some overlap in test names that was contributing to the test errors. Updated hash and test name. --- tests/site_downloaders/test_pornhub.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/site_downloaders/test_pornhub.py b/tests/site_downloaders/test_pornhub.py index cbe3662..e0933b0 100644 --- a/tests/site_downloaders/test_pornhub.py +++ b/tests/site_downloaders/test_pornhub.py @@ -13,10 +13,9 @@ from bdfr.site_downloaders.pornhub import PornHub @pytest.mark.online @pytest.mark.slow @pytest.mark.parametrize(('test_url', 'expected_hash'), ( - ('https://www.pornhub.com/view_video.php?viewkey=ph6074c59798497', 'd9b99e4ebecf2d8d67efe5e70d2acf8a'), - ('https://www.pornhub.com/view_video.php?viewkey=ph5ede121f0d3f8', ''), + ('https://www.pornhub.com/view_video.php?viewkey=ph6074c59798497', 'ad52a0f4fce8f99df0abed17de1d04c7'), )) -def test_find_resources_good(test_url: str, expected_hash: str): +def test_hash_resources_good(test_url: str, expected_hash: str): test_submission = MagicMock() test_submission.url = test_url downloader = PornHub(test_submission)