def test_import_component_twice_2(self): # Make sure we can import a component from a config file even # if it has already been imported from the schema. loader = ZConfigParser.loader.SchemaLoader() sio = StringIO( "<schema>" " <import package='ZConfigParser.tests.library.widget' />" "</schema>") schema = loader.loadFile(sio) loader = ZConfigParser.loader.ConfigLoader(schema) sio = StringIO("%import ZConfigParser.tests.library.widget") loader.loadFile(sio)
def test_import_from_package_with_missing_file(self): loader = ZConfigParser.loader.SchemaLoader() sio = StringIO("<schema>" " <import package='ZConfigParser.tests.library.widget'" " file='notthere.xml' />" "</schema>") try: loader.loadFile(sio) except ZConfigParser.SchemaResourceError, e: self.assertEqual(e.filename, "notthere.xml") self.assertEqual(e.package, "ZConfigParser.tests.library.widget") self.assert_(e.path) # make sure the str() doesn't raise an unexpected exception str(e)
def test_import_from_package(self): loader = ZConfigParser.loader.SchemaLoader() sio = StringIO( "<schema>" " <import package='ZConfigParser.tests.library.widget'/>" "</schema>") schema = loader.loadFile(sio) self.assert_(schema.gettype("widget-a") is not None)
def test_import_from_package_extra_directory(self): loader = ZConfigParser.loader.SchemaLoader() sio = StringIO("<schema>" " <import package='ZConfigParser.tests.library.thing'" " file='extras.xml' />" "</schema>") schema = loader.loadFile(sio) self.assert_(schema.gettype("extra-thing") is not None)
def test_simple_import_with_cache(self): loader = ZConfigParser.loader.SchemaLoader() url1 = ZConfigParser.url.urljoin(CONFIG_BASE, "library.xml") schema1 = loader.loadURL(url1) sio = StringIO("<schema>" " <import src='library.xml'/>" " <section type='type-a' name='section'/>" "</schema>") url2 = ZConfigParser.url.urljoin(CONFIG_BASE, "stringio") schema2 = loader.loadFile(sio, url2) self.assert_(schema1.gettype("type-a") is schema2.gettype("type-a"))
def test_import_two_components_one_package(self): loader = ZConfigParser.loader.SchemaLoader() sio = StringIO( "<schema>" " <import package='ZConfigParser.tests.library.widget' />" " <import package='ZConfigParser.tests.library.widget'" " file='extra.xml' />" "</schema>") schema = loader.loadFile(sio) schema.gettype("widget-a") schema.gettype("extra-type")
def test_import_component_twice_1(self): # Make sure we can import a component twice from a schema. # This is most likely to occur when the component is imported # from each of two other components, or from the top-level # schema and a component. loader = ZConfigParser.loader.SchemaLoader() sio = StringIO( "<schema>" " <import package='ZConfigParser.tests.library.widget' />" " <import package='ZConfigParser.tests.library.widget' />" "</schema>") schema = loader.loadFile(sio) schema.gettype("widget-a")