This repository has been archived by the owner on Oct 4, 2022. It is now read-only.
forked from pabigot/pyxb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
binding/datatypes: detect empty xml construction of scalar values
The Python default value was inappropriately used for simple data types when constructed from an empty XML element (i.e. an empty string value). Detect this situation and reject unless the value is explicitly nil. Closes pabigot#71
- Loading branch information
Showing
6 changed files
with
171 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# -*- coding: utf-8 -*- | ||
import logging | ||
if __name__ == '__main__': | ||
logging.basicConfig() | ||
_log = logging.getLogger(__name__) | ||
import pyxb.binding.generate | ||
import pyxb.utils.domutils | ||
import pyxb.binding.datatypes as xs | ||
import datetime; | ||
from xml.dom import Node | ||
|
||
import os.path | ||
xsd='''<?xml version="1.0" encoding="utf-8"?> | ||
<xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"> | ||
<xs:element name="b" type="xs:boolean"/> | ||
<xs:element name="nNI" type="xs:nonNegativeInteger"/> | ||
<xs:element name="int" type="xs:int"/> | ||
<xs:element name="time" type="xs:time"/> | ||
<xs:element name="duration" type="xs:duration"/> | ||
</xs:schema> | ||
''' | ||
|
||
code = pyxb.binding.generate.GeneratePython(schema_text=xsd) | ||
#open('code.py', 'w').write(code) | ||
#print code | ||
|
||
rv = compile(code, 'test', 'exec') | ||
eval(rv) | ||
|
||
from pyxb.exceptions_ import * | ||
|
||
import unittest | ||
|
||
class TestIssue0071 (unittest.TestCase): | ||
def testNonNegativeInteger (self): | ||
self.assertEqual(0, xs.nonNegativeInteger()); | ||
self.assertEqual(0, CreateFromDocument(six.u('<nNI>0</nNI>'))); | ||
self.assertRaises(SimpleTypeValueError, CreateFromDocument, six.u('<nNI/>')); | ||
|
||
def testBoolean (self): | ||
self.assertEqual(0, xs.boolean()); | ||
self.assertEqual(0, CreateFromDocument(six.u('<b>0</b>'))); | ||
self.assertRaises(SimpleTypeValueError, CreateFromDocument, six.u('<b/>')); | ||
|
||
def testInt (self): | ||
self.assertEqual(0, xs.int()); | ||
self.assertEqual(0, CreateFromDocument(six.u('<int>0</int>'))); | ||
self.assertRaises(SimpleTypeValueError, CreateFromDocument, six.u('<int/>')); | ||
|
||
def testTime (self): | ||
self.assertEqual(datetime.time(), xs.time()); | ||
self.assertEqual(datetime.time(), CreateFromDocument(six.u('<time>00:00:00</time>'))); | ||
self.assertRaises(SimpleTypeValueError, CreateFromDocument, six.u('<time/>')); | ||
|
||
def testDuration (self): | ||
self.assertEqual(datetime.timedelta(), xs.duration()); | ||
self.assertEqual(datetime.timedelta(), CreateFromDocument(six.u('<duration>P0D</duration>'))); | ||
self.assertRaises(SimpleTypeValueError, CreateFromDocument, six.u('<duration/>')); | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |