-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathtest_glossaries_extra.py
48 lines (38 loc) · 1.51 KB
/
test_glossaries_extra.py
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
import pytest
from yalafi import parameters, parser, utils
preamble = ('\\usepackage{glossaries-extra}\n'
+ '\\LTinput{tests/test_packages/glossaries-extra.glsdefs}\n')
def get_plain(latex):
def read(file):
try:
with open(file) as f:
return True, f.read()
except:
return False, ''
parms = parameters.Parameters()
p = parser.Parser(parms, read_macros=read)
plain, nums = utils.get_txt_pos(p.parse(preamble + latex))
assert len(plain) == len(nums)
return plain
# we first repeat tests from package glossaries, since the format of
# .glsdefs file is slightly different for glossaries-extra
#
from tests.test_packages import test_glossaries
@pytest.mark.parametrize('latex,plain_expected',
test_glossaries.data_test_macros_latex)
def test_macros_latex_glossaries(latex, plain_expected):
plain = get_plain(latex)
assert plain == plain_expected
data_test_macros_latex = [
(r'\newabbreviation{pp}{ppm}{parts per million}', 'Parts per million.'),
(r'\glsxtrshort{pp}', 'ppm'),
(r'\Glsxtrshort{pp}', 'Ppm'),
(r'\glsxtrlong{pp}', 'parts per million'),
(r'\Glsxtrlong{pp}', 'Parts per million'),
(r'\glsxtrfull{pp}', 'ppm (parts per million)'),
(r'\Glsxtrfull{pp}', 'ppm (Parts per million)'),
]
@pytest.mark.parametrize('latex,plain_expected', data_test_macros_latex)
def test_macros_latex(latex, plain_expected):
plain = get_plain(latex)
assert plain == plain_expected