From 59ffc715406b63cdadc47dc5688da0c16ab4f9d8 Mon Sep 17 00:00:00 2001 From: Splines Date: Mon, 18 Mar 2024 17:43:53 +0100 Subject: [PATCH] Improve unit string in console output This fixes #24. --- src/api/console_stringifier.py | 4 +++- tests/playground.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/api/console_stringifier.py b/src/api/console_stringifier.py index c022067e..a1b9a980 100644 --- a/src/api/console_stringifier.py +++ b/src/api/console_stringifier.py @@ -36,8 +36,10 @@ def _modify_unit(self, unit: str) -> str: unit = ( unit.replace(r"\squared", "^2") .replace(r"\cubed", "^3") + .replace("\\per\\", "/") .replace(r"\per", "/") - .replace("\\", "") + .replace("\\", " ") + .strip() ) if unit[0] == "/": diff --git a/tests/playground.py b/tests/playground.py index a29b1594..794e70d0 100644 --- a/tests/playground.py +++ b/tests/playground.py @@ -32,7 +32,7 @@ # wiz.res("", 42.0).print() # -> Error: "name must not be empty" -wiz.res("a911", 1.0, r"\mm") +wiz.res("a911", 1.0, r"\mm\s\per\N\kg") # a: 1.0 \mm wiz.res("1 b", 1.0, 0.01, r"\per\mm\cubed").print()