From 385571d2fc325dfaa1cd887173c9fcb7a448fd27 Mon Sep 17 00:00:00 2001 From: Haibao Tang Date: Sat, 11 May 2024 00:12:04 -0700 Subject: [PATCH] Add test_markup() --- jcvi/graphics/base.py | 2 ++ tests/graphics/test_base.py | 14 +++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/jcvi/graphics/base.py b/jcvi/graphics/base.py index 8010edbb..f1ed271c 100644 --- a/jcvi/graphics/base.py +++ b/jcvi/graphics/base.py @@ -413,6 +413,8 @@ def markup(s: str): """ Change the string to latex format, and italicize the text between *. """ + if not rcParams["text.usetex"]: + return s if "$" in s: return s s = latex(s) diff --git a/tests/graphics/test_base.py b/tests/graphics/test_base.py index 88066444..0477bd90 100644 --- a/tests/graphics/test_base.py +++ b/tests/graphics/test_base.py @@ -3,6 +3,8 @@ import pytest +from jcvi.graphics.base import latex, markup, rc + @pytest.mark.parametrize( "s,expected", @@ -24,15 +26,21 @@ def test_shorten(s, expected): @pytest.mark.parametrize( "s,expected", [ - ("grape_grape vs peach_peach", "grape\_grape vs peach\_peach"), + ("grape_grape vs peach_peach", r"grape\_grape vs peach\_peach"), ], ) def test_latex(s, expected): - from jcvi.graphics.base import latex - assert latex(s) == expected, "Expect {}".format(expected) +def test_markup(): + rc("text", usetex=True) + s = "Prupe_1G289800.1" + assert markup(s) == r"Prupe\_1G289800.1" + rc("text", usetex=False) + assert markup(s) == s + + @pytest.mark.parametrize( "figname,format,expected", [