From 8d237039620ef8afb68dff98f8693fbad91024a5 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 2 Aug 2024 21:51:42 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/unit/test_contributors_module.py | 64 +++++++++++++++++++------- 1 file changed, 48 insertions(+), 16 deletions(-) diff --git a/tests/unit/test_contributors_module.py b/tests/unit/test_contributors_module.py index 0d93df2..cb7d9d5 100644 --- a/tests/unit/test_contributors_module.py +++ b/tests/unit/test_contributors_module.py @@ -1,46 +1,74 @@ -import pytest from unittest.mock import Mock, patch + +import pytest from pyosmeta.contributors import ProcessContributors from pyosmeta.github_api import GitHubAPI + @pytest.fixture def github_api_mock(): return Mock(spec=GitHubAPI) + @pytest.fixture def json_files(): return ["https://example.com/file1.json", "https://example.com/file2.json"] + @pytest.fixture def process_contributors(github_api_mock, json_files): return ProcessContributors(github_api_mock, json_files) + def test_check_contrib_type(process_contributors): - assert process_contributors.check_contrib_type("software-peer-review") == "peer-review-guide" - assert process_contributors.check_contrib_type("python-package-guide") == "package-guide" - assert process_contributors.check_contrib_type("pyopensci.github.io") == "web-contrib" - assert process_contributors.check_contrib_type("update-web-metadata") == "code-contrib" + assert ( + process_contributors.check_contrib_type("software-peer-review") + == "peer-review-guide" + ) + assert ( + process_contributors.check_contrib_type("python-package-guide") + == "package-guide" + ) + assert ( + process_contributors.check_contrib_type("pyopensci.github.io") + == "web-contrib" + ) + assert ( + process_contributors.check_contrib_type("update-web-metadata") + == "code-contrib" + ) assert process_contributors.check_contrib_type("other") == "community" + @patch("requests.get") def test_load_json(mock_get, process_contributors): mock_get.return_value.text = '{"key": "value"}' result = process_contributors.load_json("https://example.com/test.json") assert result == {"key": "value"} -@patch.object(ProcessContributors, 'load_json') + +@patch.object(ProcessContributors, "load_json") def test_process_json_file(mock_load_json, process_contributors): - mock_load_json.return_value = {"contributors": [{"login": "user1"}, {"login": "user2"}]} - contrib_type, users = process_contributors.process_json_file("https://example.com/file1.json") + mock_load_json.return_value = { + "contributors": [{"login": "user1"}, {"login": "user2"}] + } + contrib_type, users = process_contributors.process_json_file( + "https://example.com/file1.json" + ) assert contrib_type == "community" assert users == ["user1", "user2"] -@patch.object(ProcessContributors, 'process_json_file') + +@patch.object(ProcessContributors, "process_json_file") def test_combine_json_data(mock_process_json_file, process_contributors): - mock_process_json_file.side_effect = [("type1", ["user1"]), ("type2", ["user2"])] + mock_process_json_file.side_effect = [ + ("type1", ["user1"]), + ("type2", ["user2"]), + ] combined_data = process_contributors.combine_json_data() assert combined_data == {"type1": ["user1"], "type2": ["user2"]} + def test_return_user_info(process_contributors, github_api_mock): github_api_mock.get_user_info.return_value = { "name": "Test User", @@ -51,7 +79,7 @@ def test_return_user_info(process_contributors, github_api_mock): "company": "Test Company", "blog": "https://test.com", "id": 12345, - "login": "testuser" + "login": "testuser", } user_info = process_contributors.return_user_info("testuser") assert user_info == { @@ -64,27 +92,31 @@ def test_return_user_info(process_contributors, github_api_mock): "organization": "Test Company", "website": "https://test.com", "github_image_id": 12345, - "github_username": "testuser" + "github_username": "testuser", } + def test_update_contrib_type(process_contributors): web_contrib_types = ["type1", "type2"] repo_contrib_types = ["type2", "type3"] - updated_types = process_contributors._update_contrib_type(web_contrib_types, repo_contrib_types) + updated_types = process_contributors._update_contrib_type( + web_contrib_types, repo_contrib_types + ) assert updated_types == ["type1", "type2", "type3"] + def test_combine_users(process_contributors): repo_dict = { "user1": {"contributor_type": ["type1"]}, - "user2": {"contributor_type": ["type2"]} + "user2": {"contributor_type": ["type2"]}, } web_dict = { "user1": {"contributor_type": ["type1"]}, - "user3": {"contributor_type": ["type3"]} + "user3": {"contributor_type": ["type3"]}, } combined_users = process_contributors.combine_users(repo_dict, web_dict) assert combined_users == { "user1": {"contributor_type": ["type1"]}, "user3": {"contributor_type": ["type3"]}, - "user2": {"contributor_type": ["type2"]} + "user2": {"contributor_type": ["type2"]}, }