def testRandomFileName(self): f = RandomPath().populate(1024 * 1024) self.assertEqual(os.path.getsize(f()), 1024 * 1024) self.assertEqual(os.path.getsize(f()), f.size()) f.remove() self.assertFalse(os.path.isfile(f.path())) self.assertEqual(0, f.size())
def testRandomDir(self): d = RandomPath(make="DIR") self.assertTrue(os.path.isdir(d())) d.remove() d1 = RandomPath(make="DIR") d2 = RandomPath(d1(), make="DIR") self.assertTrue(os.path.isdir(os.path.join(d1(), d2()))) shutil.rmtree(d1()) with RandomPath(make="DIR") as d1: with RandomPath(d1(), make="DIR") as d2: self.assertTrue(os.path.isdir(os.path.join(d1(), d2()))) self.assertFalse(os.path.isdir(os.path.join(d1(), d2()))) d1 = RandomPath(make="DIR") self.assertTrue(os.path.isdir(d1())) d1.remove() self.assertFalse(os.path.isdir(d1()))
def testRandomFile(self): r = RandomPath() self.assertTrue(os.path.isfile(r())) r.remove() self.assertFalse(os.path.isfile(r())) r = RandomPath().populate(size=1024) self.assertTrue(os.path.isfile(r())) self.assertEqual(os.path.getsize(r()), 1024) self.assertEqual(r(), os.path.join(r.dirname(), r.basename())) r.remove() self.assertFalse(os.path.isfile(r())) r = RandomPath() r.populate(1024) self.assertTrue(os.path.isfile(r())) self.assertEqual(os.path.getsize(r()), 1024) r.remove() self.assertFalse(os.path.isfile(r()))
def testRandomFile1024(self, size=1024): r = RandomPath().populate(1024) self.assertEqual(os.path.getsize(r()), r.size()) r.remove() self.assertFalse(os.path.isfile(r()))
def testRandomName(self): f = RandomPath() self.assertTrue(os.path.isfile(f.path())) f.remove() self.assertFalse(os.path.isfile(f.path()))