forked from kenkeiras/org-rw
Improve dump checks debugging, and enable them by default.
This commit is contained in:
parent
2346494268
commit
1c0ecbf8c6
@ -1,6 +1,8 @@
|
|||||||
import collections
|
import collections
|
||||||
|
import difflib
|
||||||
import logging
|
import logging
|
||||||
import re
|
import re
|
||||||
|
import sys
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from typing import List, Tuple
|
from typing import List, Tuple
|
||||||
|
|
||||||
@ -862,15 +864,23 @@ class OrgDomReader:
|
|||||||
raise NotImplementedError("{}: ‘{}’".format(linenum, line))
|
raise NotImplementedError("{}: ‘{}’".format(linenum, line))
|
||||||
|
|
||||||
|
|
||||||
def loads(s, environment=BASE_ENVIRONMENT, extra_cautious=False):
|
def loads(s, environment=BASE_ENVIRONMENT, extra_cautious=True):
|
||||||
doc = OrgDomReader()
|
doc = OrgDomReader()
|
||||||
doc.read(s, environment)
|
doc.read(s, environment)
|
||||||
dom = doc.finalize()
|
dom = doc.finalize()
|
||||||
if extra_cautious: # Check that all options can be properly re-serialized
|
if extra_cautious: # Check that all options can be properly re-serialized
|
||||||
if dumps(dom) != s:
|
after_dump = dumps(dom)
|
||||||
raise NotImplementedError(
|
if after_dump != s:
|
||||||
"Error re-serializing, file uses something not implemented"
|
diff = list(
|
||||||
|
difflib.Differ().compare(
|
||||||
|
s.splitlines(keepends=True), after_dump.splitlines(keepends=True)
|
||||||
)
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
sys.stderr.writelines(diff)
|
||||||
|
# print("---\n" + after_dump + "\n---")
|
||||||
|
|
||||||
|
raise Exception("Difference found between existing version and dumped one")
|
||||||
return dom
|
return dom
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user