def test_merge_attributes(self): target = ClassFactory.create( attrs=[ AttrFactory.element(name="a", index=10), AttrFactory.element(name="b", index=1), AttrFactory.element(name="c", index=2), AttrFactory.attribute(name="id", index=0), ] ) source = target.clone() target.attrs[0].restrictions.min_occurs = 2 target.attrs[0].restrictions.max_occurs = 3 source.attrs[1].restrictions.min_occurs = 3 source.attrs[1].restrictions.max_occurs = 4 source.attrs[3].restrictions.min_occurs = 3 source.attrs[3].restrictions.max_occurs = 4 source.attrs.append(AttrFactory.enumeration(name="d", index=4)) ClassUtils.merge_attributes(target, source) names = ["id", "b", "c", "d", "a"] min_occurs = [0, 0, 0, None, 0] max_occurs = [4, 4, 1, None, 3] self.assertEqual(names, [x.name for x in target.attrs]) self.assertEqual(min_occurs, [x.restrictions.min_occurs for x in target.attrs]) self.assertEqual(max_occurs, [x.restrictions.max_occurs for x in target.attrs])
def test_process_attribute_default_with_enumeration(self): target = ClassFactory.create() attr = AttrFactory.enumeration() attr.restrictions.max_occurs = 2 attr.fixed = True self.sanitizer.process_attribute_default(target, attr) self.assertTrue(attr.fixed)
def test_filter(self): target = ClassFactory.elements(2) self.processor.process(target) self.assertEqual(2, len(target.attrs)) target.attrs.append(AttrFactory.enumeration()) self.processor.process(target) self.assertEqual(1, len(target.attrs)) self.assertTrue(target.attrs[0].is_enumeration)
def test_process(self): one = AttrFactory.attribute(fixed=True) one_clone = one.clone() restrictions = Restrictions(min_occurs=10, max_occurs=15) two = AttrFactory.element(restrictions=restrictions, fixed=True) two_clone = two.clone() two_clone.restrictions.min_occurs = 5 two_clone.restrictions.max_occurs = 5 two_clone_two = two.clone() two_clone_two.restrictions.min_occurs = 4 two_clone_two.restrictions.max_occurs = 4 three = AttrFactory.element() four = AttrFactory.enumeration() four_clone = four.clone() five = AttrFactory.element() five_clone = five.clone() five_clone_two = five.clone() target = ClassFactory.create( attrs=[ one, one_clone, two, two_clone, two_clone_two, three, four, four_clone, five, five_clone, five_clone_two, ] ) winners = [one, two, three, four, five] self.processor.process(target) self.assertEqual(winners, target.attrs) self.assertTrue(one.fixed) self.assertIsNone(one.restrictions.min_occurs) self.assertIsNone(one.restrictions.max_occurs) self.assertFalse(two.fixed) self.assertEqual(4, two.restrictions.min_occurs) self.assertEqual(24, two.restrictions.max_occurs) self.assertIsNone(three.restrictions.min_occurs) self.assertIsNone(three.restrictions.max_occurs) self.assertIsNone(four.restrictions.min_occurs) self.assertIsNone(four.restrictions.max_occurs) self.assertEqual(0, five.restrictions.min_occurs) self.assertEqual(3, five.restrictions.max_occurs)
def test_process(self, mock_create_substitutions, mock_process_attribute): def init_substitutions(): self.processor.substitutions = {} mock_create_substitutions.side_effect = init_substitutions target = ClassFactory.create( attrs=[AttrFactory.enumeration(), AttrFactory.any(), AttrFactory.element()] ) self.processor.process(target) self.processor.process(ClassFactory.create()) mock_process_attribute.assert_called_once_with(target, target.attrs[2]) mock_create_substitutions.assert_called_once()
def test_process_dependency_extension_with_enum_type( self, mock_find_dependency, mock_process_simple_extension, mock_process_complex_extension, ): extension = ExtensionFactory.create() target = ClassFactory.create(extensions=[extension]) source = ClassFactory.create(tag=Tag.COMPLEX_TYPE) source.attrs.append(AttrFactory.enumeration()) mock_find_dependency.return_value = source self.processor.process_extension(target, extension) self.assertEqual(0, mock_process_complex_extension.call_count) mock_process_simple_extension.assert_called_once_with(source, target, extension)
def test_property_is_enumeration(self): self.assertTrue(AttrFactory.enumeration().is_enumeration) self.assertFalse(AttrFactory.element().is_enumeration)