Debian Codegraph @

test/test_utils/test_math/test__init__.py

raw symbols SCIP
1 #!/usr/bin/env python3
2 # :Copyright: © 2024 Günter Milde.
3 #
4 # :License: Released under the terms of the `2-Clause BSD license`_, in short:
5 #
6 # Copying and distribution of this file, with or without modification,
7 # are permitted in any medium without royalty provided the copyright
8 # notice and this notice are preserved.
9 # This file is offered as-is, without any warranty.
10 #
11 # .. _2-Clause BSD license: https://opensource.org/licenses/BSD-2-Clause
12 """
13 Test module for docutils/utils/math/__init__.py.
14 """
15
16 from pathlib import Path
17 import sys
18 import unittest
19
20 if __name__ == '__main__':
21 # prepend the "docutils root" to the Python library path
22 # so we import the local `docutils` package.
23 sys.path.insert(0, str(Path(__file__).resolve().parents[3]))
24
25 from docutils.utils import math
26
27 TEST_ROOT = Path(__file__).parents[2] # ./test/ from the docutils root
28
29
30 class MathTests(unittest.TestCase):
31
32 tests = [('a + b = c', 'equation*'),
33 (r'x = \begin{cases} -1&x<0 \\ 1&x>0 \end{cases}', 'equation*'),
34 (r'a + 2b = c \\ 3a + b = 2c', 'align*'),
35 ]
36
37 def test_pick_math_environment(self):
38 for sample, result in self.tests:
39 self.assertEqual(math.pick_math_environment(sample), result)
40
41 def test_wrap_math_code(self):
42 for sample, env in self.tests:
43 self.assertEqual(math.wrap_math_code(sample, as_block=False),
44 f'${sample}$')
45 self.assertEqual(math.wrap_math_code(sample, as_block=True),
46 f'\\begin{{{env}}}\n'
47 f'{sample}\n'
48 f'\\end{{{env}}}')
49
50
51 if __name__ == '__main__':
52 unittest.main()