本文整理匯總了Python中workflow.workflow.Workflow.datafile方法的典型用法代碼示例。如果您正苦於以下問題:Python Workflow.datafile方法的具體用法?Python Workflow.datafile怎麽用?Python Workflow.datafile使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類workflow.workflow.Workflow
的用法示例。
在下文中一共展示了Workflow.datafile方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_datafile_is_unicode
# 需要導入模塊: from workflow.workflow import Workflow [as 別名]
# 或者: from workflow.workflow.Workflow import datafile [as 別名]
def test_datafile_is_unicode(self):
"""Workflow.datafile returns Unicode"""
wf = Workflow()
self.assertTrue(isinstance(wf.datafile(b'test.txt'), unicode))
self.assertTrue(isinstance(wf.datafile('über.txt'), unicode))
self._teardown_env()
wf = Workflow()
self.assertTrue(isinstance(wf.datafile(b'test.txt'), unicode))
self.assertTrue(isinstance(wf.datafile('über.txt'), unicode))
示例2: test_reset
# 需要導入模塊: from workflow.workflow import Workflow [as 別名]
# 或者: from workflow.workflow.Workflow import datafile [as 別名]
def test_reset(self):
"""Magic: reset"""
wf = Workflow()
wf.settings['key'] = 'value'
datatest = wf.datafile('data.test')
cachetest = wf.cachefile('cache.test')
settings_path = wf.datafile('settings.json')
for p in (datatest, cachetest):
with open(p, 'wb') as file_obj:
file_obj.write('test!')
for p in (datatest, cachetest, settings_path):
self.assertTrue(os.path.exists(p))
c = WorkflowMock(['script', 'workflow:reset'])
with c:
wf.args
for p in (datatest, cachetest, settings_path):
self.assertFalse(os.path.exists(p))
示例3: test_delete_data
# 需要導入模塊: from workflow.workflow import Workflow [as 別名]
# 或者: from workflow.workflow.Workflow import datafile [as 別名]
def test_delete_data(self):
"""Magic: delete data"""
c = WorkflowMock(['script', 'workflow:deldata'])
wf = Workflow()
testpath = wf.datafile('file.test')
with open(testpath, 'wb') as file_obj:
file_obj.write('test!')
with c:
self.assertTrue(os.path.exists(testpath))
# Process magic arguments
wf.args
self.assertFalse(os.path.exists(testpath))
示例4: test_delete_settings
# 需要導入模塊: from workflow.workflow import Workflow [as 別名]
# 或者: from workflow.workflow.Workflow import datafile [as 別名]
def test_delete_settings(self):
"""Magic: delete settings"""
c = WorkflowMock(['script', 'workflow:delsettings'])
wf = Workflow()
wf.settings['key'] = 'value'
filepath = wf.datafile('settings.json')
with c:
self.assertTrue(os.path.exists(filepath))
wf2 = Workflow()
self.assertEquals(wf2.settings.get('key'), 'value')
# Process magic arguments
wf.args
self.assertFalse(os.path.exists(filepath))
wf3 = Workflow()
self.assertFalse('key' in wf3.settings)
示例5: WorkflowTests
# 需要導入模塊: from workflow.workflow import Workflow [as 別名]
# 或者: from workflow.workflow.Workflow import datafile [as 別名]
#.........這裏部分代碼省略.........
"""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_filter_folding(self):
"""Filter: diacritic folding"""
for key, query in self.search_items_diacritics:
results = self.wf.filter(query, [key], min_score=90,
include_score=True)
self.assertEqual(len(results), 1)
def test_filter_no_folding(self):
"""Filter: folding turned off for non-ASCII query"""
data = ['fühler', 'fuhler', 'fübar', 'fubar']
results = self.wf.filter('fü', data)
self.assertEquals(len(results), 2)
def test_filter_folding_off(self):
"""Filter: diacritic folding off"""
for key, query in self.search_items_diacritics:
results = self.wf.filter(query, [key], min_score=90,
include_score=True,
fold_diacritics=False)
self.assertEqual(len(results), 0)
def test_filter_folding_force_on(self):
"""Filter: diacritic folding forced on"""
self.wf.settings['__workflows_diacritic_folding'] = True
for key, query in self.search_items_diacritics:
results = self.wf.filter(query, [key], min_score=90,
include_score=True,
fold_diacritics=False)
self.assertEqual(len(results), 1)
def test_filter_folding_force_off(self):
"""Filter: diacritic folding forced off"""
self.wf.settings['__workflows_diacritic_folding'] = False
for key, query in self.search_items_diacritics:
results = self.wf.filter(query, [key], min_score=90,
include_score=True)
self.assertEqual(len(results), 0)
def test_filter_empty_key(self):
"""Filter: empty keys are ignored"""
data = ['bob', 'sue', 'henry']
def key(s):
return ''
results = self.wf.filter('lager', data, key)
self.assertEquals(len(results), 0)
def test_filter_empty_query_words(self):
"""Filter: empty query words are ignored"""
data = ['bob', 'sue', 'henry']
results = self.wf.filter(' ', data)
self.assertEquals(len(results), 0)
def test_filter_identical_items(self):
"""Filter: identical items are not discarded"""
data = ['bob', 'bob', 'bob']
results = self.wf.filter('bob', data)
self.assertEquals(len(results), len(data))
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('{!r} (rule {}) : {}'.format(item[0], rule, score))
def _stored_data_paths(self, name, serializer):
"""Return list of paths created when storing data"""
metadata = self.wf.datafile('.{}.alfred-workflow'.format(name))
datapath = self.wf.datafile('{}.{}'.format(name, serializer))
return [metadata, datapath]
示例6: WorkflowTests
# 需要導入模塊: from workflow.workflow import Workflow [as 別名]
# 或者: from workflow.workflow.Workflow import datafile [as 別名]
#.........這裏部分代碼省略.........
def test_invalid_data_serializer(self):
"""Invalid data serializer"""
data = {'key7': 'value7'}
self.assertRaises(ValueError, self.wf.store_data, 'test', data,
'spong')
####################################################################
# Data deletion
####################################################################
def test_delete_stored_data(self):
"""Delete stored data"""
data = {'key7': 'value7'}
paths = self._stored_data_paths('test', 'cpickle')
self.wf.store_data('test', data)
self.assertEqual(data, self.wf.stored_data('test'))
self.wf.store_data('test', None)
self.assertEqual(None, self.wf.stored_data('test'))
for p in paths:
self.assertFalse(os.path.exists(p))
def test_delete_all_stored_data_file(self):
"""Stored data are all deleted"""
data = {'key1': 'value1'}
test_file1 = 'test1.cpickle'
test_file2 = 'test2.cpickle'
self.wf.store_data('test1', data)
self.wf.store_data('test2', data)
self.assertTrue(os.path.exists(self.wf.datafile(test_file1)))
self.assertTrue(os.path.exists(self.wf.datafile(test_file2)))
self.wf.clear_data()
self.assertFalse(os.path.exists(self.wf.datafile(test_file1)))
self.assertFalse(os.path.exists(self.wf.datafile(test_file2)))
def test_delete_all_data_file_with_filter_func(self):
"""Only part of stored 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.store_data('test1', data)
self.wf.store_data('test2', data)
self.assertTrue(os.path.exists(self.wf.datafile(test_file1)))
self.assertTrue(os.path.exists(self.wf.datafile(test_file2)))
self.wf.clear_data(filter_func)
self.assertFalse(os.path.exists(self.wf.datafile(test_file1)))
self.assertTrue(os.path.exists(self.wf.datafile(test_file2)))
self.wf.clear_data()
self.assertFalse(os.path.exists(self.wf.datafile(test_file2)))
####################################################################
# Keychain
####################################################################