# HG changeset patch
# User Mihai Ibanescu <https://issues.rpath.com/>
# Date 1251409747 14400
# Node ID 07b5cbb54b6fbde72524bcad15c9b73c93fbfb8a
# Parent  ad42f4b755594a874edca453e3520d77da869917
Tests for valueof handling

diff -r ad42f4b75559 -r 07b5cbb54b6f tests/test.py
--- a/tests/test.py	Thu Aug 27 16:34:53 2009 -0400
+++ b/tests/test.py	Thu Aug 27 17:49:07 2009 -0400
@@ -67,6 +67,30 @@
 [u'value 2 1', u'group1 2', u'group2 2', u'value 2 2']
 """)
 
+    def test_valueof(self):
+        cmdTempl = 'python generateDS.py --no-dates --silence --member-specs=list -f -o tests/%s_sup.py -s tests/%s_sub.py --super=%s_sup tests/%s.xsd'
+        t_ = 'valueof'
+        cmd = cmdTempl % (t_, t_, t_, t_)
+        result, _ = self.execute(cmd, cwd='..')
+
+        # load the XML, and verify the proper data was loaded
+        cmdTempl = '''python -c "import %s_sub; obj = %s_sub.parse('%s.xml'); children = obj.get_child(); print [ (x.get_name(), x.getValueOf_()) for x in children ]"'''
+        cmd = cmdTempl % (t_, t_, t_)
+        result, _ = self.execute(cmd)
+        self.failUnlessEqual(result, """\
+[(u'child1', u'value1'), (u'child1', u'value2')]
+""")
+
+        # Now try to create a node, make sure the value of valueOf_ is passed
+        # in
+        cmdTempl = '''python -c "import %s_sub; node = %s_sub.childSub.factory(name='child1', valueOf_ = 'value1'); print (node.get_name(), node.getValueOf_())"'''
+        cmd = cmdTempl % (t_, t_)
+        result, _ = self.execute(cmd)
+        self.failUnlessEqual(result, """\
+('child1', 'value1')
+""")
+
+
 def check_result(result):
     flag1 = 0
     flag2 = 0
diff -r ad42f4b75559 -r 07b5cbb54b6f tests/valueof.xml
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/valueof.xml	Thu Aug 27 17:49:07 2009 -0400
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<root xmlns="http://example.com/schema2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="groups.xsd">
+    <child name="child1">value1</child>
+    <child name="child1">value2</child>
+</root>
diff -r ad42f4b75559 -r 07b5cbb54b6f tests/valueof.xsd
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/valueof.xsd	Thu Aug 27 17:49:07 2009 -0400
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+    xmlns="http://example.com/schema2"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://www.w3.org/2001/XMLSchema.xsd"
+    targetNamespace="http://example.com/schema2"
+    elementFormDefault="qualified" attributeFormDefault="unqualified">
+  <xsd:element name="root">
+    <xsd:complexType>
+      <xsd:sequence>
+        <xsd:element name="child" minOccurs="1" maxOccurs="unbounded">
+          <xsd:complexType>
+            <xsd:simpleContent>
+              <xsd:extension base="xsd:string">
+                <xsd:attribute name="name" type="xsd:string" use="required" />
+              </xsd:extension>
+            </xsd:simpleContent>
+          </xsd:complexType>
+        </xsd:element>
+      </xsd:sequence>
+    </xsd:complexType>
+  </xsd:element>
+</xsd:schema>
