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_full_instantiation(self): # one of each class DummyGit(Repo): schema = Schema({}, extra=ALLOW_EXTRA) def __init__(self, type, name): super(DummyGit, self).__init__(type, name) def actions(self): pass def path_for(self, source): pass class DummyPath(Source): schema = Schema({}, extra=ALLOW_EXTRA) def __init__(self, type, name, repo): super(DummyPath, self).__init__(type, name, repo) def process(self, path): pass class DummyEmail(Notifier): schema = Schema({}, extra=ALLOW_EXTRA) def __init__(self, type, name): super(DummyEmail, self).__init__(type, name, level=0, fmt='f', datefmt='d') def start(self): pass def finish(self): pass plugins = Plugins() plugins.register('repo', 'git', DummyGit) plugins.register('source', 'path', DummyPath) plugins.register('notification', 'email', DummyEmail) source = open(self.dir.write('test.yaml', """ repos: - name: config type: git sources: - path: /some/path notifications: - email: [email protected] """)) config = Config.load(source, plugins) compare( C(Config, repos=dict(config=C(DummyGit, type='git', name='config')), sources=[C(DummyPath, type='path', repo='config', name='/some/path')], notifications=[ C(DummyEmail, type='email', name='*****@*****.**', level=0, fmt='f', datefmt='d') ]), config )
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 test_defaults_instantiate(self): plugins = Plugins.load() git = plugins.get('repo', 'git') paths = plugins.get('source', 'paths') stream = plugins.get('notification', 'stream') file_path = self.dir.write('test.conf', 'conf content') source = open(self.dir.write('test.yaml', """ sources: - paths: - {} """.format(file_path))) config = Config.load(source, plugins) compare( C(Config, repos=dict(config=C(git, strict=False, **default_repo_config)), sources=[C(paths, type='paths', repo='config', name=None, source_paths=[file_path])], notifications=[ C(stream, strict=False, **default_notifications_config) ]), config )
def check_parses(self, text, expected): source = open(self.dir.write('test.yaml', text)) actual = Config.parse(source) compare(expected, actual)
def check_config_error(self, text, expected): source = open(self.dir.write('test.yaml', text)) with ShouldRaise(ConfigError) as s: Config.parse(source) compare(expected, str(s.raised), trailing_whitespace=False)
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)
def test_list_value(self): compare(config({'type': 'foo', 'name': None, 'values':['bar', 'baz']}), Config.normalise_plugin_config( config({'foo': ['bar', 'baz']}) ))
def test_no_name(self): compare(config({'type': 'foo', 'value': 'bar', 'name': None}), Config.normalise_plugin_config( config({'type': 'foo', 'value': 'bar'}) ))
def test_key_value_to_type_name(self): compare(config({'type': 'foo', 'name': 'bar'}), Config.normalise_plugin_config( config({'foo': 'bar'}) ))