Completed
Push — master ( 85d380...5cc46a )
by Christophe
01:14
created

test_listing_latex_tab_space()   A

Complexity

Conditions 2

Size

Total Lines 53

Duplication

Lines 53
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
c 1
b 0
f 0
dl 53
loc 53
rs 9.5797

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
# This Python file uses the following encoding: utf-8
2
3
from unittest import TestCase
4
from pandocfilters import Para, Str, Space, Header, BulletList, Span, Strong, Plain, Link, RawBlock
5
6
import json
7
8
import pandoc_numbering
9
10 View Code Duplication
def init():
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
11
    pandoc_numbering.count = {}
12
    pandoc_numbering.information = {}
13
    pandoc_numbering.collections = {}
14
    pandoc_numbering.headers = [0, 0, 0, 0, 0, 0]
15
    if hasattr(pandoc_numbering.getCiteShortCut, 'value'):
16
        delattr(pandoc_numbering.getCiteShortCut, 'value')
17
    if hasattr(pandoc_numbering.getDefaultLevels, 'value'):
18
        delattr(pandoc_numbering.getDefaultLevels, 'value')
19
    if hasattr(pandoc_numbering.getClasses, 'value'):
20
        delattr(pandoc_numbering.getClasses, 'value')
21
    if hasattr(pandoc_numbering.getFormat, 'value'):
22
        delattr(pandoc_numbering.getFormat, 'value')
23
24
def createLink(attributes, text, reference_title):
25
    if pandoc_numbering.pandocVersion() < '1.16':
26
        return Link(text, reference_title)
27
    else:
28
        return Link(attributes, text, reference_title)
29
30
def test_listing_classic():
31
    init()
32
33
    meta = {
34
        'pandoc-numbering': {
35
            't': 'MetaList',
36
            'c': [
37
                {
38
                    't': 'MetaMap',
39
                    'c': {
40
                        'category': {
41
                            't': 'MetaInlines',
42
                            'c': [Str('exercise')]
43
                        },
44
                        'listing': {
45
                            't': 'MetaInlines',
46
                            'c': [Str('Listings'), Space(), Str('of'), Space(), Str('exercises')]
47
                        },
48
                        'sectioning': {
49
                            't': 'MetaInlines',
50
                            'c': [Str('-.+.')]
51
                        }
52
                    }
53
                }
54
            ]
55
        }
56
    }
57
58
    src = Para([Str(u'Exercise'), Space(), Str(u'#')])
59
    pandoc_numbering.numbering(src['t'], src['c'], '', meta)
60
    src = Para([Str(u'Exercise'), Space(), Str('(test)'), Space(), Str(u'#')])
61
    pandoc_numbering.numbering(src['t'], src['c'], '', meta)
62
63
    doc = [[{'unMeta': meta}], []]
64
    pandoc_numbering.addListings(doc, '', meta)
65
66
    dest = [
67
        Header(
68
			1,
69
			['', ['unnumbered'], []],
70
	        [Str('Listings'), Space(), Str('of'), Space(), Str('exercises')]
71
	    ),
72
	    BulletList([
73
	    	[Plain([createLink(['', [], []], [Str('0.0.1'), Space(), Str('Exercise')], ['#exercise:0.0.1', ''])])],
74
	    	[Plain([createLink(['', [], []], [Str('0.0.2'), Space(), Str('test')], ['#exercise:0.0.2', ''])])]
75
	    ])
76
	]
77
78
    assert json.loads(json.dumps(doc[1])) == json.loads(json.dumps(dest))
79
80 View Code Duplication
def test_listing_latex():
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
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 View Code Duplication
def test_listing_latex_color():
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
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 View Code Duplication
def test_listing_latex_tab_space():
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
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 View Code Duplication
def test_listing_latex_tab_space_error():
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
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