Update reparse test to test full org_rw.dump. This fails.
This commit is contained in:
parent
ef615feac5
commit
c6c372e111
22
tests/13-update-reparse-test.org
Normal file
22
tests/13-update-reparse-test.org
Normal file
@ -0,0 +1,22 @@
|
||||
#+TITLE: 13-Update reparse
|
||||
#+DESCRIPTION: Update-Reparse org file
|
||||
#+TODO: TODO(t) PAUSED(p) | DONE(d)
|
||||
|
||||
|
||||
* First level
|
||||
:PROPERTIES:
|
||||
:ID: 13-update-reparse-first-level-id
|
||||
:CREATED: [2020-01-01 Wed 01:01]
|
||||
:END:
|
||||
First level content
|
||||
|
||||
- A list of items ::
|
||||
- With a sublist
|
||||
|
||||
Something after the list.
|
||||
|
||||
** Second level
|
||||
:PROPERTIES:
|
||||
:ID: 13-update-reparse-second-level-id
|
||||
:END:
|
||||
Second level content
|
@ -1,4 +1,5 @@
|
||||
import os
|
||||
import tempfile
|
||||
import unittest
|
||||
from datetime import datetime as DT
|
||||
|
||||
@ -866,45 +867,44 @@ class TestSerde(unittest.TestCase):
|
||||
self.assertEqual(dumps(doc), orig)
|
||||
|
||||
def test_update_reparse(self):
|
||||
with open(os.path.join(DIR, "01-simple.org")) as f:
|
||||
with open(os.path.join(DIR, "13-update-reparse-test.org")) as f:
|
||||
doc = load(f)
|
||||
|
||||
expected_hl_contents = ''' :PROPERTIES:
|
||||
:ID: 13-update-reparse-first-level-id
|
||||
:CREATED: [2020-01-01 Wed 01:01]
|
||||
:END:
|
||||
First level content
|
||||
|
||||
- A list of items ::
|
||||
- With a sublist
|
||||
|
||||
Something after the list.
|
||||
'''
|
||||
|
||||
hl = doc.getTopHeadlines()[0]
|
||||
ex = HL(
|
||||
"First level",
|
||||
props=[
|
||||
("ID", "01-simple-first-level-id"),
|
||||
("CREATED", DT(2020, 1, 1, 1, 1)),
|
||||
],
|
||||
content=" First level content\n",
|
||||
children=[
|
||||
HL(
|
||||
"Second level",
|
||||
props=[("ID", "01-simple-second-level-id")],
|
||||
content="\n Second level content\n",
|
||||
children=[
|
||||
HL(
|
||||
"Third level",
|
||||
props=[("ID", "01-simple-third-level-id")],
|
||||
content="\n Third level content\n",
|
||||
)
|
||||
],
|
||||
)
|
||||
],
|
||||
)
|
||||
|
||||
# Ground check
|
||||
ex.assert_matches(self, hl)
|
||||
|
||||
# Update
|
||||
lines = list(doc.dump_headline(hl, recursive=False))
|
||||
assert lines[0].startswith('* ') # Title, skip it
|
||||
content = '\n'.join(lines[1:])
|
||||
hl.update_raw_contents(content)
|
||||
self.assertEqual(content, expected_hl_contents)
|
||||
|
||||
# Check after update
|
||||
ex.assert_matches(self, hl, accept_trailing_whitespace_changes=True)
|
||||
hl.update_raw_contents(content)
|
||||
self.assertEqual(content, expected_hl_contents)
|
||||
|
||||
# Check after dump and reload
|
||||
with tempfile.NamedTemporaryFile('wt') as f:
|
||||
save = org_rw.dumps(doc)
|
||||
f.write(save)
|
||||
f.flush()
|
||||
|
||||
with open(f.name, 'rt') as reader:
|
||||
reloaded = org_rw.load(reader)
|
||||
re_hl = reloaded.getTopHeadlines()[0]
|
||||
lines = list(doc.dump_headline(hl, recursive=False))
|
||||
assert lines[0].startswith('* ') # Title, skip it
|
||||
content = '\n'.join(lines[1:])
|
||||
self.assertEqual(content, expected_hl_contents)
|
||||
|
||||
def print_tree(tree, indentation=0, headline=None):
|
||||
for element in tree:
|
||||
|
Loading…
Reference in New Issue
Block a user