chrisjsewell / ipypublish
1 3
import sys
2 3
import pytest
3

4 3
if sys.version_info >= (3, 0):
5 3
    from ipypublish.bib2glossary.parse_tex import parse_tex
6

7

8 3
@pytest.mark.skipif(
9
    sys.version_info < (3, 0),
10
    reason="SyntaxError on import of texsoup/data.py line 135",
11
)
12 3
def test_parse_acronyms():
13

14 3
    text_str = """
15
    \\newacronym{otherkey}{OTHER}{Abbreviation of other}
16
    \\newacronym{thekey}{ABRV}{Abbreviation}
17
    """
18 3
    gterms, acronyms = parse_tex(text_str=text_str)
19 3
    assert gterms == {}
20 3
    assert acronyms == {
21
        "otherkey": {"abbreviation": "OTHER", "longname": "Abbreviation of other"},
22
        "thekey": {"abbreviation": "ABRV", "longname": "Abbreviation"},
23
    }
24

25

26 3
@pytest.mark.skipif(
27
    sys.version_info < (3, 0),
28
    reason="SyntaxError on import of texsoup/data.py line 135",
29
)
30 3
def test_parse_acronyms_with_options():
31

32 3
    text_str = """
33
    \\newacronym[description={a description}]{otherkey}{OTHER}{Abbreviation of other}
34
    \\newacronym[plural={ABRVs},longplural={Abbreviations}]{thekey}{ABRV}{Abbreviation}
35
    """  # noqa: E501
36 3
    gterms, acronyms = parse_tex(text_str=text_str)
37 3
    assert gterms == {}
38 3
    assert acronyms == {
39
        "otherkey": {
40
            "abbreviation": "OTHER",
41
            "longname": "Abbreviation of other",
42
            "description": "a description",
43
        },
44
        "thekey": {
45
            "abbreviation": "ABRV",
46
            "longname": "Abbreviation",
47
            "longplural": "Abbreviations",
48
            "plural": "ABRVs",
49
        },
50
    }
51

52

53 3
@pytest.mark.skipif(
54
    sys.version_info < (3, 0),
55
    reason="SyntaxError on import of texsoup/data.py line 135",
56
)
57 3
def test_parse_gterms():
58

59 3
    text_str = """
60
    \\newglossaryentry{otherkey}{
61
        name={other name},
62
        description={the description of other}
63
    }
64
    \\newglossaryentry{thekey}{
65
        name={name},
66
        description={the description},
67
        type={symbols}
68
    }
69
    """
70 3
    gterms, acronyms = parse_tex(text_str=text_str)
71 3
    assert acronyms == {}
72 3
    assert gterms == {
73
        "otherkey": {"description": "the description of other", "name": "other name"},
74
        "thekey": {"description": "the description", "name": "name", "type": "symbols"},
75
    }
76

77

78 3
@pytest.mark.skipif(
79
    sys.version_info < (3, 0),
80
    reason="SyntaxError on import of texsoup/data.py line 135",
81
)
82 3
def test_parse_mixed():
83 3
    text_str = """
84
    \\newacronym{otherkey}{OTHER}{Abbreviation of other}
85
    \\newglossaryentry{thekey}{
86
        name={name},
87
        description={the description},
88
        type={symbols}
89
    }
90
    """
91 3
    gterms, acronyms = parse_tex(text_str=text_str)
92 3
    assert acronyms == {
93
        "otherkey": {"abbreviation": "OTHER", "longname": "Abbreviation of other"}
94
    }
95 3
    assert gterms == {
96
        "thekey": {"description": "the description", "name": "name", "type": "symbols"}
97
    }
98

99

100 3
@pytest.mark.skipif(
101
    sys.version_info < (3, 0),
102
    reason="SyntaxError on import of texsoup/data.py line 135",
103
)
104 3
def test_duplicate_key():
105 3
    text_str = """
106
    \\newacronym{thekey}{OTHER}{Abbreviation of other}
107
    \\newglossaryentry{thekey}{
108
        name={name},
109
        description={the description},
110
        type={symbols}
111
    }
112
    """
113 3
    with pytest.raises(KeyError):
114 3
        parse_tex(text_str=text_str)
115

116

117 3
@pytest.mark.skipif(
118
    sys.version_info < (3, 0),
119
    reason="SyntaxError on import of texsoup/data.py line 135",
120
)
121 3
def test_acronym_ioerror():
122 3
    text_str = """
123
    \\newacronym{thekey}{Abbreviation of other}
124
    """
125 3
    with pytest.raises(IOError):
126 3
        parse_tex(text_str=text_str)
127

128

129 3
@pytest.mark.skipif(
130
    sys.version_info < (3, 0),
131
    reason="SyntaxError on import of texsoup/data.py line 135",
132
)
133 3
def test_gterm_ioerror():
134 3
    text_str = """
135
    \\newglossaryentry{}
136
    """
137 3
    with pytest.raises(IOError):
138 3
        parse_tex(text_str=text_str)
139

140

141 3
@pytest.mark.skipif(
142
    sys.version_info < (3, 0),
143
    reason="SyntaxError on import of texsoup/data.py line 135",
144
)
145 3
def test_ioerror_skip():
146 3
    text_str = """
147
    \\newacronym{thekey}{Abbreviation of other}
148
    \\newacronym{thekey2}{ABBR}{Abbreviation of other}
149
    """
150 3
    gterms, acronyms = parse_tex(text_str=text_str, skip_ioerrors=True)
151 3
    assert gterms == {}
152 3
    assert acronyms == {
153
        "thekey2": {"abbreviation": "ABBR", "longname": "Abbreviation of other"}
154
    }

Read our documentation on viewing source code .

Loading