本文整理匯總了Python中workflow.workflow.Workflow.filter方法的典型用法代碼示例。如果您正苦於以下問題:Python Workflow.filter方法的具體用法?Python Workflow.filter怎麽用?Python Workflow.filter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類workflow.workflow.Workflow
的用法示例。
在下文中一共展示了Workflow.filter方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: WorkflowTests
# 需要導入模塊: from workflow.workflow import Workflow [as 別名]
# 或者: from workflow.workflow.Workflow import filter [as 別名]
#.........這裏部分代碼省略.........
self.assertEqual(self.wf.get_password(self.account), self.password)
# try to set different password
self.wf.save_password(self.account, self.password2)
self.assertEqual(self.wf.get_password(self.account), self.password2)
# bad call to _call_security
with self.assertRaises(KeychainError):
self.wf._call_security("pants", BUNDLE_ID, self.account)
def test_run_fails(self):
"""Run fails"""
def cb(wf):
self.assertEqual(wf, self.wf)
raise ValueError("Have an error")
self.wf.name # cause info.plist to be parsed
ret = self.wf.run(cb)
self.assertEqual(ret, 1)
# named after bundleid
self.wf = Workflow()
self.wf.bundleid
ret = self.wf.run(cb)
self.assertEqual(ret, 1)
def test_run_okay(self):
"""Run okay"""
def cb(wf):
self.assertEqual(wf, self.wf)
ret = self.wf.run(cb)
self.assertEqual(ret, 0)
def test_filter_all_rules(self):
"""Filter: all rules"""
results = self.wf.filter("test", self.search_items, key=lambda x: x[0], ascending=True, match_on=MATCH_ALL)
self.assertEqual(len(results), 8)
# now with scores, rules
results = self.wf.filter("test", self.search_items, key=lambda x: x[0], include_score=True, match_on=MATCH_ALL)
self.assertEqual(len(results), 8)
for item, score, rule in results:
self.wf.logger.debug("{} : {}".format(item, score))
for value, r in self.search_items:
if value == item[0]:
self.assertEqual(rule, r)
# self.assertTrue(False)
def test_filter_no_caps(self):
"""Filter: no caps"""
results = self.wf.filter(
"test",
self.search_items,
key=lambda x: x[0],
ascending=True,
match_on=MATCH_ALL ^ MATCH_CAPITALS,
include_score=True,
)
self._print_results(results)
for item, score, rule in results:
self.assertNotEqual(rule, MATCH_CAPITALS)
# self.assertEqual(len(results), 7)
def test_filter_only_caps(self):
"""Filter: only caps"""
results = self.wf.filter(
"test", self.search_items, key=lambda x: x[0], ascending=True, match_on=MATCH_CAPITALS, include_score=True
示例2: WorkflowTests
# 需要導入模塊: from workflow.workflow import Workflow [as 別名]
# 或者: from workflow.workflow.Workflow import filter [as 別名]
#.........這裏部分代碼省略.........
self.assertEqual(self.wf.get_password(self.account, BUNDLE_ID),
self.password)
# try to set same password
self.wf.save_password(self.account, self.password)
self.assertEqual(self.wf.get_password(self.account), self.password)
# try to set different password
self.wf.save_password(self.account, self.password2)
self.assertEqual(self.wf.get_password(self.account), self.password2)
# bad call to _call_security
with self.assertRaises(KeychainError):
self.wf._call_security('pants', BUNDLE_ID, self.account)
def test_run_fails(self):
"""Run fails"""
def cb(wf):
self.assertEqual(wf, self.wf)
raise ValueError('Have an error')
self.wf.name # cause info.plist to be parsed
ret = self.wf.run(cb)
self.assertEqual(ret, 1)
# named after bundleid
self.wf = Workflow()
self.wf.bundleid
ret = self.wf.run(cb)
self.assertEqual(ret, 1)
def test_run_okay(self):
"""Run okay"""
def cb(wf):
self.assertEqual(wf, self.wf)
ret = self.wf.run(cb)
self.assertEqual(ret, 0)
def test_filter_all_rules(self):
"""Filter: all rules"""
results = self.wf.filter('test', self.search_items, key=lambda x: x[0],
ascending=True, match_on=MATCH_ALL)
self.assertEqual(len(results), 8)
# now with scores, rules
results = self.wf.filter('test', self.search_items, key=lambda x: x[0],
include_score=True, match_on=MATCH_ALL)
self.assertEqual(len(results), 8)
for item, score, rule in results:
self.wf.logger.debug('{} : {}'.format(item, score))
for value, r in self.search_items:
if value == item[0]:
self.assertEqual(rule, r)
# self.assertTrue(False)
def test_filter_no_caps(self):
"""Filter: no caps"""
results = self.wf.filter('test', self.search_items, key=lambda x: x[0],
ascending=True,
match_on=MATCH_ALL ^ MATCH_CAPITALS,
include_score=True)
self._print_results(results)
for item, score, rule in results:
self.assertNotEqual(rule, MATCH_CAPITALS)
# self.assertEqual(len(results), 7)
def test_filter_only_caps(self):
"""Filter: only caps"""
results = self.wf.filter('test', self.search_items, key=lambda x: x[0],
ascending=True,
match_on=MATCH_CAPITALS,
include_score=True)
示例3: WorkflowTests
# 需要導入模塊: from workflow.workflow import Workflow [as 別名]
# 或者: from workflow.workflow.Workflow import filter [as 別名]
#.........這裏部分代碼省略.........
self.assertRaises(PasswordNotFound,
self.wf.delete_password, self.account)
self.assertRaises(PasswordNotFound, self.wf.get_password, self.account)
self.wf.save_password(self.account, self.password)
self.assertEqual(self.wf.get_password(self.account), self.password)
self.assertEqual(self.wf.get_password(self.account, BUNDLE_ID),
self.password)
# try to set same password
self.wf.save_password(self.account, self.password)
self.assertEqual(self.wf.get_password(self.account), self.password)
# try to set different password
self.wf.save_password(self.account, self.password2)
self.assertEqual(self.wf.get_password(self.account), self.password2)
# bad call to _call_security
with self.assertRaises(KeychainError):
self.wf._call_security('pants', BUNDLE_ID, self.account)
def test_run_fails(self):
"""Run fails"""
def cb(wf):
self.assertEqual(wf, self.wf)
raise ValueError('Have an error')
self.wf.name # cause info.plist to be parsed
ret = self.wf.run(cb)
self.assertEqual(ret, 1)
# named after bundleid
self.wf = Workflow()
self.wf.bundleid
ret = self.wf.run(cb)
self.assertEqual(ret, 1)
def test_run_okay(self):
"""Run okay"""
def cb(wf):
self.assertEqual(wf, self.wf)
ret = self.wf.run(cb)
self.assertEqual(ret, 0)
def test_filter_all_rules(self):
"""Filter: all rules"""
results = self.wf.filter('test', self.search_items, key=lambda x: x[0],
ascending=True)
self.assertEqual(len(results), 8)
# now with scores, rules
results = self.wf.filter('test', self.search_items, key=lambda x: x[0],
include_score=True)
self.assertEqual(len(results), 8)
for item, score, rule in results:
self.wf.logger.debug('{} : {}'.format(item, score))
for value, r in self.search_items:
if value == item[0]:
self.assertEqual(rule, r)
# self.assertTrue(False)
def test_filter_no_caps(self):
"""Filter: no caps"""
results = self.wf.filter('test', self.search_items, key=lambda x: x[0],
ascending=True,
match_on=MATCH_ALL ^ MATCH_CAPITALS,
include_score=True)
self._print_results(results)
for item, score, rule in results:
self.assertNotEqual(rule, MATCH_CAPITALS)
# self.assertEqual(len(results), 7)
def test_filter_only_caps(self):
"""Filter: only caps"""
results = self.wf.filter('test', self.search_items, key=lambda x: x[0],
ascending=True,
match_on=MATCH_CAPITALS,
include_score=True)
self._print_results(results)
self.assertEqual(len(results), 1)
def test_filter_max_results(self):
"""Filter: max results"""
results = self.wf.filter('test', self.search_items, key=lambda x: x[0],
ascending=True, max_results=4)
self.assertEqual(len(results), 4)
def test_filter_min_score(self):
"""Filter: min score"""
results = self.wf.filter('test', self.search_items, key=lambda x: x[0],
ascending=True, min_score=90,
include_score=True)
self.assertEqual(len(results), 6)
def test_icons(self):
"""Icons"""
import workflow
for name in dir(workflow):
if name.startswith('ICON_'):
path = getattr(workflow, name)
print(name, path)
self.assert_(os.path.exists(path))
def _print_results(self, results):
"""Print results of Workflow.filter"""
for item, score, rule in results:
print('{0} (rule {1}) : {2}'.format(item[0], rule, score))
示例4: WorkflowTests
# 需要導入模塊: from workflow.workflow import Workflow [as 別名]
# 或者: from workflow.workflow.Workflow import filter [as 別名]
#.........這裏部分代碼省略.........
####################################################################
def test_cached_data(self):
"""Cached data stored"""
data = {'key1': 'value1'}
d = self.wf.cached_data('test', lambda: data, max_age=10)
self.assertEqual(data, d)
def test_cached_data_deleted(self):
"""Cached data deleted"""
data = {'key1': 'value1'}
d = self.wf.cached_data('test', lambda: data, max_age=10)
self.assertEqual(data, d)
ret = self.wf.cache_data('test', None)
self.assertEquals(ret, None)
self.assertFalse(os.path.exists(self.wf.cachefile('test.cpickle')))
# Test alternate code path for non-existent file
self.assertEqual(self.wf.cache_data('test', None), None)
def test_delete_all_cache_file(self):
"""Cached data are all deleted"""
data = {'key1': 'value1'}
test_file1 = 'test1.cpickle'
test_file2 = 'test2.cpickle'
self.wf.cached_data('test1', lambda: data, max_age=10)
self.wf.cached_data('test2', lambda: data, max_age=10)
self.assertTrue(os.path.exists(self.wf.cachefile(test_file1)))
self.assertTrue(os.path.exists(self.wf.cachefile(test_file2)))
self.wf.clear_cache()
self.assertFalse(os.path.exists(self.wf.cachefile(test_file1)))
self.assertFalse(os.path.exists(self.wf.cachefile(test_file2)))
def test_delete_all_cache_file_with_filter_func(self):
"""Only part of cached data are deleted"""
data = {'key1': 'value1'}
test_file1 = 'test1.cpickle'
test_file2 = 'test2.cpickle'
def filter_func(file):
if file == test_file1:
return True
else:
return False
self.wf.cached_data('test1', lambda: data, max_age=10)
self.wf.cached_data('test2', lambda: data, max_age=10)
self.assertTrue(os.path.exists(self.wf.cachefile(test_file1)))
self.assertTrue(os.path.exists(self.wf.cachefile(test_file2)))
self.wf.clear_cache(filter_func)
self.assertFalse(os.path.exists(self.wf.cachefile(test_file1)))
self.assertTrue(os.path.exists(self.wf.cachefile(test_file2)))
self.wf.clear_cache()
self.assertFalse(os.path.exists(self.wf.cachefile(test_file2)))
def test_cached_data_callback(self):
"""Cached data callback"""
called = {'called': False}
data = [1, 2, 3]
def getdata():
called['called'] = True
return data
d = self.wf.cached_data('test', getdata, max_age=10)
self.assertEqual(d, data)