Ejemplo n.º 1
0
    def test_sub_schemas(self):
        imports = [
            Import.create(schema_location="../foo.xsd"),
            Import.create(schema_location="../bar.xsd"),
        ]
        includes = [
            Include.create(schema_location="common.xsd"),
            Include.create(schema_location="uncommon.xsd"),
        ]
        redefines = [
            Redefine.create(schema_location="a.xsd"),
            Redefine.create(schema_location="b.xsd"),
        ]
        overrides = [
            Override.create(schema_location="a.xsd"),
            Override.create(schema_location="b.xsd"),
        ]
        schema = Schema.create(imports=imports,
                               includes=includes,
                               redefines=redefines,
                               overrides=overrides)

        actual = schema.included()
        expected = imports + includes + redefines + overrides
        self.assertIsInstance(actual, Iterator)
        self.assertEqual(expected, list(actual))

        schema = Schema.create()
        self.assertEqual([], list(schema.included()))
Ejemplo n.º 2
0
    def test_process_schema(
        self,
        mock_parse_schema,
        mock_process_included,
        mock_generate_classes,
        mock_logger_info,
    ):
        include = Include.create()
        override = Override.create()
        schema = Schema.create(target_namespace="thug")
        schema.includes.append(include)
        schema.overrides.append(override)
        mock_process_included.side_effect = [
            ClassFactory.list(2), ClassFactory.list(3)
        ]
        mock_generate_classes.return_value = ClassFactory.list(4)

        mock_parse_schema.return_value = schema

        path = Path(__file__)
        result = self.transformer.process_schema(path,
                                                 package="foo.bar",
                                                 target_namespace="foo-bar")

        self.assertEqual(9, len(result))
        self.assertTrue(path in self.transformer.processed)

        mock_parse_schema.assert_called_once_with(path, "foo-bar")
        mock_process_included.assert_has_calls([
            mock.call(include, "foo.bar", schema.target_namespace),
            mock.call(override, "foo.bar", schema.target_namespace),
        ])

        self.transformer.process_schema(path, None, None)
        mock_logger_info.assert_called_once_with("Parsing schema...")
Ejemplo n.º 3
0
    def test_process_included_skip_when_location_is_missing(
            self, mock_logger_warning):
        include = Include.create()
        result = self.transformer.process_included(include, "foo.bar", "thug")

        self.assertIsInstance(result, list)
        self.assertEqual(0, len(result))
        mock_logger_warning.assert_called_once_with(
            "%s: %s unresolved schema location..",
            include.class_name,
            include.schema_location,
        )
Ejemplo n.º 4
0
    def test_resolve_schemas_locations(self, mock_resolve_path,
                                       mock_resolve_local_path):
        schema = Schema.create()
        self.parser.resolve_schemas_locations(schema)

        self.parser.schema_location = Path.cwd()

        mock_resolve_path.side_effect = lambda x: Path.cwd().joinpath(x)
        mock_resolve_local_path.side_effect = lambda x, y: Path.cwd().joinpath(
            x)

        schema.overrides.append(Override.create(schema_location="o1"))
        schema.overrides.append(Override.create(schema_location="o2"))
        schema.redefines.append(Redefine.create(schema_location="r1"))
        schema.redefines.append(Redefine.create(schema_location="r2"))
        schema.includes.append(Include.create(schema_location="i1"))
        schema.includes.append(Include.create(schema_location="i2"))
        schema.imports.append(
            Import.create(schema_location="i3", namespace="ns_i3"))
        schema.imports.append(
            Import.create(schema_location="i4", namespace="ns_i4"))

        self.parser.resolve_schemas_locations(schema)

        mock_resolve_path.assert_has_calls([
            mock.call("o1"),
            mock.call("o2"),
            mock.call("r1"),
            mock.call("r2"),
            mock.call("i1"),
            mock.call("i2"),
        ])

        mock_resolve_local_path.assert_has_calls(
            [mock.call("i3", "ns_i3"),
             mock.call("i4", "ns_i4")])

        for sub in schema.included():
            self.assertEqual(Path.cwd().joinpath(sub.schema_location),
                             sub.location)
Ejemplo n.º 5
0
    def test_process_included(self, mock_adjust_package, mock_process_schema):
        path = Path(__file__)
        include = Include.create(location=path, schema_location="foo.xsd")
        mock_adjust_package.return_value = "adjusted.foo.bar"
        mock_process_schema.return_value = ClassFactory.list(2)

        result = self.transformer.process_included(include, "foo.bar", "thug")

        self.assertEqual(2, len(result))
        mock_adjust_package.assert_called_once_with("foo.bar",
                                                    include.schema_location)
        mock_process_schema.assert_called_once_with(path, "adjusted.foo.bar",
                                                    "thug")
Ejemplo n.º 6
0
    def test_process_included_skip_when_location_already_imported(
            self, mock_logger_debug):
        path = Path(__file__)
        include = Include.create(location=path)
        self.transformer.processed.append(path)

        result = self.transformer.process_included(include, "foo.bar", "thug")

        self.assertIsInstance(result, list)
        self.assertEqual(0, len(result))
        mock_logger_debug.assert_called_once_with(
            "%s: %s already included skipping..",
            include.class_name,
            include.schema_location,
        )