当前位置: 首页>>代码示例>>Python>>正文


Python Workflow.cachefile方法代码示例

本文整理汇总了Python中workflow.Workflow.cachefile方法的典型用法代码示例。如果您正苦于以下问题:Python Workflow.cachefile方法的具体用法?Python Workflow.cachefile怎么用?Python Workflow.cachefile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在workflow.Workflow的用法示例。


在下文中一共展示了Workflow.cachefile方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_magic_args

# 需要导入模块: from workflow import Workflow [as 别名]
# 或者: from workflow.Workflow import cachefile [as 别名]
def test_magic_args(alfred4):
    """Magic args"""
    # cache original sys.argv
    oargs = sys.argv[:]

    # delsettings
    sys.argv = [oargs[0]] + [b'workflow:delsettings']
    try:
        wf = Workflow(default_settings={'arg1': 'value1'})
        assert wf.settings['arg1'] == 'value1'
        assert os.path.exists(wf.settings_path)
        with pytest.raises(SystemExit):
            wf.args
        assert not 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)
        assert os.path.exists(wf.cachefile('test.cpickle'))
        with pytest.raises(SystemExit):
            wf.args
        assert not os.path.exists(wf.cachefile('test.cpickle'))
    finally:
        sys.argv = oargs[:]
开发者ID:deanishe,项目名称:alfred-workflow,代码行数:36,代码来源:test_workflow.py

示例2: test_delete_cache

# 需要导入模块: from workflow import Workflow [as 别名]
# 或者: from workflow.Workflow import cachefile [as 别名]
def test_delete_cache(info2):
    """Magic: delete cache"""
    with WorkflowMock(['script', 'workflow:delcache']):
        wf = Workflow()
        testpath = wf.cachefile('file.test')
        with open(testpath, 'wb') as fp:
            fp.write('test!')

        assert os.path.exists(testpath)
        # Process magic arguments
        wf.args
        assert not os.path.exists(testpath)
开发者ID:optionalg,项目名称:alfred-workflow,代码行数:14,代码来源:test_workflow_magic.py

示例3: BackgroundTests

# 需要导入模块: from workflow import Workflow [as 别名]
# 或者: from workflow.Workflow import cachefile [as 别名]
class BackgroundTests(unittest.TestCase):

    def setUp(self):
        self.wf = Workflow()

    def _pidfile(self, name):
        return self.wf.cachefile('{}.pid'.format(name))

    def _write_pidfile(self, name, pid):
        pidfile = self._pidfile(name)
        with open(pidfile, 'wb') as file:
            file.write('{}'.format(pid))

    def _delete_pidfile(self, name):
        pidfile = self._pidfile(name)
        if os.path.exists(pidfile):
            os.unlink(pidfile)

    def test_no_pidfile(self):
        """No pidfile"""
        self.assertFalse(is_running('boomstick'))

    def test_non_existent_process(self):
        """Non-existent process"""
        self._write_pidfile('test', 9999999)
        self.assertFalse(is_running('test'))
        self.assertFalse(os.path.exists(self._pidfile('test')))

    def test_existing_process(self):
        """Existing process"""
        self._write_pidfile('test', os.getpid())
        self.assertTrue(is_running('test'))
        self.assertTrue(os.path.exists(self._pidfile('test')))
        self._delete_pidfile('test')

    def test_run_in_background(self):
        """Run in background"""
        cmd = ['sleep', '1']
        run_in_background('test', cmd)
        sleep(0.5)
        self.assertTrue(is_running('test'))
        self.assertTrue(os.path.exists(self._pidfile('test')))
        self.assertEqual(run_in_background('test', cmd), None)
        sleep(0.6)
        self.assertFalse(is_running('test'))
        self.assertFalse(os.path.exists(self._pidfile('test')))
开发者ID:JT5D,项目名称:Alfred-Popclip-Sublime,代码行数:48,代码来源:test_background.py

示例4: test_reset

# 需要导入模块: from workflow import Workflow [as 别名]
# 或者: from workflow.Workflow import cachefile [as 别名]
def test_reset(info2):
    """Magic: reset"""
    with WorkflowMock(['script', 'workflow: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):
            assert os.path.exists(p)

        # Process magic arguments
        wf.args

        for p in (datatest, cachetest, settings_path):
            assert not os.path.exists(p)
开发者ID:optionalg,项目名称:alfred-workflow,代码行数:23,代码来源:test_workflow_magic.py

示例5: Copyright

# 需要导入模块: from workflow import Workflow [as 别名]
# 或者: from workflow.Workflow import cachefile [as 别名]
#!/usr/bin/env python
# encoding: utf-8
#
# Copyright (c) 2014 [email protected]
#
# MIT Licence. See http://opensource.org/licenses/MIT
#
# Created on 2014-07-03
#

"""Common settings."""

from __future__ import unicode_literals

from workflow import Workflow

wf = Workflow()

INDEX_DB = wf.cachefile('index.db')
DATA_FILE = wf.workflowfile('books.tsv')
开发者ID:deanishe,项目名称:alfred-index-demo,代码行数:22,代码来源:config.py


注:本文中的workflow.Workflow.cachefile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。