Example #1
0
 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
Example #2
0
 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
Example #3
0
 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
Example #4
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
Example #5
0
 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
Example #6
0
 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'
Example #7
0
 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'
Example #8
0
 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'
Example #9
0
 def test_all(self):
     pluginsystem.register_plugin(Slow)
     pluginsystem.register_plugin(Quick)
     get('a', 'b', request=('foo',))
Example #10
0
 def test_select(self):
     pluginsystem.register_plugin(Slow)
     pluginsystem.register_plugin(Quick)
     get('a', 'b', request=('foo',), plugin_filter=('quick',))
Example #11
0
 def test_none(self):
     pluginsystem.register_plugin(Slow)
     get('a', 'b', request=('foo',), plugin_filter=())
Example #12
0
    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
Example #13
0
 def test_bad_analyzer(self):
     '''Specifying a non-existing analyzer should raise ValueError'''
     get('a', 'b', request=('lyrics',), analyzer='dontexist')
Example #14
0
 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