[rtems-central commit] content: Improve duration()

Sebastian Huber sebh at rtems.org
Mon Jun 26 19:05:41 UTC 2023


Module:    rtems-central
Branch:    master
Commit:    697e33618fd8b6122370f33322d26b6af7dbd7d1
Changeset: http://git.rtems.org/rtems-central/commit/?id=697e33618fd8b6122370f33322d26b6af7dbd7d1

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Wed May 24 13:27:38 2023 +0200

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"



More information about the vc mailing list