本文整理匯總了Python中workflow.workflow.Workflow.cachefile方法的典型用法代碼示例。如果您正苦於以下問題:Python Workflow.cachefile方法的具體用法?Python Workflow.cachefile怎麽用?Python Workflow.cachefile使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類workflow.workflow.Workflow
的用法示例。
在下文中一共展示了Workflow.cachefile方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_magic_args
# 需要導入模塊: from workflow.workflow import Workflow [as 別名]
# 或者: from workflow.workflow.Workflow import cachefile [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_cachefile_is_unicode
# 需要導入模塊: from workflow.workflow import Workflow [as 別名]
# 或者: from workflow.workflow.Workflow import cachefile [as 別名]
def test_cachefile_is_unicode(self):
"""Workflow.cachefile returns Unicode"""
wf = Workflow()
self.assertTrue(isinstance(wf.cachefile(b'test.txt'), unicode))
self.assertTrue(isinstance(wf.cachefile('über.txt'), unicode))
self._teardown_env()
wf = Workflow()
self.assertTrue(isinstance(wf.cachefile(b'test.txt'), unicode))
self.assertTrue(isinstance(wf.cachefile('über.txt'), unicode))
示例3: test_delete_cache
# 需要導入模塊: from workflow.workflow import Workflow [as 別名]
# 或者: from workflow.workflow.Workflow import cachefile [as 別名]
def test_delete_cache(self):
"""Magic: delete cache"""
c = WorkflowMock(['script', 'workflow:delcache'])
wf = Workflow()
testpath = wf.cachefile('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_reset
# 需要導入模塊: from workflow.workflow import Workflow [as 別名]
# 或者: from workflow.workflow.Workflow import cachefile [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))
示例5: WorkflowTests
# 需要導入模塊: from workflow.workflow import Workflow [as 別名]
# 或者: from workflow.workflow.Workflow import cachefile [as 別名]
#.........這裏部分代碼省略.........
oargs = sys.argv[:]
sys.argv = [oargs[0]] + [s.encode('utf-8') for s in args]
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)
示例6: WorkflowTests
# 需要導入模塊: from workflow.workflow import Workflow [as 別名]
# 或者: from workflow.workflow.Workflow import cachefile [as 別名]
#.........這裏部分代碼省略.........
oargs = sys.argv[:]
sys.argv = [oargs[0]] + [s.encode('utf-8') for s in args]
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)
示例7: WorkflowTests
# 需要導入模塊: from workflow.workflow import Workflow [as 別名]
# 或者: from workflow.workflow.Workflow import cachefile [as 別名]
#.........這裏部分代碼省略.........
# cache original sys.argv
oargs = sys.argv[:]
# # 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_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.cache')))
# Test alternate code path for non-existent file
self.assertEqual(self.wf.cache_data('test', None), None)