From 25a1e6bbac57aa1d478d887d0d1f6faad2ad60fb Mon Sep 17 00:00:00 2001 From: Tim Grelka Date: Tue, 10 Dec 2024 11:02:19 +0100 Subject: [PATCH] feat: improve tests for unit rendering --- test/test_unit.py | 45 +++++++++++++++++++++++++++++++++++++++++ test/test_unit_token.py | 18 ----------------- test/util.py | 4 ++-- 3 files changed, 47 insertions(+), 20 deletions(-) create mode 100644 test/test_unit.py delete mode 100644 test/test_unit_token.py diff --git a/test/test_unit.py b/test/test_unit.py new file mode 100644 index 0000000..eb736cd --- /dev/null +++ b/test/test_unit.py @@ -0,0 +1,45 @@ +import mistletoe +import pytest + +from renderer.fifty_ohm_html_renderer import FiftyOhmHtmlRenderer + +from .util import paragraph + + +@pytest.mark.html +def test_basic_units_html(): + """Test basic units: Insert non-breaking, smaller space.""" + assertions = { + "1 V": "1 V", + "0,12 V": "0,12 V", + "0,75 kW": "0,75 kW", + "33 A": "33 A", + "1 Ah": "1 Ah", # Ah can be a tricky case if the RegEx is wrong, as A might match before Ah, thus rendering the output with an "A" unit + } + + for input, output in assertions.items(): + assert mistletoe.markdown(input, FiftyOhmHtmlRenderer) == paragraph(output) + + +@pytest.mark.html +def test_translated_units_html(): + """Test translated units: Replace Ohm with Ω.""" + assertions = { + "50 Ohm": "50 Ω", + "100 mOhm": "100 mΩ", + } + + for input, output in assertions.items(): + assert mistletoe.markdown(input, FiftyOhmHtmlRenderer) == paragraph(output) + + +@pytest.mark.html +def test_special_units_html(): + """Test special units: Don't put space before ° and %.""" + assertions = { + "100%": "100%", + "42,24°": "42,24°", + } + + for input, output in assertions.items(): + assert mistletoe.markdown(input, FiftyOhmHtmlRenderer) == paragraph(output) diff --git a/test/test_unit_token.py b/test/test_unit_token.py deleted file mode 100644 index 47c929e..0000000 --- a/test/test_unit_token.py +++ /dev/null @@ -1,18 +0,0 @@ -import mistletoe - -from renderer.fifty_ohm_html_renderer import FiftyOhmHtmlRenderer - -from .util import paragraph - - -def test_unit_html(): - assertions = { - "0,1 V": "0,1 V", - "33 A": "33 A", - "1 Ah": "1 Ah", - "100 mOhm": "100 mΩ", - "25 Ohm": "25 Ω", - } - - for input, output in assertions.items(): - assert mistletoe.markdown(input, FiftyOhmHtmlRenderer) == paragraph(output) diff --git a/test/util.py b/test/util.py index f30aa79..a86b9eb 100644 --- a/test/util.py +++ b/test/util.py @@ -1,2 +1,2 @@ -def paragraph(text) : - return f'

{text}

\n' \ No newline at end of file +def paragraph(text): + return f"

{text}

\n"