Skip to content

Commit

Permalink
Merge pull request #1092 from stevenhua0320/lint-check-14
Browse files Browse the repository at this point in the history
Fix F841 F811 E402 E266 E722 in test_helpers, test_tools, and test_dates.py
  • Loading branch information
sbillinge authored Jul 6, 2024
2 parents 9d8c5f3 + 86257ea commit 4947b58
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 23 deletions.
6 changes: 2 additions & 4 deletions tests/test_dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
is_before,
is_after,
is_between,
date_to_float,
month_to_int
)

TEST_DATE = date(2019, 6, 15)
Expand All @@ -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",
[
Expand Down
11 changes: 5 additions & 6 deletions tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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:
actual = main(args=hmb[0])
main(args=hmb[0])
assert str(excinfo.value) == hmb[1]


Expand Down Expand Up @@ -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])
Expand Down
26 changes: 13 additions & 13 deletions tests/test_tools.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
from copy import copy

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
Expand Down Expand Up @@ -208,15 +202,17 @@ 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",
},
{
"_id": "paper2",
"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",
},
{
Expand All @@ -225,7 +221,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",
},
],
Expand Down Expand Up @@ -2570,7 +2567,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
Expand All @@ -2591,7 +2588,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
Expand Down Expand Up @@ -3143,8 +3140,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)
Expand All @@ -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:<group/org name>/2206_my_talk.git\nor (SSH):\ngit clone git@example.com:<group/org name>/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:<group/org name>/2206_my_talk.git\nor "
"(SSH):\ngit clone git@example.com:<group/org name>/2206_my_talk.git"
)


Expand Down

0 comments on commit 4947b58

Please sign in to comment.