From 697e33618fd8b6122370f33322d26b6af7dbd7d1 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Wed, 24 May 2023 13:27:38 +0200 Subject: content: Improve duration() --- rtemsspec/content.py | 4 +++- rtemsspec/tests/test_content.py | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/rtemsspec/content.py b/rtemsspec/content.py index 5bccd325..9651664e 100644 --- a/rtemsspec/content.py +++ b/rtemsspec/content.py @@ -1208,8 +1208,10 @@ def get_integer_type(value: int) -> str: return f"uint{power}_t" -def duration(value: float) -> str: +def duration(value: Union[float, str]) -> str: """ Converts a duration in seconds into a value with unit string. """ + if isinstance(value, str): + return value assert value >= 0.0 if value == 0.0: return "0s" diff --git a/rtemsspec/tests/test_content.py b/rtemsspec/tests/test_content.py index e2a17d12..6bc344fa 100644 --- a/rtemsspec/tests/test_content.py +++ b/rtemsspec/tests/test_content.py @@ -333,6 +333,7 @@ def test_enabled_by_to_python_exp(): def test_duration(): + assert duration("abc") == "abc" assert duration(1.0) == "1.000s" assert duration(0.0) == "0s" assert duration(0.001) == "1.000ms" -- cgit v1.2.3