def test_fileage(self): """ Assume we can `touch` within 2000ms. """ path = tempfile.mktemp() self.assertFalse(os.path.exists(path)) touch(path) self.assertTrue(os.path.exists(path)) self.assertTrue(0 < fileage(path) < 2)
def test_findfiles(self): directory = tempfile.mkdtemp() subdir = tempfile.mkdtemp(dir=directory) touch(os.path.join(directory, '1.jpg')) touch(os.path.join(subdir, '2-1.txt')) touch(os.path.join(subdir, '2-2.txt')) pathlist = sorted(list(findfiles(directory))) self.assertEquals(3, len(pathlist)) self.assertEquals(['1.jpg', '2-1.txt', '2-2.txt'], map(os.path.basename, pathlist)) self.assertEquals('{0}/1.jpg'.format(directory), pathlist[0]) self.assertEquals('{0}/2-1.txt'.format(subdir), pathlist[1]) self.assertEquals('{0}/2-2.txt'.format(subdir), pathlist[2]) pathlist = list(findfiles(directory, fun=lambda path: path.endswith('jpg'))) self.assertEquals(1, len(pathlist)) self.assertEquals('{0}/1.jpg'.format(directory), pathlist[0])
def test_touch(self): path = tempfile.mktemp() self.assertFalse(os.path.exists(path)) touch(path) self.assertTrue(os.path.exists(path))