Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/615.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed uptime_string_to_seconds raising ValueError for uptime strings without a seconds value, such as "2w1d".
4 changes: 4 additions & 0 deletions netutils/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,10 @@
r"(((?P<years>\d+)y)?(?P<weeks>\d+)w)?((?P<days>\d+)d)?((?P<hours>\d+)h)?"
r"((?P<minutes>\d+)m)?((?P<seconds>\d+)s)"
), # pylint: disable=implicit-str-concat
(
r"^(?=\d)(((?P<years>\d+)y)?(?P<weeks>\d+)w)?((?P<days>\d+)d)?((?P<hours>\d+)h)?"
r"((?P<minutes>\d+)m)?$"
), # pylint: disable=implicit-str-concat
]

# Do not modify list, see UPGRADE_PATHS documentation on the versioning of this
Expand Down
10 changes: 8 additions & 2 deletions tests/unit/test_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@
{"sent": "4m15s", "received": 255},
{"sent": "6d10m1s", "received": 519001},
{"sent": "1y3w10m2s", "received": 33351002},
{"sent": "2w1d", "received": 1296000},
{"sent": "1y3w", "received": 33350400},
{"sent": "3d02h", "received": 266400},
{"sent": "5h10m", "received": 18600},
{"sent": "10m", "received": 600},
]


Expand All @@ -58,6 +63,7 @@ def test_uptime_string_to_seconds(data):
assert uptime_string_to_seconds(data["sent"]) == data["received"]


def test_fail_uptime_string_to_seconds():
@pytest.mark.parametrize("data", ["thisismytime", "", "123", "1mo", "1h 5m", "up for 2w1d"])
def test_fail_uptime_string_to_seconds(data):
with pytest.raises(Exception, match=r"Unable to parse uptime string."):
uptime_string_to_seconds("thisismytime")
uptime_string_to_seconds(data)