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


Python Workflow.clear_cache方法代码示例

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


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

示例1: WorkflowTests

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

    def setUp(self):
        self.libs = [os.path.join(os.path.dirname(__file__), 'lib')]
        self.wf = Workflow(libraries=self.libs)
        self.account = 'this-is-my-test-account'
        self.password = 'this-is-my-safe-password'
        self.password2 = 'this-is-my-other-safe-password'
        self.search_items = [
            ('Test Item One', MATCH_STARTSWITH),
            ('test item two', MATCH_STARTSWITH),
            ('TwoExtraSpecialTests', MATCH_CAPITALS),
            ('this-is-a-test', MATCH_ATOM),
            ('the extra special trials', MATCH_INITIALS_STARTSWITH),
            ('not the extra special trials', MATCH_INITIALS_CONTAIN),
            ('intestinal fortitude', MATCH_SUBSTRING),
            ('the splits', MATCH_ALLCHARS),
            ('nomatch', 0),
        ]

    def tearDown(self):
        self.wf.clear_cache()
        self.wf.clear_settings()
        try:
            self.wf.delete_password(self.account)
        except PasswordNotFound:
            pass
        for dirpath in (self.wf.cachedir, self.wf.datadir):
            if os.path.exists(dirpath):
                shutil.rmtree(dirpath)

    def test_item_creation(self):
        """XML generation"""
        self.wf.add_item('title', 'subtitle', 'arg',
                         autocomplete='autocomplete',
                         valid=True, uid='uid', icon='icon.png',
                         icontype='fileicon',
                         type='file')
        stdout = sys.stdout
        sio = StringIO()
        sys.stdout = sio
        self.wf.send_feedback()
        sys.stdout = stdout
        output = sio.getvalue()
        sio.close()
        # pprint(output)
        root = ET.fromstring(output)
        item = list(root)[0]
        self.assertEqual(item.attrib['uid'], 'uid')
        self.assertEqual(item.attrib['autocomplete'], 'autocomplete')
        self.assertEqual(item.attrib['valid'], 'yes')
        self.assertEqual(item.attrib['uid'], 'uid')
        title, subtitle, arg, icon = list(item)
        self.assertEqual(title.text, 'title')
        self.assertEqual(title.tag, 'title')
        self.assertEqual(subtitle.text, 'subtitle')
        self.assertEqual(subtitle.tag, 'subtitle')
        self.assertEqual(arg.text, 'arg')
        self.assertEqual(arg.tag, 'arg')
        self.assertEqual(icon.text, 'icon.png')
        self.assertEqual(icon.tag, 'icon')
        self.assertEqual(icon.attrib['type'], 'fileicon')

    def test_item_creation_no_optionals(self):
        """XML generation (no optionals)"""
        self.wf.add_item('title',
                         valid=False)
        stdout = sys.stdout
        sio = StringIO()
        sys.stdout = sio
        self.wf.send_feedback()
        sys.stdout = stdout
        output = sio.getvalue()
        sio.close()
        # pprint(output)
        root = ET.fromstring(output)
        item = list(root)[0]
        for key in ['uid', 'arg', 'autocomplete']:
            self.assertFalse(key in item.attrib)
        self.assertEqual(item.attrib['valid'], 'no')
        title, subtitle = list(item)
        self.assertEqual(title.text, 'title')
        self.assertEqual(title.tag, 'title')
        self.assertEqual(subtitle.text, None)
        tags = [elem.tag for elem in list(item)]
        for tag in ['icon', 'arg']:
            self.assert_(tag not in tags)

    def test_additional_libs(self):
        """Additional libraries"""
        for path in self.libs:
            self.assert_(path in sys.path)
        self.assertEqual(sys.path[0:len(self.libs)], self.libs)
        import youcanimportme

    def test_info_plist(self):
        """info.plist"""
        self.assertEqual(self.wf.name, WORKFLOW_NAME)
        self.assertEqual(self.wf.bundleid, BUNDLE_ID)

#.........这里部分代码省略.........
开发者ID:hellohano,项目名称:alfred-workflow,代码行数:103,代码来源:test_workflow.py

示例2: WorkflowTests

# 需要导入模块: from workflow.workflow import Workflow [as 别名]
# 或者: from workflow.workflow.Workflow import clear_cache [as 别名]
class WorkflowTests(unittest.TestCase):
    def setUp(self):
        self.libs = [os.path.join(os.path.dirname(__file__), "lib")]
        self.wf = Workflow(libraries=self.libs)
        self.account = "this-is-my-test-account"
        self.password = "this-is-my-safe-password"
        self.password2 = "this-is-my-other-safe-password"
        self.search_items = [
            ("Test Item One", MATCH_STARTSWITH),
            ("test item two", MATCH_STARTSWITH),
            ("TwoExtraSpecialTests", MATCH_CAPITALS),
            ("this-is-a-test", MATCH_ATOM),
            ("the extra special trials", MATCH_INITIALS_STARTSWITH),
            ("not the extra special trials", MATCH_INITIALS_CONTAIN),
            ("intestinal fortitude", MATCH_SUBSTRING),
            ("the splits", MATCH_ALLCHARS),
            ("nomatch", 0),
        ]

        self.search_items_diacritics = [
            # search key, query
            ("Änderungen vorbehalten", "av"),
            ("Änderungen", "anderungen"),
            ("überwiegend bewolkt", "ub"),
            ("überwiegend", "uberwiegend"),
            ("Öffnungszeiten an Feiertagen", "offnungszeiten"),
            ("Öffnungszeiten an Feiertagen", "oaf"),
            ("Fußpilz", "fuss"),
            ("salé", "sale"),
        ]

    def tearDown(self):
        self.wf.clear_cache()
        self.wf.clear_settings()
        try:
            self.wf.delete_password(self.account)
        except PasswordNotFound:
            pass
        for dirpath in (self.wf.cachedir, self.wf.datadir):
            if os.path.exists(dirpath):
                shutil.rmtree(dirpath)

    def test_item_creation(self):
        """XML generation"""
        self.wf.add_item(
            "title",
            "subtitle",
            "arg",
            autocomplete="autocomplete",
            valid=True,
            uid="uid",
            icon="icon.png",
            icontype="fileicon",
            type="file",
        )
        stdout = sys.stdout
        sio = StringIO()
        sys.stdout = sio
        self.wf.send_feedback()
        sys.stdout = stdout
        output = sio.getvalue()
        sio.close()
        # pprint(output)
        root = ET.fromstring(output)
        item = list(root)[0]
        self.assertEqual(item.attrib["uid"], "uid")
        self.assertEqual(item.attrib["autocomplete"], "autocomplete")
        self.assertEqual(item.attrib["valid"], "yes")
        self.assertEqual(item.attrib["uid"], "uid")
        title, subtitle, arg, icon = list(item)
        self.assertEqual(title.text, "title")
        self.assertEqual(title.tag, "title")
        self.assertEqual(subtitle.text, "subtitle")
        self.assertEqual(subtitle.tag, "subtitle")
        self.assertEqual(arg.text, "arg")
        self.assertEqual(arg.tag, "arg")
        self.assertEqual(icon.text, "icon.png")
        self.assertEqual(icon.tag, "icon")
        self.assertEqual(icon.attrib["type"], "fileicon")

    def test_item_creation_no_optionals(self):
        """XML generation (no optionals)"""
        self.wf.add_item("title", valid=False)
        stdout = sys.stdout
        sio = StringIO()
        sys.stdout = sio
        self.wf.send_feedback()
        sys.stdout = stdout
        output = sio.getvalue()
        sio.close()
        # pprint(output)
        root = ET.fromstring(output)
        item = list(root)[0]
        for key in ["uid", "arg", "autocomplete"]:
            self.assertFalse(key in item.attrib)
        self.assertEqual(item.attrib["valid"], "no")
        title, subtitle = list(item)
        self.assertEqual(title.text, "title")
        self.assertEqual(title.tag, "title")
        self.assertEqual(subtitle.text, None)
#.........这里部分代码省略.........
开发者ID:JT5D,项目名称:Alfred-Popclip-Sublime,代码行数:103,代码来源:test_workflow.py

示例3: WorkflowTests

# 需要导入模块: from workflow.workflow import Workflow [as 别名]
# 或者: from workflow.workflow.Workflow import clear_cache [as 别名]

#.........这里部分代码省略.........
        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
        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
开发者ID:optionalg,项目名称:alfred-workflow,代码行数:70,代码来源:test_workflow.py


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