From ef7fcce1cc27fc6a85279e576d7f4d32aa66b1c7 Mon Sep 17 00:00:00 2001 From: OMEGARAZER <869111+OMEGARAZER@users.noreply.github.com> Date: Wed, 30 Nov 2022 18:05:10 -0500 Subject: [PATCH] lint tests Lint with [refurb](https://github.com/dosisod/refurb) using `--disable 126 --python-version 3.9` Also update bats to 1.8.2 and bats-assets to 2.1.0. No changes to the tests, all still passing. --- pytest.ini | 2 +- scripts/tests/bats | 2 +- scripts/tests/test_helper/bats-assert | 2 +- tests/test_connector.py | 6 +++--- tests/test_downloader.py | 2 +- tests/test_oauth2.py | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pytest.ini b/pytest.ini index 5123ee6..09df53c 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,7 +1,7 @@ [pytest] +addopts = --strict-markers markers = online: tests require a connection to the internet reddit: tests require a connection to Reddit slow: test is slow to run authenticated: test requires an authenticated Reddit instance - diff --git a/scripts/tests/bats b/scripts/tests/bats index ce5ca28..e8c840b 160000 --- a/scripts/tests/bats +++ b/scripts/tests/bats @@ -1 +1 @@ -Subproject commit ce5ca2802fabe5dc38393240cd40e20f8928d3b0 +Subproject commit e8c840b58f0833e23461c682655fe540aa923f85 diff --git a/scripts/tests/test_helper/bats-assert b/scripts/tests/test_helper/bats-assert index e0de84e..78fa631 160000 --- a/scripts/tests/test_helper/bats-assert +++ b/scripts/tests/test_helper/bats-assert @@ -1 +1 @@ -Subproject commit e0de84e9c011223e7f88b7ccf1c929f4327097ba +Subproject commit 78fa631d1370562d2cd4a1390989e706158e7bf0 diff --git a/tests/test_connector.py b/tests/test_connector.py index 2cddcdf..4c9e52d 100644 --- a/tests/test_connector.py +++ b/tests/test_connector.py @@ -47,7 +47,7 @@ def assert_all_results_are_submissions(result_limit: int, results: list[Iterator def assert_all_results_are_submissions_or_comments(result_limit: int, results: list[Iterator]) -> list: results = [sub for res in results for sub in res] - assert all([isinstance(res, praw.models.Submission) or isinstance(res, praw.models.Comment) for res in results]) + assert all([isinstance(res, (praw.models.Submission, praw.models.Comment)) for res in results]) assert not any([isinstance(m, MagicMock) for m in results]) if result_limit is not None: assert len(results) == result_limit @@ -259,7 +259,7 @@ def test_get_subreddit_search( assert all([res.subreddit.display_name in test_subreddits for res in results]) assert len(results) <= max_expected_len if max_expected_len != 0: - assert len(results) > 0 + assert results assert not any([isinstance(m, MagicMock) for m in results]) @@ -356,7 +356,7 @@ def test_get_subscribed_subreddits(downloader_mock: MagicMock, authenticated_red downloader_mock.sort_filter = RedditTypes.SortType.HOT results = RedditConnector.get_subreddits(downloader_mock) assert all([isinstance(s, praw.models.ListingGenerator) for s in results]) - assert len(results) > 0 + assert results @pytest.mark.parametrize(('test_name', 'expected'), ( diff --git a/tests/test_downloader.py b/tests/test_downloader.py index e2e9e82..e92d870 100644 --- a/tests/test_downloader.py +++ b/tests/test_downloader.py @@ -152,7 +152,7 @@ def test_download_submission_hash_exists( RedditDownloader._download_submission(downloader_mock, submission) folder_contents = list(tmp_path.iterdir()) output = capsys.readouterr() - assert len(folder_contents) == 0 + assert not folder_contents assert re.search(r'Resource hash .*? downloaded elsewhere', output.out) diff --git a/tests/test_oauth2.py b/tests/test_oauth2.py index 6c25d35..71bdca1 100644 --- a/tests/test_oauth2.py +++ b/tests/test_oauth2.py @@ -66,6 +66,6 @@ def test_token_manager_write(example_config: configparser.ConfigParser, tmp_path test_manager = OAuth2TokenManager(example_config, test_path) test_manager.post_refresh_callback(mock_authoriser) assert example_config.get('DEFAULT', 'user_token') == 'changed_token' - with open(test_path, 'r') as file: + with test_path.open('r') as file: file_contents = file.read() assert 'user_token = changed_token' in file_contents