def test_useless_are_not_called(self): '''Retrievers which don't provide requested data are not called''' pluginsystem.register_plugin(Slow) pluginsystem.register_plugin(Trackable) get('a', 'b', request=('foo',), timeout=0.3) time.sleep(0.2) assert Trackable.called == False
def test_noone_is_fast_enough(self): '''when no retriever is fast enough, (None, None) should be returned''' pluginsystem.register_plugin(Slow) res = get('a', 'b', request=('foo',), timeout=0.2) print 'NOONE', res assert res is None
def test_no_extra(self): '''Don't return anything that is not requested''' pluginsystem.register_plugin(Slow) pluginsystem.register_plugin(QuickBar) res = get('a', 'b', request=('foo',)) print 'result', res assert 'foo' in res assert 'bar' not in res
def test_timeout(self): '''Timeout must do its job''' pluginsystem.register_plugin(Slow) pluginsystem.register_plugin(Quick) start = time.time() res = get('a', 'b', request=('donthaveit'), timeout=1) assert time.time() - start < 2.0
def test_best_found(self): '''first_match must found the "best", even if not perfect''' pluginsystem.register_plugin(Slow) pluginsystem.register_plugin(QuickBar) res = get('a', 'b', request=('foo', 'bar'), timeout=0.5) assert 'bar' in res assert 'foo' not in res
def test_slow_if_no_matches(self): '''when no matches are found, slowness is ok''' pluginsystem.register_plugin(Slow) start = time.time() res = get('a', 'b', request=('foo',), analyzer='first_match') assert time.time() - start > 1.0 assert res['foo'] == 'slow foo'
def test_first_match(self): '''first match analyzer should choose the quickest, and do it quick''' #TODO: change to a more explicit, analyzer-choosing API pluginsystem.register_plugin(Quick) pluginsystem.register_plugin(Slow) res = get('a', 'b', request=('foo',), analyzer='first_match') assert res['foo'] == 'quick foo'
def test_first_advanced_match(self): '''first match should "compose" results''' pluginsystem.register_plugin(Quick) pluginsystem.register_plugin(QuickBar) res = get('a', 'b', request=('foo', 'bar'), analyzer='first_match') assert 'bar' in res assert res['bar'] == 'quickBar bar' assert 'foo' in res assert res['foo'] == 'quick foo'
def nonvalid_raises_test(self): class Missing: name = 'foo' features = ('foo', ) pluginsystem.register_plugin(Missing)
def nonvalid_raises_test(self): class Missing: name = 'foo' features = ('foo',) pluginsystem.register_plugin(Missing)
def test_all(self): pluginsystem.register_plugin(Slow) pluginsystem.register_plugin(Quick) get('a', 'b', request=('foo',))
def test_select(self): pluginsystem.register_plugin(Slow) pluginsystem.register_plugin(Quick) get('a', 'b', request=('foo',), plugin_filter=('quick',))
def test_none(self): pluginsystem.register_plugin(Slow) get('a', 'b', request=('foo',), plugin_filter=())
def test_error_handling(self): '''Even when retrievers raise, all should be fine''' pluginsystem.register_plugin(Error) #does not raise any error res = get('a', 'b', request=('foo',)) assert res is None
def test_first_dont_match(self): '''first match should not match results that don't satisfies request''' pluginsystem.register_plugin(Quick) res = get('a', 'b', request=('donthaveit',), analyzer='first_match') assert res == None