def test_wrong_type(self): class DummyPlugin(object): schema = Schema({}, extra=ALLOW_EXTRA) plugins = Plugins() plugins.register('repo', 'foo', DummyPlugin) with ShouldRaise (TypeError): Config.realise(dict(repos=[dict(type='foo')]), plugins)
def test_no_schema(self): class DummyPlugin(Repo): pass plugins = Plugins() plugins.register('repo', 'foo', DummyPlugin) with ShouldRaise ( TypeError("'abstractproperty' object is not callable") ): Config.realise(dict(repos=[dict(type='foo')]), plugins)
def test_plugin_instantiation_exception(self): class DummyPlugin(Repo): schema = Schema({}, extra=ALLOW_EXTRA) plugins = Plugins() plugins.register('repo', 'foo', DummyPlugin) with ShouldRaise (TypeError( "Can't instantiate abstract class DummyPlugin " "with abstract methods __init__, actions, path_for" )): Config.realise(dict(repos=[dict(type='foo')]), plugins)
def test_valid(self): # one of each class DummyRepo(Repo): schema = Schema({}, extra=ALLOW_EXTRA) def __init__(self, type, name, x): super(DummyRepo, self).__init__(type, name) self.x = x def actions(self): pass def path_for(self, source): pass class DummySource(Source): schema = Schema({}, extra=ALLOW_EXTRA) def __init__(self, type, name, repo, y): super(DummySource, self).__init__(type, name, repo) self.y = y def process(self, path): pass class DummyNotifier(Notifier): schema = Schema({}, extra=ALLOW_EXTRA) def __init__(self, type, name, z): super(DummyNotifier, self).__init__( type, name, level=0, fmt='f', datefmt='d' ) self.z = z def start(self): pass def finish(self): pass plugins = Plugins() plugins.register('repo', 'foo', DummyRepo) plugins.register('source', 'bar', DummySource) plugins.register('notification', 'baz', DummyNotifier) config = Config.realise(dict(repos=[dict(type='foo', name='po', x=1)], sources=[dict(type='bar', y=2, repo='po', name=None)], notifications=[dict(type='baz', z=3, name=None)]), plugins) compare({'po': C(DummyRepo, type='foo', name='po', x=1)}, config.repos) compare([C(DummySource, y=2, type='bar', repo='po', name=None)], config.sources) compare([C(DummyNotifier, type='baz', name=None, level=0, fmt='f', datefmt='d', z=3, )], config.notifications)
def check_config_error(self, config, plugins, expected): with ShouldRaise(ConfigError) as s: Config.realise(config, plugins) compare(expected, str(s.raised), trailing_whitespace=False)