Repository navigation
Fixed uptime_string_to_seconds for uptime strings without seconds - #927
Open
TheeCoderAhmed wants to merge 1 commit into
Open
TheeCoderAhmed wants to merge 1 commit into
TheeCoderAhmed wants to merge 1 commit into
Conversation
TheeCoderAhmed
requested review from
itdependsnetworks and
jeffkala
as code owners
November 4, 2026 02:24
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
New Pull Request
Have you:
Change Notes
Fixes #615
uptime_string_to_seconds("2w1d")raisesValueError: Unable to parse uptime string.The compact pattern inUPTIME_REGEX_PATTERNSrequires a trailing<n>s, so a compact uptime with no seconds matches nothing.This adds a fourth pattern for compact uptimes without seconds. It goes last, so any string the existing patterns already match gets the same result as before. It is anchored to the whole string because
uptime_string_to_secondsusesre.searchand every unit in the pattern is optional. Without the anchors, strings like"123"or"1mo"would match and return a wrong value, or 0, instead of raising.2w1dValueError1y3wValueError3d02hValueErrorthisismytime, empty string,123,1mo,1h 5m,up for 2w1dValueErrorValueErrorJustification
The issue reports this form in the
up-timevalue of a NETCONF query to a Cisco IOS-XE device. The question in the issue about which units that field can contain is still open. I don't have device output to check against, so the new pattern accepts the same units in the same order as the existing compact pattern, without the seconds. A bare1ystill raises, as it does in the existing pattern.What I ran, on Python 3.12:
tests/unit/test_time.py: the five new uptime cases fail withValueError: Unable to parse uptime string.on the default branch. All 27 tests in the file pass with the change.ruff checkandruff format --checkon the changed Python files.I did not run the rest of the test suite,
pylint,mypy, or the Docker basedinvoketasks.