-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_latex_functions.py
More file actions
65 lines (56 loc) · 2.43 KB
/
Copy pathtest_latex_functions.py
File metadata and controls
65 lines (56 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import unittest
from sphinx_runpython.ext_test_case import ExtTestCase, hide_stdout
from sphinx_runpython.tools.latex_functions import build_regex, replace_latex_command
class TestLatexFunction(ExtTestCase):
def test_build_regex(self):
regs = build_regex()
self.assertEqual(regs["supegal"], "\\geqslant")
@hide_stdout()
def test_replace_pattern(self):
self.assertEqual(replace_latex_command("\\R"), "\\mathbb{R}")
self.assertEqual(replace_latex_command("A\\R B"), "A\\mathbb{R} B")
self.assertEqual(replace_latex_command("\\pa{5+3i}"), "\\left(5+3i\\right)")
self.assertEqual(replace_latex_command("A\\pa{5+3i}B"), "A\\left(5+3i\\right)B")
self.assertEqual(replace_latex_command("\\cro{5+3i}"), "\\left[5+3i\\right]")
self.assertEqual(
replace_latex_command("\\acc{5+3i}"), "\\left\\{5+3i\\right\\}"
)
self.assertEqual(
replace_latex_command("\\vecteur{a}{b}"), "\\left(a,\\dots,b\\right)"
)
self.assertEqual(
replace_latex_command("\\pa{5\\pa{3i+3}}"),
"\\left(5\\left(3i+3\\right)\\right)",
)
self.assertEqual(
replace_latex_command("\\pa{5+3i}\\pa{3i+3}"),
"\\left(5+3i\\right)\\left(3i+3\\right)",
)
self.assertEqual(
replace_latex_command(
"\\indicatrice{ N \\supegal X } + \\cro{ X (s-p) + N (q-s)} "
"\\indicatrice{ N < X }",
verbose=1,
),
" {1\\!\\!1}_{\\left\\{ N \\geqslant X \\right\\}} + "
"\\left[ X (s-p) + N (q-s)\\right]"
" {1\\!\\!1}_{\\left\\{ N < X \\right\\}} ",
)
def test_replace_pattern_invalid_regex(self):
patterns = {"test": ("(invalid[", "replacement")}
self.assertRaise(
lambda: replace_latex_command("some text", patterns=patterns),
AssertionError,
)
def test_replace_pattern_unknown_type(self):
patterns = {"test": 42}
self.assertRaise(
lambda: replace_latex_command("some text", patterns=patterns),
AssertionError,
)
def test_replace_pattern_callable(self):
patterns = {"test": lambda t: t.replace("hello", "world")}
result = replace_latex_command("hello world", patterns=patterns)
self.assertEqual(result, "world world")
if __name__ == "__main__":
unittest.main(verbosity=2)