def test_set_schema_namespaces(self): schema = Schema() self.parser.set_schema_namespaces(schema) self.assertIsNone(schema.target_namespace) self.parser.target_namespace = "bar" self.parser.set_schema_namespaces(schema) self.assertEqual("bar", schema.target_namespace) schema.target_namespace = "foo" self.parser.set_schema_namespaces(schema) self.assertEqual("foo", schema.target_namespace)
def test_module(self): schema = Schema(location="foo/bar.xsd", target_namespace="http://xsdata/foo") self.assertEqual("bar", schema.module) schema.location = "foo/bar.noext" self.assertEqual("bar.noext", schema.module) schema.location = None self.assertEqual("foo", schema.module) schema.target_namespace = None with self.assertRaises(SchemaValueError) as cm: schema.module self.assertEqual("Unknown schema module.", str(cm.exception))
def test_set_schema_namespaces(self, mock_set_namespace_map): schema = Schema() element = etree.Element("schema") self.parser.set_schema_namespaces(schema, element) self.assertIsNone(schema.target_namespace) self.parser.target_namespace = "bar" self.parser.set_schema_namespaces(schema, element) self.assertEqual("bar", schema.target_namespace) schema.target_namespace = "foo" self.parser.set_schema_namespaces(schema, element) self.assertEqual("foo", schema.target_namespace) mock_set_namespace_map.assert_has_calls([ mock.call(element, schema), mock.call(element, schema), mock.call(element, schema), ])
def set_schema_namespaces(self, obj: xsd.Schema): """Set the given schema's target namespace and add the default namespaces if the are missing xsi, xlink, xml, xs.""" obj.target_namespace = obj.target_namespace or self.target_namespace