diff --git a/napalm_servertech_pro2/utils.py b/napalm_servertech_pro2/utils.py index eeabad2..95787df 100644 --- a/napalm_servertech_pro2/utils.py +++ b/napalm_servertech_pro2/utils.py @@ -4,8 +4,8 @@ def convert_uptime(uptime): """Converts a ServerTech uptime string to a number of seconds.""" time_regex = ( - r"^(?P\d+) days (?P\d+) hours" - r" (?P\d+) minutes (?P\d+) seconds$" + r"^(?P\d+) days? (?P\d+) hours?" + r" (?P\d+) minutes? (?P\d+) seconds?$" ) m = re.match( time_regex, diff --git a/tests/utils/test_utils.py b/tests/utils/test_utils.py index 8590f8f..309701f 100644 --- a/tests/utils/test_utils.py +++ b/tests/utils/test_utils.py @@ -8,7 +8,10 @@ def test_convert_uptime(): uptime = "11 days 4 hours 8 minutes 6 seconds" assert utils.convert_uptime(uptime) == 965286 - uptime = "0 days 0 hours 0 minutes 1 seconds" + uptime = "133 days 1 hour 12 minutes 15 seconds" + assert isinstance(utils.convert_uptime(uptime), int) + + uptime = "0 days 0 hours 0 minutes 1 second" assert utils.convert_uptime(uptime) == 1 with pytest.raises(ValueError):