From acfa78606e6ae20b52685b5c6de4cdb01c803acf Mon Sep 17 00:00:00 2001 From: stevenhua0320 Date: Sat, 6 Jul 2024 01:09:39 +0800 Subject: [PATCH 1/8] Fix F841 F811 E402 E266 in test_helpers and test_dates.py --- tests/test_dates.py | 6 ++---- tests/test_helpers.py | 4 +--- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/tests/test_dates.py b/tests/test_dates.py index ad4a82544..ba5f553e7 100644 --- a/tests/test_dates.py +++ b/tests/test_dates.py @@ -16,6 +16,8 @@ is_before, is_after, is_between, + date_to_float, + month_to_int ) TEST_DATE = date(2019, 6, 15) @@ -36,10 +38,6 @@ def test_month_to_str(input, expected): assert month_to_str_int(input) == expected -import datetime -from regolith.dates import date_to_float, month_to_int - - @pytest.mark.parametrize( "input,expected", [ diff --git a/tests/test_helpers.py b/tests/test_helpers.py index ed963bfc7..55b00a78b 100644 --- a/tests/test_helpers.py +++ b/tests/test_helpers.py @@ -1334,8 +1334,7 @@ def test_helpers_bad(hmb, make_db): repo = Path(make_db) os.chdir(repo) with pytest.raises(hmb[2]) as excinfo: - actual = main(args=hmb[0]) - assert str(excinfo.value) == hmb[1] + assert str(excinfo.value) == hmb[1] @pytest.mark.parametrize("db_src", db_srcs) @@ -1388,7 +1387,6 @@ def test_helper_python(hm, make_db, db_src, make_mongodb, capsys, mocker): @pytest.mark.parametrize("hm", helper_map_loose) def test_helper_python_loose(hm, make_db, capsys): repo = Path(make_db) - testfile = Path(__file__) os.chdir(repo) main(args=hm[0]) From 1305ee5ef085d82dfe021257f6f514bc593dc6ab Mon Sep 17 00:00:00 2001 From: stevenhua0320 Date: Sat, 6 Jul 2024 01:29:02 +0800 Subject: [PATCH 2/8] Fix CI failing issue for test_helpers_bad and confirm flake8 issue has fixed for test_helpers.py --- tests/test_helpers.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/test_helpers.py b/tests/test_helpers.py index 55b00a78b..bb79dfd14 100644 --- a/tests/test_helpers.py +++ b/tests/test_helpers.py @@ -1334,7 +1334,8 @@ def test_helpers_bad(hmb, make_db): repo = Path(make_db) os.chdir(repo) with pytest.raises(hmb[2]) as excinfo: - assert str(excinfo.value) == hmb[1] + main(args=hmb[0]) + assert str(excinfo.value) == hmb[1] @pytest.mark.parametrize("db_src", db_srcs) @@ -1387,6 +1388,7 @@ def test_helper_python(hm, make_db, db_src, make_mongodb, capsys, mocker): @pytest.mark.parametrize("hm", helper_map_loose) def test_helper_python_loose(hm, make_db, capsys): repo = Path(make_db) + testfile = Path(__file__) os.chdir(repo) main(args=hm[0]) From 045847cfbbfe8dbf051d1fd1b7cb65995257a270 Mon Sep 17 00:00:00 2001 From: stevenhua0320 Date: Sat, 6 Jul 2024 01:31:14 +0800 Subject: [PATCH 3/8] Fix CI failing issue for test_helpers_bad and confirm flake8 issue has been fixed for test_helpers.py --- tests/test_helpers.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/tests/test_helpers.py b/tests/test_helpers.py index bb79dfd14..db82d53bc 100644 --- a/tests/test_helpers.py +++ b/tests/test_helpers.py @@ -1163,10 +1163,10 @@ # "--grants", "mrsec14", "dmref15", "--payee", "ashaaban", # "--where", "bank", "--begin-date", "2020-06-20", "--end-date", "2020-06-25"], # "2006as_timbuktoo has been added in expenses\n"), - ## The following Test Cases A-D test adding presentation-related expenses and map to user stories for Issue #910. All except one are commented out - ## because the current testing architecture (1) limits our ability to validate the addition of more than one entry to a collection, and - ## (2) only spins up one test database, but two would be needed to test a different destination database for expense data. The hope is - ## that, in the future when the test architecture is improved or changed, these commented-out tests can be useful and enable fully testing the added functionality. + # The following Test Cases A-D test adding presentation-related expenses and map to user stories for Issue #910. All except one are commented out + # because the current testing architecture (1) limits our ability to validate the addition of more than one entry to a collection, and + # (2) only spins up one test database, but two would be needed to test a different destination database for expense data. The hope is + # that, in the future when the test architecture is improved or changed, these commented-out tests can be useful and enable fully testing the added functionality. # Test Case A: Expect a new entry in outputs/presentations/presentations.yaml # (["helper", "a_presentation", "flat earth", "Mars", "2020-06-26", "2020-06-26", # "--type", "contributed_oral", "--person", "ashaaban", "--grants", "mrsec14", @@ -1334,7 +1334,7 @@ def test_helpers_bad(hmb, make_db): repo = Path(make_db) os.chdir(repo) with pytest.raises(hmb[2]) as excinfo: - main(args=hmb[0]) + main(args=hmb[0]) assert str(excinfo.value) == hmb[1] @@ -1388,7 +1388,6 @@ def test_helper_python(hm, make_db, db_src, make_mongodb, capsys, mocker): @pytest.mark.parametrize("hm", helper_map_loose) def test_helper_python_loose(hm, make_db, capsys): repo = Path(make_db) - testfile = Path(__file__) os.chdir(repo) main(args=hm[0]) From b09e39835376f1ca3e10375c6051a2b76ee33f6e Mon Sep 17 00:00:00 2001 From: stevenhua0320 Date: Sat, 6 Jul 2024 01:38:32 +0800 Subject: [PATCH 4/8] Fix F401 F811 E501 E722 issues in test_tools.py --- tests/test_tools.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/test_tools.py b/tests/test_tools.py index 433c6d6db..b4622feab 100644 --- a/tests/test_tools.py +++ b/tests/test_tools.py @@ -3,11 +3,6 @@ import habanero import pytest import datetime as dt -import uuid - -import copy -import requests -from unittest import mock import requests_mock from regolith.runcontrol import DEFAULT_RC @@ -208,7 +203,8 @@ def test_get_person_contact(input, expected): "ackno": "thanks", "grant": "fwp2", "month": "jun", - "note": "\\newline\\newline\\noindent Acknowledgement:\\newline\\noindent thanks\\newline\\newline\\noindent ", + "note": "\\newline\\newline\\noindent Acknowledgement:\\newline\\noindent thanks" + "\\newline\\newline\\noindent ", "year": "2020", }, { @@ -216,7 +212,8 @@ def test_get_person_contact(input, expected): "author": ["m1", "palin"], "ackno": "thanks", "grant": "fwp2", - "note": "\\newline\\newline\\noindent Acknowledgement:\\newline\\noindent thanks\\newline\\newline\\noindent ", + "note": "\\newline\\newline\\noindent Acknowledgement:\\newline\\noindent thanks" + "\\newline\\newline\\noindent ", "year": "2020", }, { @@ -225,7 +222,8 @@ def test_get_person_contact(input, expected): "author": ["m1", "cleese"], "grant": "fwp, dmref", "month": "apr", - "note": "\\newline\\newline\\noindent Acknowledgement:\\newline\\noindent thanks\\newline\\newline\\noindent ", + "note": "\\newline\\newline\\noindent Acknowledgement:\\newline\\noindent thanks" + "\\newline\\newline\\noindent ", "year": "2021", }, ], @@ -1751,7 +1749,7 @@ def test_is_fully_appointed(appts, start, end, expected): ), ], ) -def test_get_id_from_name(input, expected): +def test_get_id_from_grants_honors(input, expected): assert awards_grants_honors(input) == expected @@ -2570,7 +2568,7 @@ def test_group_member_employment_start_end(person, grpname, expected): try: actual = group_member_employment_start_end(person, grpname) assert actual == expected - except: + except RuntimeError: with pytest.raises(RuntimeError) as excinfo: actual = group_member_employment_start_end(person, grpname) assert str(excinfo.value) == expected @@ -2591,7 +2589,7 @@ def test_remove_duplicate_docs(inp, expected): try: actual = remove_duplicate_docs(inp, "dupe_key") assert actual == expected - except: + except RuntimeError: with pytest.raises(RuntimeError) as excinfo: actual = remove_duplicate_docs(inp, "dupe_key") assert str(excinfo.value) == expected @@ -3166,7 +3164,9 @@ def test_create_repo(**kwargs): actual = create_repo("talk_repo", "gitlab_private_token", rc) assert ( actual - == "repo 2206_my_talk has been created at https://example.com.\nClone this to your local using (HTTPS):\ngit clone https://example.com:/2206_my_talk.git\nor (SSH):\ngit clone git@example.com:/2206_my_talk.git" + == "repo 2206_my_talk has been created at https://example.com.\nClone this to your local using " + "(HTTPS):\ngit clone https://example.com:/2206_my_talk.git\nor " + "(SSH):\ngit clone git@example.com:/2206_my_talk.git" ) From eb8e3eb45f1556470269dcd4dd802867a711c55a Mon Sep 17 00:00:00 2001 From: stevenhua0320 Date: Sat, 6 Jul 2024 01:50:36 +0800 Subject: [PATCH 5/8] Fix CI bug for test_get_id_from_name. But there is another test function that has the same name as this function. Not sure how to change it since as long as change the name of test it gives the error. --- tests/test_tools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_tools.py b/tests/test_tools.py index b4622feab..859be3d45 100644 --- a/tests/test_tools.py +++ b/tests/test_tools.py @@ -1749,7 +1749,7 @@ def test_is_fully_appointed(appts, start, end, expected): ), ], ) -def test_get_id_from_grants_honors(input, expected): +def test_get_id_from_name(input, expected): assert awards_grants_honors(input) == expected From 2d3183d62a4836a5cef37bc0a6bd5e352615ff53 Mon Sep 17 00:00:00 2001 From: stevenhua0320 Date: Sat, 6 Jul 2024 02:06:39 +0800 Subject: [PATCH 6/8] Fix CI error in test_tools while leaving F401 F811 issues since the import modules are necessary and test_name cannot be modified at this time. --- tests/test_tools.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_tools.py b/tests/test_tools.py index 859be3d45..337561fba 100644 --- a/tests/test_tools.py +++ b/tests/test_tools.py @@ -1,10 +1,10 @@ from copy import copy - import habanero import pytest import datetime as dt import requests_mock - +from unittest import mock +import copy from regolith.runcontrol import DEFAULT_RC from regolith.tools import ( From a95b44e2d45f086539e293b6191aad57e6a86ac6 Mon Sep 17 00:00:00 2001 From: stevenhua0320 Date: Sat, 6 Jul 2024 02:25:54 +0800 Subject: [PATCH 7/8] Fix all errors in test_tools and flake8 test for F811 a d F401 fixed. --- tests/test_tools.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/test_tools.py b/tests/test_tools.py index 337561fba..6d90713d0 100644 --- a/tests/test_tools.py +++ b/tests/test_tools.py @@ -2,9 +2,9 @@ import habanero import pytest import datetime as dt -import requests_mock -from unittest import mock import copy +import requests_mock + from regolith.runcontrol import DEFAULT_RC from regolith.tools import ( @@ -3141,8 +3141,9 @@ def test_get_target_token(tokens, expected): actual = get_target_token("gitlab_private_token", tokens) assert actual == expected - # @mock.patch("requests.post") + + @requests_mock.Mocker(kw="mock") def test_create_repo(**kwargs): kwargs["mock"].post("https://example.com/url/example", status_code=201) From 86257eaca7894a9e969f19ba38dcb0925d415c94 Mon Sep 17 00:00:00 2001 From: stevenhua0320 Date: Sat, 6 Jul 2024 02:27:45 +0800 Subject: [PATCH 8/8] Leave one F811 unfixed as change test name would create error. --- tests/test_tools.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_tools.py b/tests/test_tools.py index 6d90713d0..c85fa466d 100644 --- a/tests/test_tools.py +++ b/tests/test_tools.py @@ -1,4 +1,3 @@ -from copy import copy import habanero import pytest import datetime as dt