test_figure   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 201
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 22
dl 0
loc 201
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A FigureTest.test_figure() 0 188 2
1
import io
2
import json
3
import textwrap
4
5
from unittest import TestCase
6
7
from panflute import Doc, convert_text, dump, debug
8
9
import pandoc_figure
10
11
12
class FigureTest(TestCase):
13
    def test_figure(self):
14
        definition = """\
15
            ::: {.figure caption="Figure caption" #fig:id}
16
            
17
            ![First subfigure](sub-figure-1.png "Title 1")
18
            
19
            ![Second subfigure](sub-figure-2.png "Title 2"){#fig:subfig2}
20
            
21
            :::
22
        """
23
        debug(textwrap.dedent(definition).strip())
24
        doc = convert_text(textwrap.dedent(definition).strip(), standalone=True)
25
        modified = pandoc_figure.main(doc)
26
        with io.StringIO() as stream:
27
            dump(modified, stream)
28
            contents = stream.getvalue()
29
            parsed = json.loads(contents)
30
            self.assertEqual(
31
                json.dumps(parsed["blocks"], indent=2),
32
                textwrap.dedent(
33
                    """
34
                    [
35
                      {
36
                        "t": "Figure",
37
                        "c": [
38
                          [
39
                            "fig:id",
40
                            [],
41
                            []
42
                          ],
43
                          [
44
                            null,
45
                            [
46
                              {
47
                                "t": "Plain",
48
                                "c": [
49
                                  {
50
                                    "t": "Str",
51
                                    "c": "Figure"
52
                                  },
53
                                  {
54
                                    "t": "Space"
55
                                  },
56
                                  {
57
                                    "t": "Str",
58
                                    "c": "caption"
59
                                  }
60
                                ]
61
                              }
62
                            ]
63
                          ],
64
                          [
65
                            {
66
                              "t": "Figure",
67
                              "c": [
68
                                [
69
                                  "",
70
                                  [],
71
                                  []
72
                                ],
73
                                [
74
                                  null,
75
                                  [
76
                                    {
77
                                      "t": "Plain",
78
                                      "c": [
79
                                        {
80
                                          "t": "Str",
81
                                          "c": "First"
82
                                        },
83
                                        {
84
                                          "t": "Space"
85
                                        },
86
                                        {
87
                                          "t": "Str",
88
                                          "c": "subfigure"
89
                                        }
90
                                      ]
91
                                    }
92
                                  ]
93
                                ],
94
                                [
95
                                  {
96
                                    "t": "Plain",
97
                                    "c": [
98
                                      {
99
                                        "t": "Image",
100
                                        "c": [
101
                                          [
102
                                            "",
103
                                            [],
104
                                            []
105
                                          ],
106
                                          [
107
                                            {
108
                                              "t": "Str",
109
                                              "c": "First"
110
                                            },
111
                                            {
112
                                              "t": "Space"
113
                                            },
114
                                            {
115
                                              "t": "Str",
116
                                              "c": "subfigure"
117
                                            }
118
                                          ],
119
                                          [
120
                                            "sub-figure-1.png",
121
                                            "Title 1"
122
                                          ]
123
                                        ]
124
                                      }
125
                                    ]
126
                                  }
127
                                ]
128
                              ]
129
                            },
130
                            {
131
                              "t": "Figure",
132
                              "c": [
133
                                [
134
                                  "fig:subfig2",
135
                                  [],
136
                                  []
137
                                ],
138
                                [
139
                                  null,
140
                                  [
141
                                    {
142
                                      "t": "Plain",
143
                                      "c": [
144
                                        {
145
                                          "t": "Str",
146
                                          "c": "Second"
147
                                        },
148
                                        {
149
                                          "t": "Space"
150
                                        },
151
                                        {
152
                                          "t": "Str",
153
                                          "c": "subfigure"
154
                                        }
155
                                      ]
156
                                    }
157
                                  ]
158
                                ],
159
                                [
160
                                  {
161
                                    "t": "Plain",
162
                                    "c": [
163
                                      {
164
                                        "t": "Image",
165
                                        "c": [
166
                                          [
167
                                            "",
168
                                            [],
169
                                            []
170
                                          ],
171
                                          [
172
                                            {
173
                                              "t": "Str",
174
                                              "c": "Second"
175
                                            },
176
                                            {
177
                                              "t": "Space"
178
                                            },
179
                                            {
180
                                              "t": "Str",
181
                                              "c": "subfigure"
182
                                            }
183
                                          ],
184
                                          [
185
                                            "sub-figure-2.png",
186
                                            "Title 2"
187
                                          ]
188
                                        ]
189
                                      }
190
                                    ]
191
                                  }
192
                                ]
193
                              ]
194
                            }
195
                          ]
196
                        ]
197
                      }
198
                    ]
199
                    """
200
                ).strip(),
201
            )
202