diff --git a/elementpath/datatypes.py b/elementpath/datatypes.py index e954ddc..99b4ad0 100644 --- a/elementpath/datatypes.py +++ b/elementpath/datatypes.py @@ -1114,7 +1114,7 @@ class ArithmeticTypeProxy(object): @staticmethod def instance_check(other): return isinstance(other, (int, float, decimal.Decimal, AbstractDateTime, Duration)) \ - and not isinstance(other, bool) + and not isinstance(other, bool) @staticmethod def subclass_check(subclass): diff --git a/elementpath/xpath_nodes.py b/elementpath/xpath_nodes.py index 1663a5c..f159bb9 100644 --- a/elementpath/xpath_nodes.py +++ b/elementpath/xpath_nodes.py @@ -235,30 +235,3 @@ def node_string_value(obj): elif is_processing_instruction_node(obj): return obj.text - -### -# XPath base functions -def boolean_value(obj, token=None): - """ - The effective boolean value, as computed by fn:boolean(). - Moved to token class but kept for backward compatibility. - """ - if isinstance(obj, list): - if not obj: - return False - elif isinstance(obj[0], tuple) or is_element_node(obj[0]): - return True - elif len(obj) == 1: - return bool(obj[0]) - else: - raise xpath_error( - code='FORG0006', token=token, prefix=getattr(token, 'error_prefix', 'err'), - message="Effective boolean value is not defined for a sequence of two or " - "more items not starting with an XPath node.", - ) - elif isinstance(obj, tuple) or is_element_node(obj): - raise xpath_error( - code='FORG0006', token=token, prefix=getattr(token, 'error_prefix', 'err'), - message="Effective boolean value is not defined for {}.".format(obj) - ) - return bool(obj) diff --git a/tests/test_helpers.py b/tests/test_helpers.py index 059fbf2..b80a180 100644 --- a/tests/test_helpers.py +++ b/tests/test_helpers.py @@ -22,6 +22,7 @@ from elementpath.xpath_nodes import AttributeNode, NamespaceNode, is_etree_eleme is_namespace_node, is_processing_instruction_node, is_text_node, node_attributes, \ node_base_uri, node_document_uri, node_children, node_is_id, node_is_idrefs, \ node_nilled, node_kind, node_name, node_string_value +from elementpath.xpath_helpers import boolean_value from elementpath.xpath1_parser import XPath1Parser @@ -245,5 +246,23 @@ class NodeHelpersTest(unittest.TestCase): self.assertIsNone(node_string_value(10)) +class CompatibilityHelpersTest(unittest.TestCase): + + def test_boolean_value_function(self): + elem = ElementTree.Element('A') + + self.assertFalse(boolean_value([])) + self.assertTrue(boolean_value([elem])) + self.assertFalse(boolean_value([0])) + self.assertTrue(boolean_value([1])) + with self.assertRaises(TypeError): + boolean_value([1, 1]) + with self.assertRaises(TypeError): + boolean_value(elem) + self.assertFalse(boolean_value(0)) + self.assertTrue(boolean_value(1)) + + + if __name__ == '__main__': unittest.main() diff --git a/tests/test_schema_proxy.py b/tests/test_schema_proxy.py index ec3d308..14698c3 100644 --- a/tests/test_schema_proxy.py +++ b/tests/test_schema_proxy.py @@ -114,6 +114,10 @@ class XPath2ParserXMLSchemaTest(test_xpath2_parser.XPath2ParserTest): facet_type = schema_proxy.get_type('{%s}facet' % XSD_NAMESPACE) any_type = schema_proxy.get_type('{%s}anyType' % XSD_NAMESPACE) self.assertEqual(schema_proxy.get_primitive_type(facet_type), any_type) + self.assertEqual(schema_proxy.get_primitive_type(any_type), any_type) + + any_simple_type = schema_proxy.get_type('{%s}anySimpleType' % XSD_NAMESPACE) + self.assertEqual(schema_proxy.get_primitive_type(any_simple_type), any_simple_type) def test_is_instance_api(self): self.assertFalse(self.schema_proxy.is_instance(True, '{%s}integer' % XSD_NAMESPACE))