def test_obtain_from_python_path(self): self.assertEquals( os.path.sep, LoaderUtilities.obtain_from_python_path('os.path.sep')) self.assertEquals(os.open, LoaderUtilities.obtain_from_python_path('os.open')) self.assertEquals(os.path, LoaderUtilities.obtain_from_python_path('os.path')) self.assertRaises(LoaderErrors.InvalidConfigurationError, LoaderUtilities.obtain_from_python_path, 'I guess this does not exist') self.assertRaises(LoaderErrors.InvalidConfigurationError, LoaderUtilities.obtain_from_python_path, 'os.path.thisdoesnt')
def _parse_server_type_module(self, server_type_node): text_value = LoaderUtilities.obtain_text_safe(server_type_node) if text_value.count('::') != 1: raise LoaderErrors.InvalidConfigurationError( 'Unknown format: %s. module::variable expected' % text_value ) module_name, _ = text_value.split('::') module_inst = LoaderUtilities.obtain_from_python_path(module_name) return module_inst
def test_obtain_from_python_path(self): self.assertEquals( os.path.sep, LoaderUtilities.obtain_from_python_path('os.path.sep') ) self.assertEquals( os.open, LoaderUtilities.obtain_from_python_path('os.open') ) self.assertEquals( os.path, LoaderUtilities.obtain_from_python_path('os.path') ) self.assertRaises( LoaderErrors.InvalidConfigurationError, LoaderUtilities.obtain_from_python_path, 'I guess this does not exist' ) self.assertRaises( LoaderErrors.InvalidConfigurationError, LoaderUtilities.obtain_from_python_path, 'os.path.thisdoesnt' )
def _retrieve_variable(self, format_node): text_value = LoaderUtilities.obtain_text_safe(format_node) if text_value.count('::') != 1: raise LoaderErrors.InvalidConfigurationError( 'Unknown format: %s. module::variable expected' % text_value ) module_name, variable = text_value.split('::') module_inst = LoaderUtilities.obtain_from_python_path(module_name) try: return getattr(module_inst, variable) except AttributeError: raise LoaderErrors.InvalidConfigurationError( 'Unknown format: couldn\'t find %s in %s' % (variable, module_name) )
def _parse_implementation(self, implementation_node): implementation_class_name = LoaderUtilities.obtain_text_safe(implementation_node) return LoaderUtilities.obtain_from_python_path(implementation_class_name)