[Erp5-report] r39633 nicolas - /erp5/trunk/utils/xml_marshaller/src/xml_marshaller/
nobody at svn.erp5.org
nobody at svn.erp5.org
Thu Oct 28 18:27:07 CEST 2010
Author: nicolas
Date: Thu Oct 28 18:27:02 2010
New Revision: 39633
URL: http://svn.erp5.org?rev=39633&view=rev
Log:
Tests are moved to dedicated module
Modified:
erp5/trunk/utils/xml_marshaller/src/xml_marshaller/xml_marshaller.py
Modified: erp5/trunk/utils/xml_marshaller/src/xml_marshaller/xml_marshaller.py
URL: http://svn.erp5.org/erp5/trunk/utils/xml_marshaller/src/xml_marshaller/xml_marshaller.py?rev=39633&r1=39632&r2=39633&view=diff
==============================================================================
--- erp5/trunk/utils/xml_marshaller/src/xml_marshaller/xml_marshaller.py [utf8] (original)
+++ erp5/trunk/utils/xml_marshaller/src/xml_marshaller/xml_marshaller.py [utf8] Thu Oct 28 18:27:02 2010
@@ -610,113 +610,3 @@ loads = _um.loads
load_tree = _um.load_tree
del _m, _um, _m_ns
-
-def test(load, loads, dump, dumps, test_values,
- do_assert=1):
- # Try all the above bits of data
- for item in test_values:
- s = dumps(item)
- print s
- output = loads(s)
- # Try it from a file
- file = StringIO()
- dump(item, file)
- file.seek(0)
- output2 = load(file)
- if do_assert:
- assert item == output, '%r %r' % (item, output)
- assert item == output2 , '%r %r' % (item, output2)
- assert output == output2, '%r %r' % (output, output2)
-
-
-# Classes used in the test suite
-class _A:
- def __repr__(self):
- return '<A instance>'
-class _B(object):
- def __repr__(self):
- return '<B instance>'
-class _C(object):
- def __init__(self, attr1, attr2=None):
- self.attr1 = attr1
- self.attr2 = attr2
- def __getinitargs__(self):
- return (self.attr1, )
- def __repr__(self):
- return '<C instance>'
-
-def runtests(namespace_uri=None):
- print "Testing XML marshalling..."
-
- L = [None, 1, pow(2, 123L), 19.72, 1+5j,
- "here is a string & a <fake tag>",
- (1, 2, 3),
- ['alpha', 'beta', 'gamma'],
- {'key': 'value', 1: 2},
- 'éàù^ç'.decode('utf-8'),
- set(('a', 1,)),
- True,
- False
- ]
- if namespace_uri:
- test(load, loads, dump_ns, dumps_ns, L)
- test(load, loads, dump, dumps, L)
-
- instance = _A() ; instance.subobject = _B()
- instance.subobject.list=[None, 1, pow(2, 123L), 19.72, 1+5j,
- "here is a string & a <fake tag>"]
- instance.self = instance
- L = [instance]
-
- if namespace_uri:
- test(load, loads, dump_ns, dumps_ns, L, do_assert=0)
- test(load, loads, dump, dumps, L, do_assert=0)
-
- recursive_list = [None, 1, pow(3, 65L), {1: 'spam', 2: 'eggs'},
- '<fake tag>', 1+5j]
- recursive_list.append(recursive_list)
- if namespace_uri:
- test(load, loads, dump_ns, dumps_ns, [recursive_list], do_assert=0)
- test(load, loads, dump, dumps, [recursive_list], do_assert=0)
-
- # Try unmarshalling XML with extra harmless whitespace (as if it was
- # pretty-printed)
- output = loads("""<?xml version="1.0"?>
-<marshal>
- <tuple>
- <float> 1.0 </float>
- <string>abc</string>
- <list id="i2" />
- </tuple>
-</marshal>""")
- assert output == (1.0, 'abc', [])
-
- output = loads("""<?xml version="1.0"?>
-<marshal:marshal xmlns:marshal="http://www.erp5.org/namespaces/marshaller">
- <marshal:tuple>
- <marshal:float> 1.0 </marshal:float>
- <marshal:string>abc</marshal:string>
- <marshal:list id="i2" />
- </marshal:tuple>
-</marshal:marshal>""")
- assert output == (1.0, 'abc', [])
-
- c_instance = _C('value1', attr2='value2')
- c_instance.attr3 = 'value3'
- nested_instance = _C('somevalue', 'someother')
- nested_instance.attr3 = "stillanother"
- c_instance.nested_instance = nested_instance
- c_marshalled = dumps(c_instance)
- c_unmarshalled = loads(c_marshalled)
- assert c_unmarshalled.attr3 == c_instance.attr3
- assert c_unmarshalled.attr2 == c_instance.attr2
- assert c_unmarshalled.attr1 == c_instance.attr1
- assert c_unmarshalled.__class__ == _C
- assert c_unmarshalled.nested_instance.__class__ == _C
- assert c_unmarshalled.nested_instance.attr1 == nested_instance.attr1
- assert c_unmarshalled.nested_instance.attr2 == nested_instance.attr2
- assert c_unmarshalled.nested_instance.attr3 == nested_instance.attr3
-
-if __name__ == '__main__':
- runtests()
- runtests(namespace_uri='http://www.erp5.org/namespaces/marshaller')
More information about the Erp5-report
mailing list