當前位置: 首頁>>代碼示例>>Python>>正文


Python FileCache.flush方法代碼示例

本文整理匯總了Python中tweepy.FileCache.flush方法的典型用法代碼示例。如果您正苦於以下問題:Python FileCache.flush方法的具體用法?Python FileCache.flush怎麽用?Python FileCache.flush使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在tweepy.FileCache的用法示例。


在下文中一共展示了FileCache.flush方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: TweepyCacheTests

# 需要導入模塊: from tweepy import FileCache [as 別名]
# 或者: from tweepy.FileCache import flush [as 別名]
class TweepyCacheTests(unittest.TestCase):
    timeout = 0.5
    memcache_servers = ['127.0.0.1:11211']  # must be running for test to pass

    def _run_tests(self, do_cleanup=True):
        # test store and get
        self.cache.store('testkey', 'testvalue')
        self.assertEqual(self.cache.get('testkey'), 'testvalue',
            'Stored value does not match retrieved value')

        # test timeout
        time.sleep(self.timeout)
        self.assertEqual(self.cache.get('testkey'), None,
            'Cache entry should have expired')

        # test cleanup
        if do_cleanup:
            self.cache.store('testkey', 'testvalue')
            time.sleep(self.timeout)
            self.cache.cleanup()
            self.assertEqual(self.cache.count(), 0, 'Cache cleanup failed')

        # test count
        for i in range(0, 20):
            self.cache.store('testkey%i' % i, 'testvalue')
        self.assertEqual(self.cache.count(), 20, 'Count is wrong')

        # test flush
        self.cache.flush()
        self.assertEqual(self.cache.count(), 0, 'Cache failed to flush')

    def testmemorycache(self):
        self.cache = MemoryCache(timeout=self.timeout)
        self._run_tests()

    def testfilecache(self):
        os.mkdir('cache_test_dir')
        try:
            self.cache = FileCache('cache_test_dir', self.timeout)
            self._run_tests()
            self.cache.flush()
        finally:
            if os.path.exists('cache_test_dir'):
                shutil.rmtree('cache_test_dir')
開發者ID:Kjwon15,項目名稱:tweepy,代碼行數:46,代碼來源:test_api.py

示例2: TweepyCacheTests

# 需要導入模塊: from tweepy import FileCache [as 別名]
# 或者: from tweepy.FileCache import flush [as 別名]
class TweepyCacheTests(unittest.TestCase):

    timeout = 2.0
    memcache_servers = ["127.0.0.1:11211"]  # must be running for test to pass

    def _run_tests(self, do_cleanup=True):
        # test store and get
        self.cache.store("testkey", "testvalue")
        self.assertEqual(self.cache.get("testkey"), "testvalue", "Stored value does not match retrieved value")

        # test timeout
        sleep(self.timeout)
        self.assertEqual(self.cache.get("testkey"), None, "Cache entry should have expired")

        # test cleanup
        if do_cleanup:
            self.cache.store("testkey", "testvalue")
            sleep(self.timeout)
            self.cache.cleanup()
            self.assertEqual(self.cache.count(), 0, "Cache cleanup failed")

        # test count
        for i in range(0, 20):
            self.cache.store("testkey%i" % i, "testvalue")
        self.assertEqual(self.cache.count(), 20, "Count is wrong")

        # test flush
        self.cache.flush()
        self.assertEqual(self.cache.count(), 0, "Cache failed to flush")

    def testmemorycache(self):
        self.cache = MemoryCache(timeout=self.timeout)
        self._run_tests()

    def testfilecache(self):
        os.mkdir("cache_test_dir")
        self.cache = FileCache("cache_test_dir", self.timeout)
        self._run_tests()
        self.cache.flush()
        os.rmdir("cache_test_dir")
開發者ID:QiaozhiWang,項目名稱:tweepy,代碼行數:42,代碼來源:tests.py


注:本文中的tweepy.FileCache.flush方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。