def test_base64_binary_constructor(self): self.check_value('xs:base64Binary(())', []) self.check_value('xs:base64Binary("ODQ=")', b'ODQ=') self.check_value('xs:base64Binary(xs:base64Binary("ODQ="))', b'ODQ=') self.check_value('xs:base64Binary("YWJjZWZnaGk=")', b'YWJjZWZnaGk=') self.wrong_value('xs:base64Binary("xyz")') self.wrong_value('xs:base64Binary("\u0411")') self.wrong_type('xs:base64Binary(1e2)') self.wrong_type('xs:base64Binary(1.1)') root = self.etree.XML('<root a="YWJjZWZnaGk="/>') context = XPathContext(root) self.check_value('xs:base64Binary(@a)', b'YWJjZWZnaGk=', context=context) context.item = UntypedAtomic('YWJjZWZnaGk=') self.check_value('xs:base64Binary(.)', b'YWJjZWZnaGk=', context=context) context.item = b'abcefghi' # Don't change, it can be an encoded value. self.check_value('xs:base64Binary(.)', b'abcefghi', context=context) context.item = b'YWJjZWZnaGlq' self.check_value('xs:base64Binary(.)', b'YWJjZWZnaGlq', context=context)
def test_xmlschema_proxy(self): context = XPathContext(root=self.etree.XML( '<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"/>')) self.wrong_syntax("schema-element(*)") self.wrong_name("schema-element(nil)") self.wrong_name("schema-element(xs:string)") self.check_value("schema-element(xs:complexType)", MissingContextError) self.check_value("self::schema-element(xs:complexType)", NameError, context) self.check_value("self::schema-element(xs:schema)", [context.item], context) self.check_tree("schema-element(xs:group)", '(schema-element (: (xs) (group)))') context.item = AttributeNode(XML_LANG, 'en') self.wrong_syntax("schema-attribute(*)") self.wrong_name("schema-attribute(nil)") self.wrong_name("schema-attribute(xs:string)") self.check_value("schema-attribute(xml:lang)", MissingContextError) self.check_value("schema-attribute(xml:lang)", NameError, context) self.check_value("self::schema-attribute(xml:lang)", [context.item], context) self.check_tree("schema-attribute(xsi:schemaLocation)", '(schema-attribute (: (xsi) (schemaLocation)))') token = self.parser.parse("self::schema-attribute(xml:lang)") context.item = AttributeNode(XML_LANG, 'en') context.axis = 'attribute' self.assertEqual(list(token.select(context)), [context.item])
def test_datetime_constructor(self): tz1 = Timezone(datetime.timedelta(hours=5, minutes=24)) self.check_value('xs:dateTime(())', []) self.check_value('xs:dateTime("1969-07-20T20:18:00")', DateTime10(1969, 7, 20, 20, 18)) self.check_value( 'xs:dateTime(xs:untypedAtomic("1969-07-20T20:18:00"))', DateTime10(1969, 7, 20, 20, 18)) self.check_value( 'xs:dateTime("2000-05-10T21:30:00+05:24")', datetime.datetime(2000, 5, 10, hour=21, minute=30, tzinfo=tz1)) self.check_value('xs:dateTime("1999-12-31T24:00:00")', datetime.datetime(2000, 1, 1, 0, 0)) self.check_value('xs:dateTime(xs:date("1969-07-20"))', DateTime10(1969, 7, 20)) self.check_value('xs:dateTime(xs:date("1969-07-20"))', DateTime10) with self.assertRaises(AssertionError): self.check_value('xs:dateTime(xs:date("1969-07-20"))', DateTime) self.parser._xsd_version = '1.1' try: self.check_value('xs:dateTime(xs:date("1969-07-20"))', DateTime(1969, 7, 20)) self.check_value('xs:dateTime(xs:date("1969-07-20"))', DateTime) finally: self.parser._xsd_version = '1.0' self.wrong_value('xs:dateTime("2000-05-10t21:30:00+05:24")') self.wrong_value('xs:dateTime("2000-5-10T21:30:00+05:24")') self.wrong_value('xs:dateTime("2000-05-10T21:3:00+05:24")') self.wrong_value('xs:dateTime("2000-05-10T21:13:0+05:24")') self.wrong_value('xs:dateTime("2000-05-10T21:13:0")') self.check_value('xs:dateTime("-25252734927766554-12-31T12:00:00")', OverflowError) self.wrong_type('xs:dateTime(50)', 'FORG0006', '1st argument has an invalid type') self.wrong_type('xs:dateTime("2000-05-10T21:30:00", "+05:24")', 'XPST0017') root = self.etree.XML('<root a="1969-07-20T20:18:00"/>') context = XPathContext(root) self.check_value('xs:dateTime(@a)', DateTime10(1969, 7, 20, 20, 18), context=context) context.item = AttributeNode('a', str(DateTime10(1969, 7, 20, 20, 18))) self.check_value('xs:dateTime(.)', DateTime10(1969, 7, 20, 20, 18), context=context) context.item = AttributeNode('a', 'true') self.check_value('xs:dateTime(.)', ValueError, context=context) context.item = DateTime10(1969, 7, 20, 20, 18) self.check_value('xs:dateTime(.)', DateTime10(1969, 7, 20, 20, 18), context=context)
def test_date_constructor(self): tz = Timezone(datetime.timedelta(hours=-14, minutes=0)) self.check_value('xs:date("2017-01-19")', datetime.datetime(2017, 1, 19)) self.check_value('xs:date(xs:untypedAtomic("2017-01-19"))', datetime.datetime(2017, 1, 19)) self.check_value('xs:date("2011-11-11-14:00")', datetime.datetime(2011, 11, 11, tzinfo=tz)) self.check_value('xs:date(xs:dateTime("1969-07-20T20:18:00"))', Date10(1969, 7, 20)) self.wrong_value('xs:date("2011-11-11-14:01")') self.wrong_value('xs:date("11-11-11")') self.check_value('xs:date(())', []) root = self.etree.XML('<root a="2017-01-19"/>') context = XPathContext(root) self.check_value('xs:date(@a)', Date10(2017, 1, 19), context=context) class DummyXsdDateType(xpath_test_class.DummyXsdType): def is_simple(self): return True def decode(self, obj, *args, **kwargs): return Date10.fromstring(obj) def validate(self, obj, *args, **kwargs): if not isinstance(obj, Date10): raise TypeError() context.item = AttributeNode('a', 'true', xsd_type=DummyXsdDateType()) self.check_value('xs:date(.)', TypeError, context=context) context.item = AttributeNode('a', str(Date10(2017, 1, 19))) self.check_value('xs:date(.)', Date10(2017, 1, 19), context=context) context.item = AttributeNode('a', 'true') self.check_value('xs:date(.)', ValueError, context=context) root = self.etree.XML("<root>2017-10-02</root>") context = XPathContext(root) self.check_value('xs:date(.)', Date10(2017, 10, 2), context=context) root = self.etree.XML("<root>2017<a>-10-02</a></root>") context = XPathContext(root) self.check_value('xs:date(.)', Date10(2017, 10, 2), context=context) context = XPathContext(root, item=Date10(2017, 10, 2)) self.check_value('xs:date(.)', Date10(2017, 10, 2), context=context)
def test_iter_following(self): root = ElementTree.XML( '<A a="1"><B1><C1/></B1><B2/><B3><C1/></B3><B4/><B5/></A>') context = XPathContext(root) self.assertListEqual(list(context.iter_followings()), []) context = XPathContext(root) context.item = context.root.attributes[0] self.assertListEqual(list(context.iter_followings()), []) context = XPathContext(root, item=root[2]) self.assertListEqual(list(e.elem for e in context.iter_followings()), list(root[3:])) context = XPathContext(root, item=root[1]) result = [root[2], root[2][0], root[3], root[4]] self.assertListEqual(list(e.elem for e in context.iter_followings()), result) with patch.object(DummyXsdType(), 'has_mixed_content', return_value=True) as xsd_type: context = XPathContext(root, item=root[1]) context.root[1].xsd_type = xsd_type self.assertListEqual( list(e.elem for e in context.iter_followings()), result)
def test_gregorian_month_day_constructor(self): tz = Timezone(datetime.timedelta(hours=-14, minutes=0)) self.check_value('xs:gMonthDay("--07-02")', datetime.datetime(2000, 7, 2)) self.check_value('xs:gMonthDay(xs:untypedAtomic("--07-02"))', datetime.datetime(2000, 7, 2)) self.check_value('xs:gMonthDay("--07-02-14:00")', datetime.datetime(2000, 7, 2, tzinfo=tz)) self.check_value('xs:gMonthDay(xs:dateTime("1969-07-20T20:18:00"))', GregorianMonthDay(7, 20)) self.wrong_value('xs:gMonthDay("--7-02")') self.wrong_value('xs:gMonthDay("-07-02")') self.wrong_value('xs:gMonthDay("--07-32")') root = self.etree.XML('<root a="--05-20"/>') context = XPathContext(root) self.check_value('xs:gMonthDay(@a)', GregorianMonthDay(5, 20), context=context) context.item = GregorianMonthDay(1, 15) self.check_value('xs:gMonthDay(.)', GregorianMonthDay(1, 15), context=context)
def test_duration_constructor(self): self.check_value('xs:duration("P3Y5M1D")', (41, 86400)) self.check_value('xs:duration(xs:untypedAtomic("P3Y5M1D"))', (41, 86400)) self.check_value('xs:duration("P3Y5M1DT1H")', (41, 90000)) self.check_value('xs:duration("P3Y5M1DT1H3M2.01S")', (41, Decimal('90182.01'))) self.check_value('xs:untypedAtomic("P3Y5M1D") castable as xs:duration', True) self.check_value('"P8192912991912Y" castable as xs:duration', False) self.wrong_value('xs:duration("P3Y5M1X")') self.assertRaises(ValueError, self.parser.parse, 'xs:duration(1)') root = self.etree.XML('<root a="P1Y5M"/>') context = XPathContext(root) self.check_value('xs:duration(@a)', Duration(months=17), context=context) context.item = Duration(months=12, seconds=86400) self.check_value('xs:duration(.)', Duration(12, 86400), context=context) root = self.etree.XML('<root><a>P1Y5M</a></root>') context = XPathContext(root) self.check_value('xs:duration(.)', Duration(months=17), context=context)
def test_iter_children_or_self(self): doc = ElementTree.ElementTree(self.root) context = XPathContext(doc) self.assertIsInstance(context.root, DocumentNode) self.assertIsInstance(context.root[0], ElementNode) self.assertListEqual( list(e.elem for e in context.iter_children_or_self()), [self.root]) context.item = context.root[0] # root element self.assertListEqual(list(context.iter_children_or_self()), [context.root[0].children[0]]) context.item = context.root # document node self.assertListEqual( list(e.elem for e in context.iter_children_or_self()), [self.root])
def test_day_time_duration_constructor(self): self.check_value('xs:dayTimeDuration("-P2DT15H")', DayTimeDuration(seconds=-226800)) self.check_value('xs:dayTimeDuration(xs:duration("-P2DT15H"))', DayTimeDuration(seconds=-226800)) self.check_value('xs:dayTimeDuration("PT240H")', DayTimeDuration.fromstring("P10D")) self.check_value('xs:dayTimeDuration("P365D")', DayTimeDuration.fromstring("P365D")) self.check_value('xs:dayTimeDuration(xs:untypedAtomic("PT240H"))', DayTimeDuration.fromstring("P10D")) self.check_value( 'xs:untypedAtomic("PT240H") castable as xs:dayTimeDuration', True) self.check_value('xs:dayTimeDuration("-P2DT15H0M0S")', DayTimeDuration.fromstring('-P2DT15H')) self.check_value('xs:dayTimeDuration("P3DT10H")', DayTimeDuration.fromstring("P3DT10H")) self.check_value('xs:dayTimeDuration("PT1S")', (0, 1)) self.check_value('xs:dayTimeDuration("PT0S")', (0, 0)) self.wrong_value('xs:dayTimeDuration("+P3DT10H")', 'FORG0001') self.check_value('xs:dayTimeDuration("P999999999999999D")', OverflowError) root = self.etree.XML('<root a="P5DT18H"/>') context = XPathContext(root) self.check_value('xs:dayTimeDuration(@a)', DayTimeDuration(496800), context=context) context.item = DayTimeDuration(86400) self.check_value('xs:dayTimeDuration(.)', DayTimeDuration(86400), context=context)
def test_year_month_duration_constructor(self): self.check_value('xs:yearMonthDuration("P3Y5M")', (41, 0)) self.check_value('xs:yearMonthDuration(xs:untypedAtomic("P3Y5M"))', (41, 0)) self.check_value('xs:yearMonthDuration("-P15M")', (-15, 0)) self.check_value('xs:yearMonthDuration("-P20Y18M")', YearMonthDuration.fromstring("-P21Y6M")) self.check_value('xs:yearMonthDuration(xs:duration("P3Y5M"))', (41, 0)) self.check_value( 'xs:untypedAtomic("P3Y5M") castable as xs:yearMonthDuration', True) self.check_value( '"P9999999999999999Y" castable as xs:yearMonthDuration', False) self.wrong_value('xs:yearMonthDuration("-P15M1D")') self.wrong_value('xs:yearMonthDuration("P15MT1H")') self.wrong_value('xs:yearMonthDuration("P1MT10H")') root = self.etree.XML('<root a="P1Y5M"/>') context = XPathContext(root) self.check_value('xs:yearMonthDuration(@a)', Duration(months=17), context=context) context.item = YearMonthDuration(months=12) self.check_value('xs:yearMonthDuration(.)', YearMonthDuration(12), context=context)
def test_is_principal_node_kind(self): root = ElementTree.XML('<A a1="10" a2="20"/>') context = XPathContext(root) self.assertTrue(hasattr(context.item.elem, 'tag')) self.assertTrue(context.is_principal_node_kind()) context.item = context.root.attributes[0] self.assertFalse(context.is_principal_node_kind()) context.axis = 'attribute' self.assertTrue(context.is_principal_node_kind())
def test_untyped_atomic_constructor(self): self.check_value('xs:untypedAtomic(())', []) root = self.etree.XML('<root>1999</root>') context = XPathContext(root) self.check_value('xs:untypedAtomic(.)', UntypedAtomic(1999), context=context) context.item = UntypedAtomic('true') self.check_value('xs:untypedAtomic(.)', UntypedAtomic(True), context=context)
def test_date_constructor(self): tz = Timezone(datetime.timedelta(hours=-14, minutes=0)) self.check_value('xs:date("2017-01-19")', datetime.datetime(2017, 1, 19)) self.check_value('xs:date(xs:untypedAtomic("2017-01-19"))', datetime.datetime(2017, 1, 19)) self.check_value('xs:date("2011-11-11-14:00")', datetime.datetime(2011, 11, 11, tzinfo=tz)) self.check_value('xs:date(xs:dateTime("1969-07-20T20:18:00"))', Date10(1969, 7, 20)) self.wrong_value('xs:date("2011-11-11-14:01")') self.wrong_value('xs:date("11-11-11")') self.check_value('xs:date(())', []) root = self.etree.XML('<root a="2017-01-19"/>') context = XPathContext(root) self.check_value('xs:date(@a)', Date10(2017, 1, 19), context=context) context.item = AttributeNode('a', str(Date10(2017, 1, 19))) self.check_value('xs:date(.)', Date10(2017, 1, 19), context=context) context.item = AttributeNode('a', 'true') self.check_value('xs:date(.)', ValueError, context=context) context.item = AttributeNode('a', True) self.check_value('xs:date(.)', ValueError, context=context) with patch.multiple(self.dummy_type, is_simple=lambda x: True): context.item = TypedAttribute(AttributeNode('a', 'true'), self.dummy_type, True) self.check_value('xs:date(.)', TypeError, context=context) root = self.etree.XML("<root>2017-10-02</root>") context = XPathContext(root) self.check_value('xs:date(.)', Date10(2017, 10, 2), context=context) root = self.etree.XML("<root>2017<a>-10-02</a></root>") context = XPathContext(root) self.check_value('xs:date(.)', Date10(2017, 10, 2), context=context) context = XPathContext(root, item=Date10(2017, 10, 2)) self.check_value('xs:date(.)', Date10(2017, 10, 2), context=context)
def test_double_constructor(self): self.wrong_value('xs:double("world")') self.check_value('xs:double("39.09")', 39.09) self.check_value('xs:double(xs:untypedAtomic("39.09"))', 39.09) self.check_value('xs:double(-5)', -5.0) self.check_value('xs:double(-5)', float) root = self.etree.XML('<root a="10.3"/>') context = XPathContext(root) context.item = context.root.attributes[0] self.check_value('xs:double(.)', float, context=context) self.check_value('xs:double(.)', 10.3, context=context)
def test_iter_attributes(self): root = ElementTree.XML('<A a1="10" a2="20"/>') context = XPathContext(root) attributes = context.root.attributes self.assertEqual(len(attributes), 2) self.assertListEqual(list(context.iter_attributes()), attributes) context.item = attributes[0] self.assertListEqual(list(context.iter_attributes()), attributes[:1]) with patch.object(DummyXsdType(), 'has_simple_content', return_value=True) as xsd_type: context = XPathContext(root) context.root.xsd_type = xsd_type self.assertListEqual(list(context.iter_attributes()), context.root.attributes) self.assertNotEqual(attributes, context.root.attributes) context.item = None self.assertListEqual(list(context.iter_attributes()), [])
def test_iter_descendants(self): root = ElementTree.XML('<A a1="10" a2="20"><B1/><B2/></A>') context = XPathContext(root) attr = context.root.attributes[0] self.assertListEqual(list(e.elem for e in context.iter_descendants()), [root, root[0], root[1]]) context.item = attr self.assertListEqual(list(context.iter_descendants(axis='descendant')), []) context.item = attr self.assertListEqual(list(context.iter_descendants()), [attr]) with patch.object(DummyXsdType(), 'has_mixed_content', return_value=True) as xsd_type: context = XPathContext(root, item=root) context.root.xsd_type = xsd_type self.assertListEqual( list(e.elem for e in context.iter_descendants()), [root, root[0], root[1]])
def test_hex_binary_constructor(self): self.check_value('xs:hexBinary(())', []) self.check_value('xs:hexBinary("84")', b'84') self.check_value('xs:hexBinary(xs:hexBinary("84"))', b'84') self.wrong_type('xs:hexBinary(12)') root = self.etree.XML('<root a="84"/>') context = XPathContext(root) self.check_value('xs:hexBinary(@a)', b'84', context=context) context.item = UntypedAtomic('84') self.check_value('xs:hexBinary(.)', b'84', context=context) context.item = '84' self.check_value('xs:hexBinary(.)', b'84', context=context) context.item = b'84' self.check_value('xs:hexBinary(.)', b'84', context=context) context.item = b'XY' self.check_value('xs:hexBinary(.)', ValueError, context=context) context.item = b'F859' self.check_value('xs:hexBinary(.)', b'F859', context=context)
def test_gregorian_month_constructor(self): self.check_value('xs:gMonth("--09")', datetime.datetime(2000, 9, 1)) self.check_value('xs:gMonth(xs:untypedAtomic("--09"))', datetime.datetime(2000, 9, 1)) self.check_value('xs:gMonth("--12")', datetime.datetime(2000, 12, 1)) self.wrong_value('xs:gMonth("--9")') self.wrong_value('xs:gMonth("-09")') self.wrong_value('xs:gMonth("--13")') self.check_value('xs:gMonth(xs:dateTime("1969-07-20T20:18:00"))', GregorianMonth(7)) root = self.etree.XML('<root a="--11"/>') context = XPathContext(root) self.check_value('xs:gMonth(@a)', GregorianMonth(11), context=context) context.item = GregorianMonth(1) self.check_value('xs:gMonth(.)', GregorianMonth(1), context=context)
def test_gregorian_year_month_constructor(self): self.check_value('xs:gYearMonth("2004-02")', datetime.datetime(2004, 2, 1)) self.check_value('xs:gYearMonth(xs:untypedAtomic("2004-02"))', datetime.datetime(2004, 2, 1)) self.check_value('xs:gYearMonth(xs:dateTime("1969-07-20T20:18:00"))', GregorianYearMonth10(1969, 7)) self.wrong_value('xs:gYearMonth("2004-2")') self.wrong_value('xs:gYearMonth("204-02")') self.check_value('"99999999999999999999999999999-01" castable as xs:gYearMonth', False) root = self.etree.XML('<root a="1900-01"/>') context = XPathContext(root) self.check_value('xs:gYearMonth(@a)', GregorianYearMonth10(1900, 1), context=context) context.item = GregorianYearMonth10(1300, 10) self.check_value('xs:gYearMonth(.)', GregorianYearMonth10(1300, 10), context=context)
def test_time_constructor(self): tz = Timezone(datetime.timedelta(hours=5, minutes=24)) self.check_value('xs:time("21:30:00")', datetime.datetime(2000, 1, 1, 21, 30)) self.check_value('xs:time(xs:untypedAtomic("21:30:00"))', datetime.datetime(2000, 1, 1, 21, 30)) self.check_value('xs:time("11:15:48+05:24")', datetime.datetime(2000, 1, 1, 11, 15, 48, tzinfo=tz)) self.check_value('xs:time(xs:dateTime("1969-07-20T20:18:00"))', Time(20, 18, 00)) self.wrong_value('xs:time("24:00:01")') root = self.etree.XML('<root a="13:15:39"/>') context = XPathContext(root) self.check_value('xs:time(@a)', Time(13, 15, 39), context=context) context.item = Time(20, 10, 00) self.check_value('xs:time(.)', Time(20, 10, 00), context=context)
def test_xmlschema_proxy(self): context = XPathContext(root=self.etree.XML( '<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"/>')) self.wrong_name("schema-element(nil)") self.wrong_name("schema-element(xs:string)") self.check_value("schema-element(xs:complexType)", None) self.check_value("schema-element(xs:schema)", context.item, context) self.check_tree("schema-element(xs:group)", '(schema-element (: (xs) (group)))') context.item = AttributeNode(XML_LANG, 'en') self.wrong_name("schema-attribute(nil)") self.wrong_name("schema-attribute(xs:string)") self.check_value("schema-attribute(xml:lang)", None) self.check_value("schema-attribute(xml:lang)", context.item, context) self.check_tree("schema-attribute(xsi:schemaLocation)", '(schema-attribute (: (xsi) (schemaLocation)))')
def test_gregorian_year_constructor(self): self.check_value('xs:gYear("2004")', datetime.datetime(2004, 1, 1)) self.check_value('xs:gYear(xs:untypedAtomic("2004"))', datetime.datetime(2004, 1, 1)) self.check_value('xs:gYear("-2004")', GregorianYear10(-2004)) self.check_value('xs:gYear("-12540")', GregorianYear10(-12540)) self.check_value('xs:gYear("12540")', GregorianYear10(12540)) self.check_value('xs:gYear(xs:dateTime("1969-07-20T20:18:00"))', GregorianYear10(1969)) self.wrong_value('xs:gYear("84")') self.wrong_value('xs:gYear("821")') self.wrong_value('xs:gYear("84")') self.check_value('"99999999999999999999999999999" castable as xs:gYear', False) root = self.etree.XML('<root a="1999"/>') context = XPathContext(root) self.check_value('xs:gYear(@a)', GregorianYear10(1999), context=context) context.item = GregorianYear10(1492) self.check_value('xs:gYear(.)', GregorianYear10(1492), context=context)
def test_iter_ancestors(self): root = ElementTree.XML('<A a1="10" a2="20"><B1/><B2/></A>') context = XPathContext(root) attr = context.root.attributes[0] self.assertListEqual(list(context.iter_ancestors()), []) context.item = attr self.assertListEqual(list(context.iter_ancestors()), [context.root]) result = list( e.elem for e in XPathContext(root, item=root[1]).iter_ancestors()) self.assertListEqual(result, [root]) with patch.object(DummyXsdType(), 'has_mixed_content', return_value=True) as xsd_type: context = XPathContext(root, item=root[1]) context.root[1].xsd_type = xsd_type self.assertListEqual(list(context.iter_ancestors()), [context.root])
def test_gregorian_day_constructor(self): tz = Timezone(datetime.timedelta(hours=5, minutes=24)) self.check_value('xs:gDay("---30")', datetime.datetime(2000, 1, 30)) self.check_value('xs:gDay(xs:untypedAtomic("---30"))', datetime.datetime(2000, 1, 30)) self.check_value('xs:gDay("---21+05:24")', datetime.datetime(2000, 1, 21, tzinfo=tz)) self.check_value('xs:gDay(xs:dateTime("1969-07-20T20:18:00"))', GregorianDay(20)) self.wrong_value('xs:gDay("---32")') self.wrong_value('xs:gDay("--19")') root = self.etree.XML('<root a="---08"/>') context = XPathContext(root) self.check_value('xs:gDay(@a)', GregorianDay(8), context=context) context.item = GregorianDay(10) self.check_value('xs:gDay(.)', GregorianDay(10), context=context)
def test_float_constructor(self): self.wrong_value('xs:float("..")') self.wrong_value('xs:float("ab")', 'FORG0001') self.wrong_value('xs:float("inf")') self.check_value('xs:float(25.05)', 25.05) self.check_value('xs:float(xs:untypedAtomic(25.05))', 25.05) self.check_value('xs:float(-0.00001)', -0.00001) self.check_value('xs:float(0.00001)', float) self.check_value('xs:float("INF")', float('inf')) self.check_value('xs:float("-INF")', float('-inf')) root = self.etree.XML('<root a="10.3"/>') context = XPathContext(root) context.item = context.root.attributes[0] self.check_value('xs:float(.)', float, context=context) self.check_value('xs:float(.)', 10.3, context=context) self.parser._xsd_version = '1.1' try: self.check_value('xs:float(9.001)', 9.001) finally: self.parser._xsd_version = '1.1'