Beispiel #1
0
    def test_process_attribute_with_unknown_source(self):
        group_attr = AttrFactory.attribute_group(name="bar")
        target = ClassFactory.create()
        target.attrs.append(group_attr)

        with self.assertRaises(AnalyzerValueError) as cm:
            self.processor.process_attribute(target, group_attr)

        self.assertEqual("Group attribute not found: `bar`", str(cm.exception))
Beispiel #2
0
    def test_process_attribute_with_circular_reference(self):
        group_attr = AttrFactory.attribute_group(name="bar")
        target = ClassFactory.create(qname="bar", type=Group)
        target.attrs.append(group_attr)

        target.status = Status.PROCESSING
        self.processor.container.add(target)

        self.processor.process_attribute(target, group_attr)
        self.assertFalse(group_attr in target.attrs)
Beispiel #3
0
    def test_expand_attribute_group_with_unknown_source(self):
        group_attr = AttrFactory.attribute_group(name="foo:bar")
        target = ClassFactory.create()
        target.attrs.append(group_attr)

        with self.assertRaises(AnalyzerError) as cm:
            self.analyzer.expand_attribute_group(target, group_attr)

        self.assertEqual("Group attribute not found: `{foo}bar`",
                         str(cm.exception))
Beispiel #4
0
    def test_process_attribute_with_group(self, mock_copy_group_attributes):
        complex_bar = ClassFactory.create(qname="bar", type=ComplexType)
        group_bar = ClassFactory.create(qname="bar", type=Group)
        group_attr = AttrFactory.attribute_group(name="bar")
        target = ClassFactory.create()
        target.attrs.append(group_attr)

        self.processor.container.add(complex_bar)
        self.processor.container.add(group_bar)
        self.processor.container.add(target)

        self.processor.process_attribute(target, group_attr)
        mock_copy_group_attributes.assert_called_once_with(
            group_bar, target, group_attr)
Beispiel #5
0
    def test_expand_attribute_group(self, mock_find_class,
                                    mock_clone_attribute):
        source = ClassFactory.elements(2)
        group_attr = AttrFactory.attribute_group(name="foo:bar")
        target = ClassFactory.create()
        target.attrs.append(group_attr)

        mock_find_class.return_value = source
        mock_clone_attribute.side_effect = lambda x, y, z: x.clone()

        self.analyzer.expand_attribute_group(target, group_attr)

        self.assertEqual(2, len(target.attrs))
        self.assertIsNot(source.attrs[0], target.attrs[0])
        self.assertIsNot(source.attrs[1], target.attrs[1])
        self.assertNotIn(group_attr, target.attrs)

        mock_clone_attribute.assert_has_calls([
            mock.call(source.attrs[0], group_attr.restrictions, "foo"),
            mock.call(source.attrs[1], group_attr.restrictions, "foo"),
        ])
Beispiel #6
0
 def test_property_is_group(self):
     self.assertTrue(AttrFactory.group().is_group)
     self.assertTrue(AttrFactory.attribute_group().is_group)
     self.assertFalse(AttrFactory.element().is_group)