예제 #1
0
    def test_filter_classes_with_only_simple_types(self, mock_class_should_generate):
        mock_class_should_generate.return_value = False
        classes = [ClassFactory.enumeration(2), ClassFactory.create(type=SimpleType)]
        container = ClassContainer.from_list(classes)
        container.filter_classes()

        self.assertEqual(classes, container.class_list)
예제 #2
0
    def test_from_list(self):
        classes = [
            ClassFactory.create(qname="{xsdata}foo", type=Element),
            ClassFactory.create(qname="{xsdata}foo", type=ComplexType),
            ClassFactory.create(qname="{xsdata}foobar", type=ComplexType),
        ]
        container = ClassContainer.from_list(classes)

        expected = {
            "{xsdata}foo": classes[:2],
            "{xsdata}foobar": classes[2:],
        }

        self.assertEqual(2, len(container))
        self.assertEqual(expected, container)
        self.assertEqual(
            [
                "AttributeGroupHandler",
                "ClassExtensionHandler",
                "AttributeEnumUnionHandler",
                "AttributeSubstitutionHandler",
                "AttributeTypeHandler",
                "AttributeMergeHandler",
                "AttributeMixedContentHandler",
                "AttributeMismatchHandler",
            ],
            [x.__class__.__name__ for x in container.processors],
        )
예제 #3
0
    def test_select_classes_when_no_complex_class_available(self):
        classes = [
            ClassFactory.enumeration(2),
            ClassFactory.create(type=SimpleType)
        ]
        container = ClassContainer.from_list(classes)

        self.assertEqual(classes, ClassAnalyzer.select_classes(container))
예제 #4
0
    def test_filter_classes(self, mock_class_should_generate):
        mock_class_should_generate.side_effect = [True, False, False, True, False]

        classes = ClassFactory.list(5)
        container = ClassContainer.from_list(classes)

        expected = [
            classes[0],
            classes[3],
        ]
        container.filter_classes()
        self.assertEqual(expected, container.class_list)
예제 #5
0
    def test_from_list(self):
        classes = [
            ClassFactory.create(qname="foo", type=Element),
            ClassFactory.create(qname="foo", type=ComplexType),
            ClassFactory.create(qname="foobar", type=ComplexType),
        ]
        container = ClassContainer.from_list(classes)

        expected = {
            "{xsdata}foo": classes[:2],
            "{xsdata}foobar": classes[2:],
        }

        self.assertEqual(2, len(container))
        self.assertEqual(expected, container)
예제 #6
0
    def process(cls, classes: List[Class]) -> List[Class]:
        """Run all the processes."""

        # Wrap classes with container for easy access.
        container = ClassContainer.from_list(classes)

        # Run validation checks for duplicate, invalid and redefined types.
        ClassValidator.process(container)

        # Run analyzer handlers
        container.process()

        # Sanitize class attributes after merging and flattening types and extensions.
        ClassSanitizer.process(container)

        # Select final list of classes to be generated.
        return cls.select_classes(container)
예제 #7
0
    def test_select_classes(self, mock_validate_references):
        classes = [
            ClassFactory.create(strict_type=True, type=ComplexType),
            ClassFactory.create(type=Element),
            ClassFactory.create(type=ComplexType),
            ClassFactory.create(type=SimpleType),
            ClassFactory.enumeration(2),
        ]

        container = ClassContainer.from_list(classes)

        expected = [
            classes[1],
            classes[2],
            classes[4],
        ]

        self.assertEqual(expected, ClassAnalyzer.select_classes(container))
        mock_validate_references.assert_called_once_with(expected)
예제 #8
0
    def test_process(
        self,
        mock_validator_process,
        mock_container_process,
        mock_sanitizer_process,
        mock_select_classes,
    ):
        original_classes = ClassFactory.list(2)
        container = ClassContainer.from_list(original_classes)
        result_classes = ClassFactory.list(1)
        mock_select_classes.return_value = result_classes

        result = ClassAnalyzer.process(original_classes)

        self.assertEqual(result_classes, result)

        mock_validator_process.assert_called_once_with(container)
        mock_container_process.assert_called_once_with()
        mock_sanitizer_process.assert_called_once_with(container)
        mock_select_classes.assert_called_once_with(container)
예제 #9
0
    def setUp(self):
        super().setUp()

        self.root_enum = ClassFactory.enumeration(2)
        self.inner_enum = ClassFactory.enumeration(2)
        self.target = ClassFactory.create(attrs=[
            AttrFactory.create(
                name="value",
                tag=Tag.UNION,
                types=[
                    AttrTypeFactory.create(name=self.root_enum.name),
                    AttrTypeFactory.create(name=self.inner_enum.name,
                                           forward=True),
                ],
            ),
        ], )
        self.target.inner.append(self.inner_enum)

        container = ClassContainer.from_list([self.target, self.root_enum])
        self.processor = AttributeEnumUnionHandler(container=container)
예제 #10
0
    def process(cls, classes: List[Class], config: GeneratorConfig) -> List[Class]:
        """Run all the processes."""

        # Wrap classes with container for easy access.
        container = ClassContainer.from_list(classes)

        # Run validation checks for duplicate, invalid and redefined types.
        ClassValidator.process(container)

        # Run analyzer handlers
        container.process()

        # Filter classes that should be generated.
        container.filter_classes()

        # Sanitize class attributes after merging and flattening types and extensions.
        ClassSanitizer.process(container, config)

        classes = container.class_list
        cls.validate_references(classes)

        return classes
예제 #11
0
파일: analyzer.py 프로젝트: rmr1154/xsdata
 def from_classes(cls, classes: List[Class]) -> "ClassAnalyzer":
     """Instantiate from a list of classes."""
     container = ClassContainer.from_list(classes)
     return cls(container)