Code Duplication    Length = 51-55 lines in 4 locations

tests/test_listings.py 4 locations

@@ 132-186 (lines=55) @@
129
130
    assert json.loads(json.dumps(doc[1])) == json.loads(json.dumps(dest))
131
132
def test_listing_latex_color():
133
    init()
134
135
    meta = {
136
        'toccolor': {
137
            't': 'MetaInlines',
138
            'c': [Str('blue')]
139
        },
140
        'pandoc-numbering': {
141
            't': 'MetaList',
142
            'c': [
143
                {
144
                    't': 'MetaMap',
145
                    'c': {
146
                        'category': {
147
                            't': 'MetaInlines',
148
                            'c': [Str('exercise')]
149
                        },
150
                        'listing': {
151
                            't': 'MetaInlines',
152
                            'c': [Str('Listings'), Space(), Str('of'), Space(), Str('exercises')]
153
                        },
154
                        'sectioning': {
155
                            't': 'MetaInlines',
156
                            'c': [Str('-.+.')]
157
                        }
158
                    }
159
                }
160
            ]
161
        }
162
    }
163
164
    src = Para([Str(u'Exercise'), Space(), Str(u'#')])
165
    pandoc_numbering.numbering(src['t'], src['c'], 'latex', meta)
166
    src = Para([Str(u'Exercise'), Space(), Str('(test)'), Space(), Str(u'#')])
167
    pandoc_numbering.numbering(src['t'], src['c'], 'latex', meta)
168
169
    doc = [[{'unMeta': meta}], []]
170
    pandoc_numbering.addListings(doc, 'latex', meta)
171
172
    dest = [
173
        Header(1, ['', ['unnumbered'], []], [Str('Listings'), Space(), Str('of'), Space(), Str('exercises')]),
174
        RawBlock(
175
            'tex',
176
            ''.join([
177
                '\\hypersetup{linkcolor=blue}',
178
                '\\makeatletter',
179
                '\\newcommand*\\l@exercise{\\@dottedtocline{1}{1.5em}{3.3em}}',
180
                '\\@starttoc{exercise}',
181
                '\\makeatother'
182
            ])
183
        )
184
    ]
185
186
    assert json.loads(json.dumps(doc[1])) == json.loads(json.dumps(dest))
187
188
def test_listing_latex_tab_space():
189
    init()
@@ 242-294 (lines=53) @@
239
240
    assert json.loads(json.dumps(doc[1])) == json.loads(json.dumps(dest))
241
242
def test_listing_latex_tab_space_error():
243
    init()
244
245
    meta = {
246
        'pandoc-numbering': {
247
            't': 'MetaList',
248
            'c': [
249
                {
250
                    't': 'MetaMap',
251
                    'c': {
252
                        'category': {
253
                            't': 'MetaInlines',
254
                            'c': [Str('exercise')]
255
                        },
256
                        'listing': {
257
                            't': 'MetaInlines',
258
                            'c': [Str('Listings'), Space(), Str('of'), Space(), Str('exercises')]
259
                        },
260
                        'sectioning': {
261
                            't': 'MetaInlines',
262
                            'c': [Str('-.+.')]
263
                        },
264
                        'tab': {
265
                            't': 'MetaString',
266
                            'c': 'a'
267
                        },
268
                        'space': {
269
                            't': 'MetaString',
270
                            'c': 'b'
271
                        }
272
                    }
273
                }
274
            ]
275
        }
276
    }
277
278
    src = Para([Str(u'Exercise'), Space(), Str(u'#')])
279
    pandoc_numbering.numbering(src['t'], src['c'], 'latex', meta)
280
    src = Para([Str(u'Exercise'), Space(), Str('(test)'), Space(), Str(u'#')])
281
    pandoc_numbering.numbering(src['t'], src['c'], 'latex', meta)
282
283
    doc = [[{'unMeta': meta}], []]
284
    pandoc_numbering.addListings(doc, 'latex', meta)
285
286
    dest = [
287
        Header(1, ['', ['unnumbered'], []], [Str('Listings'), Space(), Str('of'), Space(), Str('exercises')]),
288
        RawBlock(
289
            'tex',
290
            '\\hypersetup{linkcolor=black}\\makeatletter\\newcommand*\\l@exercise{\\@dottedtocline{1}{1.5em}{3.3em}}\\@starttoc{exercise}\\makeatother'
291
        )
292
    ]
293
294
    assert json.loads(json.dumps(doc[1])) == json.loads(json.dumps(dest))
295
296
@@ 188-240 (lines=53) @@
185
186
    assert json.loads(json.dumps(doc[1])) == json.loads(json.dumps(dest))
187
188
def test_listing_latex_tab_space():
189
    init()
190
191
    meta = {
192
        'pandoc-numbering': {
193
            't': 'MetaList',
194
            'c': [
195
                {
196
                    't': 'MetaMap',
197
                    'c': {
198
                        'category': {
199
                            't': 'MetaInlines',
200
                            'c': [Str('exercise')]
201
                        },
202
                        'listing': {
203
                            't': 'MetaInlines',
204
                            'c': [Str('Listings'), Space(), Str('of'), Space(), Str('exercises')]
205
                        },
206
                        'sectioning': {
207
                            't': 'MetaInlines',
208
                            'c': [Str('-.+.')]
209
                        },
210
                        'tab': {
211
                            't': 'MetaString',
212
                            'c': '2'
213
                        },
214
                        'space': {
215
                            't': 'MetaString',
216
                            'c': '4'
217
                        }
218
                    }
219
                }
220
            ]
221
        }
222
    }
223
224
    src = Para([Str(u'Exercise'), Space(), Str(u'#')])
225
    pandoc_numbering.numbering(src['t'], src['c'], 'latex', meta)
226
    src = Para([Str(u'Exercise'), Space(), Str('(test)'), Space(), Str(u'#')])
227
    pandoc_numbering.numbering(src['t'], src['c'], 'latex', meta)
228
229
    doc = [[{'unMeta': meta}], []]
230
    pandoc_numbering.addListings(doc, 'latex', meta)
231
232
    dest = [
233
        Header(1, ['', ['unnumbered'], []], [Str('Listings'), Space(), Str('of'), Space(), Str('exercises')]),
234
        RawBlock(
235
            'tex',
236
            '\\hypersetup{linkcolor=black}\\makeatletter\\newcommand*\\l@exercise{\\@dottedtocline{1}{2.0em}{4.0em}}\\@starttoc{exercise}\\makeatother'
237
        )
238
    ]
239
240
    assert json.loads(json.dumps(doc[1])) == json.loads(json.dumps(dest))
241
242
def test_listing_latex_tab_space_error():
243
    init()
@@ 80-130 (lines=51) @@
77
78
    assert json.loads(json.dumps(doc[1])) == json.loads(json.dumps(dest))
79
80
def test_listing_latex():
81
    init()
82
83
    meta = {
84
        'pandoc-numbering': {
85
            't': 'MetaList',
86
            'c': [
87
                {
88
                    't': 'MetaMap',
89
                    'c': {
90
                        'category': {
91
                            't': 'MetaInlines',
92
                            'c': [Str('exercise')]
93
                        },
94
                        'listing': {
95
                            't': 'MetaInlines',
96
                            'c': [Str('Listings'), Space(), Str('of'), Space(), Str('exercises')]
97
                        },
98
                        'sectioning': {
99
                            't': 'MetaInlines',
100
                            'c': [Str('-.+.')]
101
                        }
102
                    }
103
                }
104
            ]
105
        }
106
    }
107
108
    src = Para([Str(u'Exercise'), Space(), Str(u'#')])
109
    pandoc_numbering.numbering(src['t'], src['c'], 'latex', meta)
110
    src = Para([Str(u'Exercise'), Space(), Str('(test)'), Space(), Str(u'#')])
111
    pandoc_numbering.numbering(src['t'], src['c'], 'latex', meta)
112
113
    doc = [[{'unMeta': meta}], []]
114
    pandoc_numbering.addListings(doc, 'latex', meta)
115
116
    dest = [
117
        Header(1, ['', ['unnumbered'], []], [Str('Listings'), Space(), Str('of'), Space(), Str('exercises')]),
118
        RawBlock(
119
            'tex',
120
            ''.join([
121
                '\\hypersetup{linkcolor=black}',
122
                '\\makeatletter',
123
                '\\newcommand*\\l@exercise{\\@dottedtocline{1}{1.5em}{3.3em}}',
124
                '\\@starttoc{exercise}',
125
                '\\makeatother'
126
            ])
127
        )
128
    ]
129
130
    assert json.loads(json.dumps(doc[1])) == json.loads(json.dumps(dest))
131
132
def test_listing_latex_color():
133
    init()