RE: [xml] Missing line numbers in error handling



Hi David,

While trying to expand the python/tests/tstLastError.py code to test 
validation and not just well-formedness, I'm finding a memory 
leak from 
the debugMemory call in tearDown.  Specifically, adding the 
following test:

     def test3(self):
         """Test a validation error: we get the last error only"""
         s = """<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";>
<html xmlns="http://www.w3.org/1999/xhtml"; xml:lang="en" lang="en">
<head>
     <title><!-- Insert your title here --></title>
</head>
<bodyBROKEN>
</bodyBROKEN>
</html>"""
         self.failUnlessXmlError(libxml2.readMemory,
                         (s,len(s),"dummy.xml",None,0),
                         libxml2.treeError,   # not sure what 
it should 
be yet
                         domain=libxml2.XML_FROM_PARSER,
                         code=libxml2.XML_ERR_TAG_NOT_FINISHED,
                         message='Premature end of data in 
tag x line 1\n',
                         level=libxml2.XML_ERR_FATAL,
                         file='dummy.xml',
                         line=3)


while I'm not expecting the test to run yet (as I haven't tweaked the 
expected exception yet), but I'm not expecting (note that the "FE" is 
printed by libxml (!?):

The FE is printed by python's unittest module.
It means 1 Failure and 1 Error.

C:\foo>python tstLastError.py
..FE
======================================================================
ERROR: Test a validation error: we get the last error only
----------------------------------------------------------------------
Traceback (most recent call last):
   File "tstLastError.py", line 15, in tearDown
     self.fail("Memory leak %d bytes" % (libxml2.debugMemory(1),))
   File "C:\Python23\lib\unittest.py", line 270, in fail
     raise self.failureException, msg
AssertionError: Memory leak 4415 bytes

======================================================================
FAIL: Test a validation error: we get the last error only
----------------------------------------------------------------------
Traceback (most recent call last):
   File "tstLastError.py", line 90, in test3
     line=3)
   File "tstLastError.py", line 44, in failUnlessXmlError
     self.fail("exception %s should have been raised" % exc)
   File "C:\Python23\lib\unittest.py", line 270, in fail
     raise self.failureException, msg
AssertionError: exception libxml2.treeError should have been raised

----------------------------------------------------------------------

1) Can others replicate?  (it's running against the latest windows 
binary distribution, while the test is from the latest CVS 
snapshot, if 
that makes a difference).

With libxml2-python-2.6.6.win32-py2.3.exe on windows, 
I get the same as William on Linux:

~>python tstLastError.py

..F
======================================================================
FAIL: Test a validation error: we get the last error only
----------------------------------------------------------------------
Traceback (most recent call last):
  File "mytstLastError.py", line 91, in test3
    line=3)
  File "mytstLastError.py", line 38, in failUnlessXmlError
    self.failUnlessEqual(code,e.code())
  File "c:\soft\python23\lib\unittest.py", line 302, in failUnlessEqual
    raise self.failureException, \
AssertionError: 77 != 4

----------------------------------------------------------------------
Ran 3 tests in 0.350s

FAILED (failures=1)

2) Suggestions for what to fix?

Upgrade? What version are you running?

BTW, note that the python bindings for structured error handling
are not fully finished (the structured error callbacks are not 
implemented yet, only the last error is available).

-sbi




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]