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
|
'''
Tests for rich formatting: tables etc.
'''
from .. import load, loads
from ..extra import Table
import pytest
def test_table() -> None:
root = loads('''
| | | |
| | "heading" | |
| | | |
|-------+-----------+-----|
| reiwf | fef | |
|-------+-----------+-----|
|-------+-----------+-----|
| aba | caba | 123 |
| yeah | | X |
|------------------------+-------|
| when | count |
| datetime | int |
|------------------------+-------|
| | -1 |
| [2020-11-05 Thu 23:44] | |
| [2020-11-06 Fri 01:00] | 1 |
|------------------------+-------|
some irrelevant text
| simple |
|--------|
| value1 |
| value2 |
''')
[gap1, t1, gap2, t2, gap3, t3, gap4] = root.body_rich
t1 = Table(root._lines[1:10])
t2 = Table(root._lines[11:19])
t3 = Table(root._lines[22:26])
assert ilen(t1.blocks) == 4
assert list(t1.blocks)[2] == []
assert ilen(t1.rows) == 6
with pytest.raises(RuntimeError):
list(t1.as_dicts) # not sure what should it be
assert ilen(t2.blocks) == 2
assert ilen(t2.rows) == 5
assert list(t2.rows)[3] == ['[2020-11-05 Thu 23:44]', '']
assert ilen(t3.blocks) == 2
assert list(t3.rows) == [['simple'], ['value1'], ['value2']]
assert t3.as_dicts.columns == ['simple']
assert list(t3.as_dicts) == [{'simple': 'value1'}, {'simple': 'value2'}]
def test_table_2() -> None:
root = loads('''
* item
#+tblname: something
| date | value | comment |
|----------------------+-------+-------------------------------|
| 14.04.17 | 11 | aaaa |
| May 26 2017 08:00 | 12 | what + about + pluses? |
| May 26 09:00 - 10:00 | 13 | time is |
some comment
#+BEGIN_SRC python :var fname="plot.png" :var table=something :results file
fig.savefig(fname)
return fname
#+END_SRC
#+RESULTS:
[[file:plot.png]]
''')
[_, t, _] = root.children[0].body_rich
assert ilen(t.as_dicts) == 3
def ilen(x) -> int:
return len(list(x))
|