Skip to content

Commit

Permalink
updated new ParseError and fixed tests accordingly
Browse files Browse the repository at this point in the history
  • Loading branch information
proycon committed Mar 28, 2017
1 parent fc7d379 commit f011b20
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
7 changes: 5 additions & 2 deletions formats/folia.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,10 @@ class MalformedXMLError(Exception):
pass

class ParseError(Exception):
pass
def __init__(self, msg, cause=None):
self.cause = cause
Exception.__init__(self, msg)


class ModeError(Exception):
pass
Expand Down Expand Up @@ -2410,7 +2413,7 @@ def parsexml(Class, node, doc, **kwargs): #pylint: disable=bad-classmethod-argum
except ParseError as e:
raise #just re-raise deepest parseError
except Exception as e:
raise ParseError("FoLiA exception in handling of <" + subnode.tag[len(NSFOLIA)+2:] + "> @ line " + str(subnode.sourceline) + ": [" + e.__class__.__name__ + "] " + str(e)) #Python 3 will preserve full original traceback, Python 2 does not
raise ParseError("FoLiA exception in handling of <" + subnode.tag[len(NSFOLIA)+2:] + "> @ line " + str(subnode.sourceline) + ": [" + e.__class__.__name__ + "] " + str(e), cause=e) #Python 3 will preserve full original traceback, Python 2 does not, original cause is explicitly passed to ParseError anyway
if e is not None:
args.append(e)
if (Class.TEXTCONTAINER or Class.PHONCONTAINER) and subnode.tail:
Expand Down
16 changes: 12 additions & 4 deletions tests/folia.py
Original file line number Diff line number Diff line change
Expand Up @@ -1072,7 +1072,9 @@ def test102b_declarations(self):
<gap class="X" set="extended-gap-set" />
</text>
</FoLiA>""".format(version=folia.FOLIAVERSION, generator='pynlpl.formats.folia-v' + folia.LIBVERSION)
self.assertRaises( ValueError, folia.Document, string=xml)
with self.assertRaises( folia.ParseError) as cm:
folia.Document(string=xml)
self.assertEqual(cm.exception.cause.__class__, ValueError)


def test102c_declarations(self):
Expand Down Expand Up @@ -1109,7 +1111,9 @@ def test102d1_declarations(self):
<gap class="Y" />
</text>
</FoLiA>""".format(version=folia.FOLIAVERSION, generator='pynlpl.formats.folia-v' + folia.LIBVERSION)
self.assertRaises(ValueError, folia.Document, string=xml )
with self.assertRaises( folia.ParseError) as cm:
folia.Document(string=xml)
self.assertEqual(cm.exception.cause.__class__, ValueError)



Expand All @@ -1130,7 +1134,9 @@ def test102d2_declarations(self):
<gap class="Y" set="gip-set"/>
</text>
</FoLiA>""".format(version=folia.FOLIAVERSION, generator='pynlpl.formats.folia-v' + folia.LIBVERSION)
self.assertRaises(ValueError, folia.Document, string=xml )
with self.assertRaises( folia.ParseError) as cm:
folia.Document(string=xml)
self.assertEqual(cm.exception.cause.__class__, ValueError)

def test102d3_declarations(self):
"""Sanity Check - Declarations - Ignore Duplicates"""
Expand Down Expand Up @@ -1164,7 +1170,9 @@ def test102e_declarations(self):
<gap class="X" set="extended-gap-set" />
</text>
</FoLiA>""".format(version=folia.FOLIAVERSION, generator='pynlpl.formats.folia-v' + folia.LIBVERSION)
self.assertRaises( ValueError, folia.Document, string=xml)
with self.assertRaises( folia.ParseError) as cm:
folia.Document(string=xml)
self.assertEqual(cm.exception.cause.__class__, ValueError)

def test102f_declarations(self):
"""Sanity Check - Declarations - Declaration not needed"""
Expand Down

0 comments on commit f011b20

Please sign in to comment.