[lxml-dev] objectify factories

jholg at gmx.de jholg at gmx.de
Fri Aug 31 18:05:04 CEST 2007


Hi,

> Exactly. That's why I'm proposing to change that behaviour for the
> objectify.E
> factory. It should always annotate, just as everything else does.
> [...]
> >> __setattr__/_setElementValue. Maybe modify DataElement() instead of
> >> introducing PT(), then?
> >>
> >> +1 for having the same behaviour everywhere.
> > 

Patch attached:
- makes DataElement() behaviour consistent with new _setElementValue workings, using _typename(<value>) as pytype name, if not explicitly given
- makes objectify ElementMaker add pytype annotation
- fixes _setElementValue() to safely delAttributeFromNsName() for unregistered types
- adds some tests for that stuff

It does work except for these doctests for me:

TESTED VERSION: 2.0.alpha1-46212
    Python:            (2, 4, 4, 'final', 0)
    lxml.etree:        (2, 0, -199, 46212)
    libxml used:       (2, 6, 27)
    libxml compiled:   (2, 6, 27)
    libxslt used:      (1, 1, 20)
    libxslt compiled:  (1, 1, 20)

 758/758 (100.0%): Doctest: xpathxslt.txt                                                    
======================================================================
FAIL: Doctest: element_classes.txt
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/apps/prod//lib/python2.4/unittest.py", line 260, in run
    testMethod()
  File "/apps/prod//lib/python2.4/doctest.py", line 2157, in runTest
    raise self.failureException(self.format_failure(new.getvalue()))
AssertionError: Failed doctest test for element_classes.txt
  File "/data/pydev/hjoukl/LXML/lxml/src/lxml/tests/../../../doc/element_classes.txt", line 0

----------------------------------------------------------------------
File "/data/pydev/hjoukl/LXML/lxml/src/lxml/tests/../../../doc/element_classes.txt", line 347, in element_classes.txt
Failed example:
    print honk_element[0].honking
Expected:
    Traceback (most recent call last):
    ...
    AttributeError: 'lxml.etree._Element' object has no attribute 'honking'
Got:
    Traceback (most recent call last):
      File "/apps/prod//lib/python2.4/doctest.py", line 1248, in __run
        compileflags, 1) in test.globs
      File "<doctest element_classes.txt[66]>", line 1, in ?
        print honk_element[0].honking
    AttributeError: 'etree._Element' object has no attribute 'honking'

======================================================================
FAIL: Doctest: objectify.txt
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/apps/prod//lib/python2.4/unittest.py", line 260, in run
    testMethod()
  File "/apps/prod//lib/python2.4/doctest.py", line 2157, in runTest
    raise self.failureException(self.format_failure(new.getvalue()))
AssertionError: Failed doctest test for objectify.txt
  File "/data/pydev/hjoukl/LXML/lxml/src/lxml/tests/../../../doc/objectify.txt", line 0

----------------------------------------------------------------------
File "/data/pydev/hjoukl/LXML/lxml/src/lxml/tests/../../../doc/objectify.txt", line 283, in objectify.txt
Failed example:
    print etree.tostring(root, pretty_print=True)
Expected:
    <root>
      <a>5</a>
      <b>6.1</b>
      <c>true</c>
      <d tell="me">how</d>
    </root>
Got:
    <root xmlns:ns0="http://codespeak.net/lxml/objectify/pytype" ns0:pytype="TREE">
      <a xmlns:ns0="http://codespeak.net/lxml/objectify/pytype" ns0:pytype="int">5</a>
      <b ns0:pytype="float">6.1</b>
      <c ns0:pytype="bool">true</c>
      <d tell="me" ns0:pytype="str">how</d>
    </root>
----------------------------------------------------------------------
File "/data/pydev/hjoukl/LXML/lxml/src/lxml/tests/../../../doc/objectify.txt", line 302, in objectify.txt
Failed example:
    print etree.tostring(root, pretty_print=True)
Expected:
    <root>
      <title>The title</title>
      <type>5</type>
    </root>
Got:
    <root xmlns:ns0="http://codespeak.net/lxml/objectify/pytype" ns0:pytype="TREE">
      <title xmlns:ns0="http://codespeak.net/lxml/objectify/pytype" ns0:pytype="str">The title</title>
      <type ns0:pytype="int">5</type>
    </root>


----------------------------------------------------------------------
Ran 758 tests in 2.762s

FAILED (failures=2)
make: *** [test_inplace] Error 1

The first one seems to fail because of some change in element naming.

The others result from the now-added type information of the ElementMaker but I left them in because I'm not sure why the nsmap-"aggregation" does not work here (ElementMaker uses _DEFAULT_NSMAP) as expected.

Holger



-- 
Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen! 
Ideal für Modem und ISDN: http://www.gmx.net/de/go/smartsurfer
-------------- next part --------------
A non-text attachment was scrubbed...
Name: data_element_elementmaker.patch
Type: application/octet-stream
Size: 12271 bytes
Desc: not available
Url : http://codespeak.net/pipermail/lxml-dev/attachments/20070831/20e8ece1/attachment.obj 


More information about the lxml-dev mailing list