Esempio n. 1
0
    def testCacheExpired(self):
        """
        Test the `cache_expired` utilitarian function. Delta is in hours
        """
        # file-like object is always considered expired
        fcache = tempfile.NamedTemporaryFile(prefix="testIsFile", delete=True)
        self.assertTrue(cache_expired(fcache, delta=0))
        self.assertTrue(cache_expired(fcache, delta=100))
        fcache.close()
        self.assertTrue(cache_expired(fcache, delta=0))
        self.assertTrue(cache_expired(fcache, delta=100))

        # path to a file that does not exist, always expired
        newfile = fcache.name + 'testCacheExpired'
        self.assertTrue(cache_expired(newfile, delta=0))
        self.assertTrue(cache_expired(newfile, delta=100))

        # now create and write something to it
        with open(newfile, 'w') as f:
            f.write("whatever")

        self.assertFalse(cache_expired(newfile, delta=1))
        time.sleep(1)
        self.assertTrue(cache_expired(newfile, delta=0))
        self.assertFalse(cache_expired(newfile, delta=1))
Esempio n. 2
0
    def testCacheExpired(self):
        """
        Test the `cache_expired` utilitarian function. Delta is in hours
        """
        # file-like object is always considered expired
        fcache = tempfile.NamedTemporaryFile(prefix="testIsFile", delete=True)
        self.assertTrue(cache_expired(fcache, delta=0))
        self.assertTrue(cache_expired(fcache, delta=100))
        fcache.close()
        self.assertTrue(cache_expired(fcache, delta=0))
        self.assertTrue(cache_expired(fcache, delta=100))

        # path to a file that does not exist, always expired
        newfile = fcache.name + 'testCacheExpired'
        self.assertTrue(cache_expired(newfile, delta=0))
        self.assertTrue(cache_expired(newfile, delta=100))

        # now create and write something to it
        with open(newfile, 'w') as f:
            f.write("whatever")

        self.assertFalse(cache_expired(newfile, delta=1))
        time.sleep(1)
        self.assertTrue(cache_expired(newfile, delta=0))
        self.assertFalse(cache_expired(newfile, delta=1))