Passed
Push — develop ( 874d1e...76289b )
by Christophe
04:05
created

tests.test_tip   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 451
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 9
eloc 67
dl 0
loc 451
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A TipTest.test_div_rule() 0 40 1
A TipTest.test_codeblock() 0 49 1
A TipTest.test_div_bulletlist() 0 46 1
A TipTest.test_div_codeblock() 0 49 1
A TipTest.test_div_div() 0 41 1
A TipTest.test_span() 0 61 1
A TipTest.verify_conversion() 0 38 1
A TipTest.test_div_lineblock() 0 42 1
A TipTest.test_div() 0 61 1
1
from unittest import TestCase
2
3
from panflute import convert_text
4
5
import pandoc_latex_tip
6
7
8
class TipTest(TestCase):
9
    def verify_conversion(
10
        self,
11
        text,
12
        expected,
13
        transform,
14
        input_format="markdown",
15
        output_format="latex",
16
        standalone=False,
17
    ) -> None:
18
        """
19
        Verify the conversion.
20
21
        Parameters
22
        ----------
23
        text
24
            input text
25
        expected
26
            expected text
27
        transform
28
            filter function
29
        input_format
30
            input format
31
        output_format
32
            output format
33
        standalone
34
            is the output format standalone ?
35
        """
36
        doc = convert_text(text, input_format=input_format, standalone=True)
37
        doc.format = output_format
38
        doc = transform(doc)
39
        converted = convert_text(
40
            doc.content,
41
            input_format="panflute",
42
            output_format=output_format,
43
            extra_args=["--wrap=none"],
44
            standalone=standalone,
45
        )
46
        self.assertEqual(converted.strip(), expected.strip())
47
48
    def test_span(self):
49
        self.verify_conversion(
50
            """
51
---
52
pandoc-latex-tip:
53
  - classes: [tip, listing]
54
    icons:
55
      - {name: fa-file-text, color: darksalmon, link: http://www.google.fr}
56
      - fa-comments
57
    size: 36
58
    position: right
59
60
  - classes: [warning]
61
    icons: fa-comments
62
63
  - classes: [tip]
64
    position: left
65
66
  - classes: [v5.0]
67
    icons:
68
      - name: far-user
69
        color: orange
70
---
71
72
[]{.tip .listing}[]{.tip}[]{.warning}[]{.v5.0}
73
            """,
74
            """
75
{}
76
\\checkoddpage%%
77
\\ifoddpage%%
78
\\pandoclatextipoddright%%
79
\\else%%
80
\\pandoclatextipevenright%%
81
\\fi%%
82
\\marginnote{\\href{http://www.google.fr}{\\includegraphics[width=0.5in,height=0.5in]{/home/chdemko/.cache/pandoc_latex_tip/darksalmon/fa-file-text.png}}\\includegraphics[width=0.5in,height=0.5in]{/home/chdemko/.cache/pandoc_latex_tip/black/fa-comments.png}}[0pt]\\vspace{0cm}%%
83
{}
84
\\checkoddpage%%
85
\\ifoddpage%%
86
\\pandoclatextipoddleft%%
87
\\else%%
88
\\pandoclatextipevenleft%%
89
\\fi%%
90
\\marginnote{\\includegraphics[width=0.25in,height=0.25in]{/home/chdemko/.cache/pandoc_latex_tip/black/fa-exclamation-circle.png}}[0pt]\\vspace{0cm}%%
91
{}
92
\\checkoddpage%%
93
\\ifoddpage%%
94
\\pandoclatextipoddleft%%
95
\\else%%
96
\\pandoclatextipevenleft%%
97
\\fi%%
98
\\marginnote{\\includegraphics[width=0.25in,height=0.25in]{/home/chdemko/.cache/pandoc_latex_tip/black/fa-comments.png}}[0pt]\\vspace{0cm}%%
99
{}
100
\\checkoddpage%%
101
\\ifoddpage%%
102
\\pandoclatextipoddleft%%
103
\\else%%
104
\\pandoclatextipevenleft%%
105
\\fi%%
106
\\marginnote{\\includegraphics[width=0.25in,height=0.25in]{/home/chdemko/.cache/pandoc_latex_tip/orange/far-user.png}}[0pt]\\vspace{0cm}%%
107
            """,
108
            pandoc_latex_tip.main,
109
        )
110
111
    def test_codeblock(self):
112
        self.verify_conversion(
113
            """
114
---
115
pandoc-latex-tip:
116
  - classes: [tip, listing]
117
    icons:
118
      - {name: fa-file-text, color: darksalmon, link: http://www.google.fr}
119
      - fa-comments
120
    size: 36
121
    position: right
122
123
  - classes: [warning]
124
    icons: fa-comments
125
126
  - classes: [tip]
127
    position: left
128
129
  - classes: [v5.0]
130
    icons:
131
      - name: far-user
132
        color: orange
133
---
134
135
~~~{.python .warning}
136
main()
137
~~~
138
139
            """,
140
            """
141
\\begin{minipage}{\\textwidth}
142
\\checkoddpage%%
143
\\ifoddpage%%
144
\\pandoclatextipoddleft%%
145
\\else%%
146
\\pandoclatextipevenleft%%
147
\\fi%%
148
\\marginnote{\\includegraphics[width=0.25in,height=0.25in]{/home/chdemko/.cache/pandoc_latex_tip/black/fa-comments.png}}[0pt]\\vspace{0cm}%%
149
150
\\begin{Shaded}
151
\\begin{Highlighting}[]
152
\\NormalTok{main()}
153
\\end{Highlighting}
154
\\end{Shaded}
155
156
\\end{minipage}
157
158
            """,
159
            pandoc_latex_tip.main,
160
        )
161
162
    def test_div(self):
163
        self.verify_conversion(
164
            """
165
---
166
pandoc-latex-tip:
167
  - classes: [tip, listing]
168
    icons:
169
      - {name: fa-file-text, color: darksalmon, link: http://www.google.fr}
170
      - fa-comments
171
    size: 36
172
    position: right
173
174
  - classes: [warning]
175
    icons: fa-comments
176
177
  - classes: [tip]
178
    position: left
179
180
  - classes: [v5.0]
181
    icons:
182
      - name: far-user
183
        color: orange
184
---
185
186
::: warning
187
Division
188
:::
189
            """,
190
            """
191
Division
192
\\checkoddpage%%
193
\\ifoddpage%%
194
\\pandoclatextipoddleft%%
195
\\else%%
196
\\pandoclatextipevenleft%%
197
\\fi%%
198
\\marginnote{\\includegraphics[width=0.25in,height=0.25in]{/home/chdemko/.cache/pandoc_latex_tip/black/fa-comments.png}}[0pt]\\vspace{0cm}%%
199
            """,
200
            pandoc_latex_tip.main,
201
        )
202
        self.verify_conversion(
203
            """
204
::: {
205
  latex-tip-icon=fa-address-book
206
  latex-tip-size=24
207
  latex-tip-position=right
208
  latex-tip-color=lightskyblue} :::
209
Division
210
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
211
            """,
212
            """
213
Division
214
\\checkoddpage%%
215
\\ifoddpage%%
216
\\pandoclatextipoddright%%
217
\\else%%
218
\\pandoclatextipevenright%%
219
\\fi%%
220
\\marginnote{\\includegraphics[width=0.33333in,height=0.33333in]{/home/chdemko/.cache/pandoc_latex_tip/lightskyblue/fa-address-book.png}}[0pt]\\vspace{0cm}%%
221
            """,
222
            pandoc_latex_tip.main,
223
        )
224
225
    def test_div_div(self):
226
        self.verify_conversion(
227
            """
228
---
229
pandoc-latex-tip:
230
  - classes: [tip, listing]
231
    icons:
232
      - {name: fa-file-text, color: darksalmon, link: http://www.google.fr}
233
      - fa-comments
234
    size: 36
235
    position: right
236
237
  - classes: [warning]
238
    icons: fa-comments
239
240
  - classes: [tip]
241
    position: left
242
243
  - classes: [v5.0]
244
    icons:
245
      - name: far-user
246
        color: orange
247
---
248
249
::: warning
250
::: div
251
Division
252
:::
253
:::
254
            """,
255
            """
256
Division
257
\\checkoddpage%%
258
\\ifoddpage%%
259
\\pandoclatextipoddleft%%
260
\\else%%
261
\\pandoclatextipevenleft%%
262
\\fi%%
263
\\marginnote{\\includegraphics[width=0.25in,height=0.25in]{/home/chdemko/.cache/pandoc_latex_tip/black/fa-comments.png}}[0pt]\\vspace{0cm}%%
264
            """,
265
            pandoc_latex_tip.main,
266
        )
267
268
    def test_div_rule(self):
269
        self.verify_conversion(
270
            """
271
---
272
pandoc-latex-tip:
273
  - classes: [tip, listing]
274
    icons:
275
      - {name: fa-file-text, color: darksalmon, link: http://www.google.fr}
276
      - fa-comments
277
    size: 36
278
    position: right
279
280
  - classes: [warning]
281
    icons: fa-comments
282
283
  - classes: [tip]
284
    position: left
285
286
  - classes: [v5.0]
287
    icons:
288
      - name: far-user
289
        color: orange
290
---
291
292
::: warning
293
-----------
294
:::
295
            """,
296
            """
297
\\checkoddpage%%
298
\\ifoddpage%%
299
\\pandoclatextipoddleft%%
300
\\else%%
301
\\pandoclatextipevenleft%%
302
\\fi%%
303
\\marginnote{\\includegraphics[width=0.25in,height=0.25in]{/home/chdemko/.cache/pandoc_latex_tip/black/fa-comments.png}}[0pt]\\vspace{0cm}%%
304
305
\\begin{center}\\rule{0.5\\linewidth}{0.5pt}\\end{center}
306
            """,
307
            pandoc_latex_tip.main,
308
        )
309
310
    def test_div_lineblock(self):
311
        self.verify_conversion(
312
            """
313
---
314
pandoc-latex-tip:
315
  - classes: [tip, listing]
316
    icons:
317
      - {name: fa-file-text, color: darksalmon, link: http://www.google.fr}
318
      - fa-comments
319
    size: 36
320
    position: right
321
322
  - classes: [warning]
323
    icons: fa-comments
324
325
  - classes: [tip]
326
    position: left
327
328
  - classes: [v5.0]
329
    icons:
330
      - name: far-user
331
        color: orange
332
---
333
334
::: warning
335
| Lineblock
336
| continue
337
:::
338
            """,
339
            """
340
Lineblock
341
\\checkoddpage%%
342
\\ifoddpage%%
343
\\pandoclatextipoddleft%%
344
\\else%%
345
\\pandoclatextipevenleft%%
346
\\fi%%
347
\\marginnote{\\includegraphics[width=0.25in,height=0.25in]{/home/chdemko/.cache/pandoc_latex_tip/black/fa-comments.png}}[0pt]\\vspace{0cm}%%
348
\\\\
349
continue
350
            """,
351
            pandoc_latex_tip.main,
352
        )
353
354
    def test_div_codeblock(self):
355
        self.verify_conversion(
356
            """
357
---
358
pandoc-latex-tip:
359
  - classes: [tip, listing]
360
    icons:
361
      - {name: fa-file-text, color: darksalmon, link: http://www.google.fr}
362
      - fa-comments
363
    size: 36
364
    position: right
365
366
  - classes: [warning]
367
    icons: fa-comments
368
369
  - classes: [tip]
370
    position: left
371
372
  - classes: [v5.0]
373
    icons:
374
      - name: far-user
375
        color: orange
376
---
377
378
::: warning
379
~~~python
380
main()
381
~~~
382
:::
383
            """,
384
            """
385
\\begin{minipage}{\\textwidth}
386
\\checkoddpage%%
387
\\ifoddpage%%
388
\\pandoclatextipoddleft%%
389
\\else%%
390
\\pandoclatextipevenleft%%
391
\\fi%%
392
\\marginnote{\\includegraphics[width=0.25in,height=0.25in]{/home/chdemko/.cache/pandoc_latex_tip/black/fa-comments.png}}[0pt]\\vspace{0cm}%%
393
394
\\begin{Shaded}
395
\\begin{Highlighting}[]
396
\\NormalTok{main()}
397
\\end{Highlighting}
398
\\end{Shaded}
399
400
\\end{minipage}
401
            """,
402
            pandoc_latex_tip.main,
403
        )
404
405
    def test_div_bulletlist(self):
406
        self.verify_conversion(
407
            """
408
---
409
pandoc-latex-tip:
410
  - classes: [tip, listing]
411
    icons:
412
      - {name: fa-file-text, color: darksalmon, link: http://www.google.fr}
413
      - fa-comments
414
    size: 36
415
    position: right
416
417
  - classes: [warning]
418
    icons: fa-comments
419
420
  - classes: [tip]
421
    position: left
422
423
  - classes: [v5.0]
424
    icons:
425
      - name: far-user
426
        color: orange
427
---
428
429
::: warning
430
* a
431
* b
432
:::
433
            """,
434
            """
435
\\begin{itemize}
436
\\tightlist
437
\\item
438
  a
439
  \\checkoddpage%%
440
  \\ifoddpage%%
441
  \\pandoclatextipoddleft%%
442
  \\else%%
443
  \\pandoclatextipevenleft%%
444
  \\fi%%
445
  \\marginnote{\\includegraphics[width=0.25in,height=0.25in]{/home/chdemko/.cache/pandoc_latex_tip/black/fa-comments.png}}[0pt]\\vspace{0cm}%%
446
\\item
447
  b
448
\\end{itemize}
449
            """,
450
            pandoc_latex_tip.main,
451
        )
452