本文整理匯總了Python中workflow.workflow.Workflow.cached_data方法的典型用法代碼示例。如果您正苦於以下問題:Python Workflow.cached_data方法的具體用法?Python Workflow.cached_data怎麽用?Python Workflow.cached_data使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類workflow.workflow.Workflow
的用法示例。
在下文中一共展示了Workflow.cached_data方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_magic_args
# 需要導入模塊: from workflow.workflow import Workflow [as 別名]
# 或者: from workflow.workflow.Workflow import cached_data [as 別名]
def test_magic_args(self):
"""Magic args"""
# cache original sys.argv
oargs = sys.argv[:]
# delsettings
sys.argv = [oargs[0]] + [b'workflow:delsettings']
try:
wf = Workflow(default_settings={'arg1': 'value1'})
self.assertEqual(wf.settings['arg1'], 'value1')
self.assertTrue(os.path.exists(wf.settings_path))
with self.assertRaises(SystemExit):
wf.args
self.assertFalse(os.path.exists(wf.settings_path))
finally:
sys.argv = oargs[:]
# delcache
sys.argv = [oargs[0]] + [b'workflow:delcache']
def somedata():
return {'arg1': 'value1'}
try:
wf = Workflow()
cachepath = wf.cachefile('somedir')
os.makedirs(cachepath)
wf.cached_data('test', somedata)
self.assertTrue(os.path.exists(wf.cachefile('test.cpickle')))
with self.assertRaises(SystemExit):
wf.args
self.assertFalse(os.path.exists(wf.cachefile('test.cpickle')))
finally:
sys.argv = oargs[:]
示例2: test_update
# 需要導入模塊: from workflow.workflow import Workflow [as 別名]
# 或者: from workflow.workflow.Workflow import cached_data [as 別名]
def test_update(self):
"""Workflow update methods"""
# Initialise with outdated version
wf = Workflow(update_settings={
'github_slug': 'deanishe/alfred-workflow-dummy',
'version': 'v2.0',
'frequency': 1,
})
# Check won't have completed yet
self.assertFalse(wf.update_available)
# wait for background update check
self.assertTrue(is_running('__workflow_update_check'))
while is_running('__workflow_update_check'):
time.sleep(0.05)
# There *is* a newer version in the repo
self.assertTrue(wf.update_available)
# Mock out subprocess and check the correct command is run
c = WorkflowMock()
with c:
self.assertTrue(wf.start_update())
# wf.logger.debug('start_update : {}'.format(c.cmd))
self.assertEquals(c.cmd[0], '/usr/bin/python')
self.assertEquals(c.cmd[2], '__workflow_update_install')
# Grab the updated release data, then reset the cache
update_info = wf.cached_data('__workflow_update_status')
wf.reset()
# Initialise with latest available release
wf = Workflow(update_settings={
'github_slug': 'deanishe/alfred-workflow-dummy',
'version': update_info['version'],
})
# Wait for background update check
self.assertTrue(is_running('__workflow_update_check'))
while is_running('__workflow_update_check'):
time.sleep(0.05)
# Remove version is same as the one we passed to Workflow
self.assertFalse(wf.update_available)
self.assertFalse(wf.start_update())
示例3: Workflow
# 需要導入模塊: from workflow.workflow import Workflow [as 別名]
# 或者: from workflow.workflow.Workflow import cached_data [as 別名]
from __future__ import unicode_literals
import main
from fuzzywuzzy import process
from workflow.workflow import Workflow
wf = Workflow()
UPDATE_INTERVAL = 3600 * 3
localCache = wf.cached_data('usernameList')
def username_lookup(username):
if not wf.cached_data_fresh('usernameList', max_age=UPDATE_INTERVAL) or wf.cached_data('hostIdList') is None:
main.update_caches()
match_found = localCache.get(str(username))
if match_found < 1:
results = process.extract(username, localCache.keys(), limit=3)
fuzzy_match(results, username)
else:
exact_match(match_found, username)
# spits back the top five results, this will have to be relayed to the workflow and then user selected
# once it does we have the key for the map and we can get the id.
def fuzzy_match(results, username):
for bad_variable_name in results:
info = localCache.get(bad_variable_name[0])
host_id = info[0][0]
hostname = info[0][1]
wf.add_item(title=bad_variable_name[0],
subtitle=username + ' ' + ' \u2318-Click to copy username; ',
示例4: WorkflowTests
# 需要導入模塊: from workflow.workflow import Workflow [as 別名]
# 或者: from workflow.workflow.Workflow import cached_data [as 別名]
#.........這裏部分代碼省略.........
# # openlog
# sys.argv = [oargs[0]] + [b'workflow:openlog']
# try:
# wf = Workflow()
# wf.logger.debug('This is a test message') # ensure log file exists
# with self.assertRaises(SystemExit):
# wf.args
# finally:
# sys.argv = oargs[:]
# delsettings
sys.argv = [oargs[0]] + [b"workflow:delsettings"]
try:
wf = Workflow(default_settings={"arg1": "value1"})
self.assertEqual(wf.settings["arg1"], "value1")
self.assertTrue(os.path.exists(wf.settings_path))
with self.assertRaises(SystemExit):
wf.args
self.assertFalse(os.path.exists(wf.settings_path))
finally:
sys.argv = oargs[:]
# delcache
sys.argv = [oargs[0]] + [b"workflow:delcache"]
def somedata():
return {"arg1": "value1"}
try:
wf = Workflow()
cachepath = wf.cachefile("somedir")
os.makedirs(cachepath)
wf.cached_data("test", somedata)
self.assertTrue(os.path.exists(wf.cachefile("test.cache")))
with self.assertRaises(SystemExit):
wf.args
self.assertFalse(os.path.exists(wf.cachefile("test.cache")))
finally:
sys.argv = oargs[:]
def test_logger(self):
"""Logger"""
self.assert_(isinstance(self.wf.logger, logging.Logger))
logger = logging.Logger("")
self.wf.logger = logger
self.assertEqual(self.wf.logger, logger)
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_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)
self.assertTrue(called["called"])
示例5: WorkflowTests
# 需要導入模塊: from workflow.workflow import Workflow [as 別名]
# 或者: from workflow.workflow.Workflow import cached_data [as 別名]
#.........這裏部分代碼省略.........
# # openlog
# sys.argv = [oargs[0]] + [b'workflow:openlog']
# try:
# wf = Workflow()
# wf.logger.debug('This is a test message') # ensure log file exists
# with self.assertRaises(SystemExit):
# wf.args
# finally:
# sys.argv = oargs[:]
# delsettings
sys.argv = [oargs[0]] + [b'workflow:delsettings']
try:
wf = Workflow(default_settings={'arg1': 'value1'})
self.assertEqual(wf.settings['arg1'], 'value1')
self.assertTrue(os.path.exists(wf.settings_path))
with self.assertRaises(SystemExit):
wf.args
self.assertFalse(os.path.exists(wf.settings_path))
finally:
sys.argv = oargs[:]
# delcache
sys.argv = [oargs[0]] + [b'workflow:delcache']
def somedata():
return {'arg1': 'value1'}
try:
wf = Workflow()
cachepath = wf.cachefile('somedir')
os.makedirs(cachepath)
wf.cached_data('test', somedata)
self.assertTrue(os.path.exists(wf.cachefile('test.cache')))
with self.assertRaises(SystemExit):
wf.args
self.assertFalse(os.path.exists(wf.cachefile('test.cache')))
finally:
sys.argv = oargs[:]
def test_logger(self):
"""Logger"""
self.assert_(isinstance(self.wf.logger, logging.Logger))
logger = logging.Logger('')
self.wf.logger = logger
self.assertEqual(self.wf.logger, logger)
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_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)
self.assertTrue(called['called'])
示例6: WorkflowTests
# 需要導入模塊: from workflow.workflow import Workflow [as 別名]
# 或者: from workflow.workflow.Workflow import cached_data [as 別名]
#.........這裏部分代碼省略.........
wf = Workflow(normalization='NFD')
try:
self.assertEqual(wf.args, args)
finally:
sys.argv = oargs[:]
def test_magic_args(self):
"""Magic args"""
# cache original sys.argv
oargs = sys.argv[:]
# delsettings
sys.argv = [oargs[0]] + [b'workflow:delsettings']
try:
wf = Workflow(default_settings={'arg1': 'value1'})
self.assertEqual(wf.settings['arg1'], 'value1')
self.assertTrue(os.path.exists(wf.settings_path))
with self.assertRaises(SystemExit):
wf.args
self.assertFalse(os.path.exists(wf.settings_path))
finally:
sys.argv = oargs[:]
# delcache
sys.argv = [oargs[0]] + [b'workflow:delcache']
def somedata():
return {'arg1': 'value1'}
try:
wf = Workflow()
cachepath = wf.cachefile('somedir')
os.makedirs(cachepath)
wf.cached_data('test', somedata)
self.assertTrue(os.path.exists(wf.cachefile('test.cpickle')))
with self.assertRaises(SystemExit):
wf.args
self.assertFalse(os.path.exists(wf.cachefile('test.cpickle')))
finally:
sys.argv = oargs[:]
def test_logger(self):
"""Logger"""
self.assert_(isinstance(self.wf.logger, logging.Logger))
logger = logging.Logger('')
self.wf.logger = logger
self.assertEqual(self.wf.logger, logger)
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_cached_data_callback(self):
示例7: WorkflowTests
# 需要導入模塊: from workflow.workflow import Workflow [as 別名]
# 或者: from workflow.workflow.Workflow import cached_data [as 別名]
#.........這裏部分代碼省略.........
wf = Workflow(normalization='NFD')
try:
self.assertEqual(wf.args, args)
finally:
sys.argv = oargs[:]
def test_magic_args(self):
"""Magic args"""
# cache original sys.argv
oargs = sys.argv[:]
# delsettings
sys.argv = [oargs[0]] + [b'workflow:delsettings']
try:
wf = Workflow(default_settings={'arg1': 'value1'})
self.assertEqual(wf.settings['arg1'], 'value1')
self.assertTrue(os.path.exists(wf.settings_path))
self.assertRaises(SystemExit, lambda wf: wf.args, wf)
self.assertFalse(os.path.exists(wf.settings_path))
finally:
sys.argv = oargs[:]
# delcache
sys.argv = [oargs[0]] + [b'workflow:delcache']
def somedata():
return {'arg1': 'value1'}
try:
wf = Workflow()
cachepath = wf.cachefile('somedir')
os.makedirs(cachepath)
wf.cached_data('test', somedata)
self.assertTrue(os.path.exists(wf.cachefile('test.cpickle')))
self.assertRaises(SystemExit, lambda wf: wf.args, wf)
self.assertFalse(os.path.exists(wf.cachefile('test.cpickle')))
finally:
sys.argv = oargs[:]
def test_logger(self):
"""Logger"""
self.assert_(isinstance(self.wf.logger, logging.Logger))
logger = logging.Logger('')
self.wf.logger = logger
self.assertEqual(self.wf.logger, logger)
####################################################################
# Cached data
####################################################################
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