def test_retrieve_file_notfound(self): c = LocalFilesystemCache(self.remotebase) tmppath = c.temppath with self.assertRaises(IOError) as cm: c.retrieve("fileB") self.assertEqual(cm.exception.errno, 2) del c
def test_retrieve_file_list(self): c = LocalFilesystemCache(self.remotebase) tmppath = c.temppath c.retrieve(["fileA", os.path.join("dirA", "fileA")]) self.assertTrue(os.path.isfile(c("fileA"))) self.assertTrue(os.path.isfile(c(os.path.join("dirA", "fileA")))) del c
def test_clean_pattern(self): c = LocalFilesystemCache(self.remotebase) tmppath = c.temppath c.retrieve(["fileA", os.path.join("dirA", "fileA")]) c.clean("f*") self.assertEqual(os.listdir(c.temppath), ["dirA"]) self.assertEqual(c._files.keys(), [os.path.join("dirA", "fileA")]) del c
def test_clean_all(self): c = LocalFilesystemCache(self.remotebase) tmppath = c.temppath c.retrieve(["fileA", os.path.join("dirA", "fileA")]) c.clean() self.assertEqual(os.listdir(c.temppath), []) self.assertEqual(c._files, {}) del c
def test_clean_datetime(self): # TODO: repeat several times c = LocalFilesystemCache(self.remotebase) tmppath = c.temppath t0 = datetime.datetime.now() c.retrieve("fileA") time.sleep(0.5) t1 = datetime.datetime.now() c.retrieve(os.path.join("dirA", "fileA")) time.sleep(0.5) c.clean(time=t0 + datetime.timedelta(milliseconds=100)) self.assertEqual(os.listdir(c.temppath), ["dirA"]) self.assertEqual(c._files.keys(), [os.path.join("dirA", "fileA")]) del c
def test_retrieve_dir(self): c = LocalFilesystemCache(self.remotebase) tmppath = c.temppath lpath = c.retrieve(os.path.join("dirA", "fileA")) self.assertTrue(os.path.isfile(os.path.join(tmppath, "dirA", "fileA"))) self.assertEqual(lpath, os.path.join(tmppath, "dirA", "fileA")) del c
def test_retrieve_file(self): c = LocalFilesystemCache(self.remotebase) tmppath = c.temppath t0 = datetime.datetime.now() lpath = c.retrieve("fileA") t1 = datetime.datetime.now() self.assertTrue(t0 < c._files["fileA"][1] < t1) del c
def test_retrieve_file_call(self): c = LocalFilesystemCache(self.remotebase) tmppath = c.temppath lpath = c.retrieve("fileA") self.assertEqual(lpath, c("fileA")) del c