-
Notifications
You must be signed in to change notification settings - Fork 691
/
Copy pathtest_utils.py
682 lines (591 loc) · 23.3 KB
/
test_utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
#!/usr/bin/env python
import logging
import os
import re
import unittest
from itertools import groupby
from operator import itemgetter
import pandas as pd
import pytest
from pdfminer.pdfparser import PDFObjRef
from pdfminer.psparser import PSLiteral
import pdfplumber
from pdfplumber import utils
logging.disable(logging.ERROR)
HERE = os.path.abspath(os.path.dirname(__file__))
class Test(unittest.TestCase):
@classmethod
def setup_class(self):
self.pdf = pdfplumber.open(os.path.join(HERE, "pdfs/pdffill-demo.pdf"))
self.pdf_scotus = pdfplumber.open(
os.path.join(HERE, "pdfs/scotus-transcript-p1.pdf")
)
@classmethod
def teardown_class(self):
self.pdf.close()
def test_cluster_list(self):
a = [1, 2, 3, 4]
assert utils.cluster_list(a) == [[x] for x in a]
assert utils.cluster_list(a, tolerance=1) == [a]
a = [1, 2, 5, 6]
assert utils.cluster_list(a, tolerance=1) == [[1, 2], [5, 6]]
def test_cluster_objects(self):
a = ["a", "ab", "abc", "b"]
assert utils.cluster_objects(a, len, 0) == [["a", "b"], ["ab"], ["abc"]]
b = [{"x": 1, 7: "a"}, {"x": 1, 7: "b"}, {"x": 2, 7: "b"}, {"x": 2, 7: "b"}]
assert utils.cluster_objects(b, "x", 0) == [[b[0], b[1]], [b[2], b[3]]]
assert utils.cluster_objects(b, 7, 0) == [[b[0]], [b[1], b[2], b[3]]]
def test_resolve(self):
annot = self.pdf.annots[0]
annot_ad0 = utils.resolve(annot["data"]["A"]["D"][0])
assert annot_ad0["MediaBox"] == [0, 0, 612, 792]
assert utils.resolve(1) == 1
def test_resolve_all(self):
info = self.pdf.doc.xrefs[0].trailer["Info"]
assert type(info) is PDFObjRef
a = [{"info": info}]
a_res = utils.resolve_all(a)
assert a_res[0]["info"]["Producer"] == self.pdf.doc.info[0]["Producer"]
def test_decode_psl_list(self):
a = [PSLiteral("test"), "test_2"]
assert utils.decode_psl_list(a) == ["test", "test_2"]
def test_x_tolerance_ratio(self):
pdf = pdfplumber.open(os.path.join(HERE, "pdfs/issue-987-test.pdf"))
page = pdf.pages[0]
assert page.extract_text() == "Big Te xt\nSmall Text"
assert page.extract_text(x_tolerance=4) == "Big Te xt\nSmallText"
assert page.extract_text(x_tolerance_ratio=0.15) == "Big Text\nSmall Text"
words = page.extract_words(x_tolerance_ratio=0.15)
assert "|".join(w["text"] for w in words) == "Big|Text|Small|Text"
def test_extract_words(self):
path = os.path.join(HERE, "pdfs/issue-192-example.pdf")
with pdfplumber.open(path) as pdf:
p = pdf.pages[0]
words = p.extract_words(vertical_ttb=False)
words_attr = p.extract_words(vertical_ttb=False, extra_attrs=["size"])
words_w_spaces = p.extract_words(vertical_ttb=False, keep_blank_chars=True)
words_rtl = p.extract_words(horizontal_ltr=False)
assert words[0]["text"] == "Agaaaaa:"
assert words[0]["direction"] == "ltr"
assert "size" not in words[0]
assert round(words_attr[0]["size"], 2) == 9.96
assert words_w_spaces[0]["text"] == "Agaaaaa: AAAA"
vertical = [w for w in words if w["upright"] == 0]
assert vertical[0]["text"] == "Aaaaaabag8"
assert vertical[0]["direction"] == "btt"
assert words_rtl[1]["text"] == "baaabaaA/AAA"
assert words_rtl[1]["direction"] == "rtl"
def test_extract_words_return_chars(self):
path = os.path.join(HERE, "pdfs/extra-attrs-example.pdf")
with pdfplumber.open(path) as pdf:
page = pdf.pages[0]
words = page.extract_words()
assert "chars" not in words[0]
words = page.extract_words(return_chars=True)
assert "chars" in words[0]
assert "".join(c["text"] for c in words[0]["chars"]) == words[0]["text"]
def test_text_rotation(self):
rotations = {
"0": ("ltr", "ttb"),
"-0": ("rtl", "ttb"),
"180": ("rtl", "btt"),
"-180": ("ltr", "btt"),
"90": ("ttb", "rtl"),
"-90": ("btt", "rtl"),
"270": ("btt", "ltr"),
"-270": ("ttb", "ltr"),
}
path = os.path.join(HERE, "pdfs/issue-848.pdf")
with pdfplumber.open(path) as pdf:
expected = utils.text.extract_text(pdf.pages[0].chars)
for i, (rotation, (char_dir, line_dir)) in enumerate(rotations.items()):
if i == 0:
continue
print(f"--- {rotation} ---")
p = pdf.pages[i].filter(lambda obj: obj.get("text") != " ")
output = utils.text.extract_text(
x_tolerance=2,
y_tolerance=2,
chars=p.chars,
char_dir=char_dir,
line_dir=line_dir,
char_dir_rotated=char_dir,
line_dir_rotated=line_dir,
char_dir_render="ltr",
line_dir_render="ttb",
)
assert output == expected
def test_text_rotation_layout(self):
rotations = {
"0": ("ltr", "ttb"),
"-0": ("rtl", "ttb"),
"180": ("rtl", "btt"),
"-180": ("ltr", "btt"),
"90": ("ttb", "rtl"),
"-90": ("btt", "rtl"),
"270": ("btt", "ltr"),
"-270": ("ttb", "ltr"),
}
def meets_expectations(text):
# Both texts should be found, and the first should appear before the second
a = re.search("opens with a news report", text)
b = re.search("having been transferred", text)
return a and b and (a.start() < b.start())
path = os.path.join(HERE, "pdfs/issue-848.pdf")
with pdfplumber.open(path) as pdf:
for i, (rotation, (char_dir, line_dir)) in enumerate(rotations.items()):
print(f"--- {rotation} ---")
p = pdf.pages[i].filter(lambda obj: obj.get("text") != " ")
output = p.extract_text(
layout=True,
x_tolerance=2,
y_tolerance=2,
char_dir=char_dir,
line_dir=line_dir,
char_dir_rotated=char_dir,
line_dir_rotated=line_dir,
char_dir_render="ltr",
line_dir_render="ttb",
y_density=14,
)
assert meets_expectations(output)
def test_text_render_directions(self):
path = os.path.join(HERE, "pdfs/line-char-render-example.pdf")
targets = {
("ttb", "ltr"): "first line\nsecond line\nthird line",
("ttb", "rtl"): "enil tsrif\nenil dnoces\nenil driht",
("btt", "ltr"): "third line\nsecond line\nfirst line",
("btt", "rtl"): "enil driht\nenil dnoces\nenil tsrif",
("ltr", "ttb"): "fst\nieh\nrci\nsor\ntnd\n d \nl l\nili\nnin\nene\n e ",
("ltr", "btt"): " s \nfet\nich\nroi\nsnr\ntdd\n \nlll\niii\nnnn\neee",
("rtl", "ttb"): "tsf\nhei\nicr\nros\ndnt\n d \nl l\nili\nnin\nene\n e ",
("rtl", "btt"): " s \ntef\nhci\nior\nrns\nddt\n \nlll\niii\nnnn\neee",
}
with pdfplumber.open(path) as pdf:
page = pdf.pages[0]
for (line_dir, char_dir), target in targets.items():
text = page.extract_text(
line_dir_render=line_dir, char_dir_render=char_dir
)
assert text == target
def test_invalid_directions(self):
path = os.path.join(HERE, "pdfs/line-char-render-example.pdf")
pdf = pdfplumber.open(path)
page = pdf.pages[0]
with pytest.raises(ValueError):
page.extract_text(line_dir="xxx", char_dir="ltr")
with pytest.raises(ValueError):
page.extract_text(line_dir="ttb", char_dir="a")
with pytest.raises(ValueError):
page.extract_text(line_dir="rtl", char_dir="ltr")
with pytest.raises(ValueError):
page.extract_text(line_dir="ttb", char_dir="btt")
with pytest.raises(ValueError):
page.extract_text(line_dir_rotated="ttb", char_dir="btt")
with pytest.raises(ValueError):
page.extract_text(line_dir_render="ttb", char_dir_render="btt")
pdf.close()
def test_extra_attrs(self):
path = os.path.join(HERE, "pdfs/extra-attrs-example.pdf")
with pdfplumber.open(path) as pdf:
page = pdf.pages[0]
assert page.extract_text() == "BlackRedArial"
assert (
page.extract_text(extra_attrs=["non_stroking_color"])
== "Black RedArial"
)
assert page.extract_text(extra_attrs=["fontname"]) == "BlackRed Arial"
assert (
page.extract_text(extra_attrs=["non_stroking_color", "fontname"])
== "Black Red Arial"
)
# Should not error
assert page.extract_text(
layout=True,
use_text_flow=True,
extra_attrs=["non_stroking_color", "fontname"],
)
def test_extract_words_punctuation(self):
path = os.path.join(HERE, "pdfs/test-punkt.pdf")
with pdfplumber.open(path) as pdf:
wordsA = pdf.pages[0].extract_words(split_at_punctuation=True)
wordsB = pdf.pages[0].extract_words(split_at_punctuation=False)
wordsC = pdf.pages[0].extract_words(
split_at_punctuation=r"!\"&'()*+,.:;<=>?@[]^`{|}~"
)
assert wordsA[0]["text"] == "https"
assert (
wordsB[0]["text"]
== "https://dell-research-harvard.github.io/HJDataset/"
)
assert wordsC[2]["text"] == "//dell-research-harvard"
wordsA = pdf.pages[1].extract_words(split_at_punctuation=True)
wordsB = pdf.pages[1].extract_words(split_at_punctuation=False)
wordsC = pdf.pages[1].extract_words(
split_at_punctuation=r"!\"&'()*+,.:;<=>?@[]^`{|}~"
)
assert len(wordsA) == 4
assert len(wordsB) == 2
assert len(wordsC) == 2
wordsA = pdf.pages[2].extract_words(split_at_punctuation=True)
wordsB = pdf.pages[2].extract_words(split_at_punctuation=False)
wordsC = pdf.pages[2].extract_words(
split_at_punctuation=r"!\"&'()*+,.:;<=>?@[]^`{|}~"
)
assert wordsA[1]["text"] == "["
assert wordsB[1]["text"] == "[2,"
assert wordsC[1]["text"] == "["
wordsA = pdf.pages[3].extract_words(split_at_punctuation=True)
wordsB = pdf.pages[3].extract_words(split_at_punctuation=False)
wordsC = pdf.pages[3].extract_words(
split_at_punctuation=r"!\"&'()*+,.:;<=>?@[]^`{|}~"
)
assert wordsA[2]["text"] == "al"
assert wordsB[2]["text"] == "al."
assert wordsC[2]["text"] == "al"
def test_extract_text_punctuation(self):
path = os.path.join(HERE, "pdfs/test-punkt.pdf")
with pdfplumber.open(path) as pdf:
text = pdf.pages[0].extract_text(
layout=True,
split_at_punctuation=True,
)
assert "https " in text
def test_text_flow(self):
path = os.path.join(HERE, "pdfs/federal-register-2020-17221.pdf")
def words_to_text(words):
grouped = groupby(words, key=itemgetter("top"))
lines = [" ".join(word["text"] for word in grp) for top, grp in grouped]
return "\n".join(lines)
with pdfplumber.open(path) as pdf:
p0 = pdf.pages[0]
using_flow = p0.extract_words(use_text_flow=True)
not_using_flow = p0.extract_words()
target_text = (
"The FAA proposes to\n"
"supersede Airworthiness Directive (AD)\n"
"2018–23–51, which applies to all The\n"
"Boeing Company Model 737–8 and 737–\n"
"9 (737 MAX) airplanes. Since AD 2018–\n"
)
assert target_text in words_to_text(using_flow)
assert target_text not in words_to_text(not_using_flow)
def test_text_flow_overlapping(self):
path = os.path.join(HERE, "pdfs/issue-912.pdf")
with pdfplumber.open(path) as pdf:
p0 = pdf.pages[0]
using_flow = p0.extract_text(use_text_flow=True, layout=True, x_tolerance=1)
not_using_flow = p0.extract_text(layout=True, x_tolerance=1)
assert re.search("2015 RICE PAYMENT 26406576 0 1207631 Cr", using_flow)
assert re.search("124644,06155766", using_flow) is None
assert re.search("124644,06155766", not_using_flow)
assert (
re.search("2015 RICE PAYMENT 26406576 0 1207631 Cr", not_using_flow) is None
)
def test_extract_text(self):
text = self.pdf.pages[0].extract_text()
goal_lines = [
"First Page Previous Page Next Page Last Page",
"Print",
"PDFill: PDF Drawing",
"You can open a PDF or create a blank PDF by PDFill.",
"Online Help",
"Here are the PDF drawings created by PDFill",
"Please save into a new PDF to see the effect!",
"Goto Page 2: Line Tool",
"Goto Page 3: Arrow Tool",
"Goto Page 4: Tool for Rectangle, Square and Rounded Corner",
"Goto Page 5: Tool for Circle, Ellipse, Arc, Pie",
"Goto Page 6: Tool for Basic Shapes",
"Goto Page 7: Tool for Curves",
"Here are the tools to change line width, style, arrow style and colors",
]
goal = "\n".join(goal_lines)
assert text == goal
text_simple = self.pdf.pages[0].extract_text_simple()
assert text_simple == goal
assert self.pdf.pages[0].crop((0, 0, 1, 1)).extract_text() == ""
def test_extract_text_blank(self):
assert utils.extract_text([]) == ""
def test_extract_text_layout(self):
target = (
open(os.path.join(HERE, "comparisons/scotus-transcript-p1.txt"))
.read()
.strip("\n")
)
page = self.pdf_scotus.pages[0]
text = page.extract_text(layout=True)
utils_text = utils.extract_text(
page.chars,
layout=True,
layout_width=page.width,
layout_height=page.height,
layout_bbox=page.bbox,
)
assert text == utils_text
assert text == target
def test_extract_text_layout_cropped(self):
target = (
open(os.path.join(HERE, "comparisons/scotus-transcript-p1-cropped.txt"))
.read()
.strip("\n")
)
p = self.pdf_scotus.pages[0]
cropped = p.crop((90, 70, p.width, 300))
text = cropped.extract_text(layout=True)
assert text == target
def test_extract_text_layout_widths(self):
p = self.pdf_scotus.pages[0]
text = p.extract_text(layout=True, layout_width_chars=75)
assert all(len(line) == 75 for line in text.splitlines())
with pytest.raises(ValueError):
p.extract_text(layout=True, layout_width=300, layout_width_chars=50)
with pytest.raises(ValueError):
p.extract_text(layout=True, layout_height=300, layout_height_chars=50)
def test_extract_text_nochars(self):
charless = self.pdf.pages[0].filter(lambda df: df["object_type"] != "char")
assert charless.extract_text() == ""
assert charless.extract_text(layout=True) == ""
def test_search_regex_compiled(self):
page = self.pdf_scotus.pages[0]
pat = re.compile(r"supreme\s+(\w+)", re.I)
results = page.search(pat)
assert results[0]["text"] == "SUPREME COURT"
assert results[0]["groups"] == ("COURT",)
assert results[1]["text"] == "Supreme Court"
assert results[1]["groups"] == ("Court",)
with pytest.raises(ValueError):
page.search(re.compile(r"x"), regex=False)
with pytest.raises(ValueError):
page.search(re.compile(r"x"), case=False)
def test_search_regex_uncompiled(self):
page = self.pdf_scotus.pages[0]
pat = r"supreme\s+(\w+)"
results = page.search(pat, case=False)
assert results[0]["text"] == "SUPREME COURT"
assert results[0]["groups"] == ("COURT",)
assert results[1]["text"] == "Supreme Court"
assert results[1]["groups"] == ("Court",)
def test_search_string(self):
page = self.pdf_scotus.pages[0]
results = page.search("SUPREME COURT", regex=False)
assert results[0]["text"] == "SUPREME COURT"
assert results[0]["groups"] == tuple()
results = page.search("supreme court", regex=False)
assert len(results) == 0
results = page.search("supreme court", regex=False, case=False)
assert len(results) == 2
results = page.search("supreme court", regex=True, case=False)
assert len(results) == 2
results = page.search(r"supreme\s+(\w+)", regex=False)
assert len(results) == 0
results = page.search(r"10 Tuesday", layout=False)
assert len(results) == 1
results = page.search(r"10 Tuesday", layout=True)
assert len(results) == 0
def test_extract_text_lines(self):
page = self.pdf_scotus.pages[0]
results = page.extract_text_lines()
assert len(results) == 28
assert "chars" in results[0]
assert results[0]["text"] == "Official - Subject to Final Review"
alt = page.extract_text_lines(layout=True, strip=False, return_chars=False)
assert "chars" not in alt[0]
assert (
alt[0]["text"]
== " Official - Subject to Final Review " # noqa: E501
)
assert results[10]["text"] == "10 Tuesday, January 13, 2009"
assert (
alt[10]["text"]
== " 10 Tuesday, January 13, 2009 " # noqa: E501
)
assert (
page.extract_text_lines(layout=True)[10]["text"]
== "10 Tuesday, January 13, 2009"
) # noqa: E501
def test_handle_empty_and_whitespace_search_results(self):
# via https://github.com/jsvine/pdfplumber/discussions/853
# The searches below should not raise errors but instead
# should return empty result-sets.
page = self.pdf_scotus.pages[0]
for regex in [True, False]:
results = page.search("\n", regex=regex)
assert len(results) == 0
assert len(page.search("(sdfsd)?")) == 0
assert len(page.search("")) == 0
def test_intersects_bbox(self):
objs = [
# Is same as bbox
{
"x0": 0,
"top": 0,
"x1": 20,
"bottom": 20,
},
# Inside bbox
{
"x0": 10,
"top": 10,
"x1": 15,
"bottom": 15,
},
# Overlaps bbox
{
"x0": 10,
"top": 10,
"x1": 30,
"bottom": 30,
},
# Touching on one side
{
"x0": 20,
"top": 0,
"x1": 40,
"bottom": 20,
},
# Touching on one corner
{
"x0": 20,
"top": 20,
"x1": 40,
"bottom": 40,
},
# Fully outside
{
"x0": 21,
"top": 21,
"x1": 40,
"bottom": 40,
},
]
bbox = utils.obj_to_bbox(objs[0])
assert utils.intersects_bbox(objs, bbox) == objs[:4]
assert utils.intersects_bbox(iter(objs), bbox) == objs[:4]
def test_merge_bboxes(self):
bboxes = [
(0, 10, 20, 20),
(10, 5, 10, 30),
]
merged = utils.merge_bboxes(bboxes)
assert merged == (0, 5, 20, 30)
merged = utils.merge_bboxes(iter(bboxes))
assert merged == (0, 5, 20, 30)
def test_resize_object(self):
obj = {
"x0": 5,
"x1": 10,
"top": 20,
"bottom": 30,
"width": 5,
"height": 10,
"doctop": 120,
"y0": 40,
"y1": 50,
}
assert utils.resize_object(obj, "x0", 0) == {
"x0": 0,
"x1": 10,
"top": 20,
"doctop": 120,
"bottom": 30,
"width": 10,
"height": 10,
"y0": 40,
"y1": 50,
}
assert utils.resize_object(obj, "x1", 50) == {
"x0": 5,
"x1": 50,
"top": 20,
"doctop": 120,
"bottom": 30,
"width": 45,
"height": 10,
"y0": 40,
"y1": 50,
}
assert utils.resize_object(obj, "top", 0) == {
"x0": 5,
"x1": 10,
"top": 0,
"doctop": 100,
"bottom": 30,
"height": 30,
"width": 5,
"y0": 40,
"y1": 70,
}
assert utils.resize_object(obj, "bottom", 40) == {
"x0": 5,
"x1": 10,
"top": 20,
"doctop": 120,
"bottom": 40,
"height": 20,
"width": 5,
"y0": 30,
"y1": 50,
}
def test_move_object(self):
a = {
"x0": 5,
"x1": 10,
"top": 20,
"bottom": 30,
"width": 5,
"height": 10,
"doctop": 120,
"y0": 40,
"y1": 50,
}
b = dict(a)
b["x0"] = 15
b["x1"] = 20
a_new = utils.move_object(a, "h", 10)
assert a_new == b
def test_snap_objects(self):
a = {
"x0": 5,
"x1": 10,
"top": 20,
"bottom": 30,
"width": 5,
"height": 10,
"doctop": 120,
"y0": 40,
"y1": 50,
}
b = dict(a)
b["x0"] = 6
b["x1"] = 11
c = dict(a)
c["x0"] = 7
c["x1"] = 12
a_new, b_new, c_new = utils.snap_objects([a, b, c], "x0", 1)
assert a_new == b_new == c_new
a_new, b_new, c_new = utils.snap_objects(iter([a, b, c]), "x0", 1)
assert a_new == b_new == c_new
def test_filter_edges(self):
with pytest.raises(ValueError):
utils.filter_edges([], "x")
def test_to_list(self):
objs = [
{
"x0": 0,
"top": 0,
"x1": 20,
"bottom": 20,
},
{
"x0": 10,
"top": 10,
"x1": 15,
"bottom": 15,
},
]
assert utils.to_list(objs) == objs
assert utils.to_list(iter(objs)) == objs
assert utils.to_list(tuple(objs)) == objs
assert utils.to_list((o for o in objs)) == objs
assert utils.to_list(pd.DataFrame(objs)) == objs