def test_Size(self):
        target_root = '/tmp/work/__TEST__'
        target_dummy = os.path.join(target_root, 'a.dummy')
        self.__MakeDummy(target_dummy, 1024)

        #s = Directory(target_root)
        s = Directory(target_root)
        self.assertEqual(1024, s.Size)

        path_b = os.path.join(target_root, 'B')
        Directory.Create(path_b)
        self.__MakeDummy(os.path.join(path_b, 'b.dummy'), 1024)
        self.assertEqual(2048, s.Size)

        path_c = os.path.join(target_root, 'C')
        Directory.Create(path_c)
        self.__MakeDummy(os.path.join(path_c, 'c.dummy'), 1024)
        self.assertEqual(3072, s.Size)

        path_bb = os.path.join(target_root, 'B/BB')
        Directory.Create(path_bb)
        self.__MakeDummy(os.path.join(path_bb, 'bb.dummy'), 1024)
        self.assertEqual(4096, s.Size)

        Directory.Delete(target_root)
    def __make_archive(self):
        target = '/tmp/work/__TEST__'
        self.assertTrue(not Directory.IsExist(target))
        Directory.Create(target)
        Directory.Create(os.path.join(target, 'A'))
        pathlib.Path(os.path.join(target, 'A/a.txt')).touch()

        Directory.Archive(target, target + '.zip')
        self.assertTrue(os.path.isfile(target + '.zip'))
        Directory.Delete(target)
 def test_Copy_tree(self):
     target = '/tmp/work/__TEST__'
     self.assertTrue(not Directory.IsExist(target))
     Directory.Create(target)
     Directory.Create(os.path.join(target, 'A'))
     pathlib.Path(os.path.join(target, 'A/a.txt')).touch()
     self.assertTrue(not Directory.IsExist('/tmp/work/__TEST_2__'))
     Directory.Copy(target, '/tmp/work/__TEST_2__')
     self.assertTrue(Directory.IsExist('/tmp/work/__TEST_2__'))
     self.assertTrue(os.path.isfile('/tmp/work/__TEST_2__/A/a.txt'))
     Directory.Delete(target)
     Directory.Delete('/tmp/work/__TEST_2__')
 def test_Create_Delete(self):
     target = '/tmp/work/__TEST__'
     self.assertTrue(not Directory.IsExist(target))
     Directory.Create(target)
     self.assertTrue(Directory.IsExist(target))
     Directory.Delete(target)
     self.assertTrue(not Directory.IsExist(target))
     target = '/tmp/work/__TEST__/A/B/C'
     self.assertTrue(not Directory.IsExist(target))
     Directory.Create(target)
     self.assertTrue(Directory.IsExist(target))
     Directory.Delete(target)
     self.assertTrue(not Directory.IsExist(target))
     target = '/tmp/work/__TEST__'
     Directory.Delete(target)
 def test_Copy_single(self):
     target = '/tmp/work/__TEST__'
     self.assertTrue(not Directory.IsExist(target))
     Directory.Create(target)
     Directory.Copy(target, '/tmp/work/__TEST_2__')
     self.assertTrue(Directory.IsExist('/tmp/work/__TEST_2__'))
     Directory.Delete(target)
     Directory.Delete('/tmp/work/__TEST_2__')
    def test_GetSize(self):
        target_root = '/tmp/work/__TEST__'
        target_dummy = os.path.join(target_root, 'a.dummy')
        self.__MakeDummy(target_dummy, 1024)
        self.assertTrue(hasattr(Directory, 'GetSize'))
        print('Dir Size is {}'.format(Directory.GetSize(target_root)))
        self.assertEqual(1024, Directory.GetSize(target_root))

        path_b = os.path.join(target_root, 'B')
        Directory.Create(path_b)
        self.__MakeDummy(os.path.join(path_b, 'b.dummy'), 1024)
        self.assertEqual(2048, Directory.GetSize(target_root))

        path_c = os.path.join(target_root, 'C')
        Directory.Create(path_c)
        self.__MakeDummy(os.path.join(path_c, 'c.dummy'), 1024)
        self.assertEqual(3072, Directory.GetSize(target_root))

        path_bb = os.path.join(target_root, 'B/BB')
        Directory.Create(path_bb)
        self.__MakeDummy(os.path.join(path_bb, 'bb.dummy'), 1024)
        self.assertEqual(4096, Directory.GetSize(target_root))

        Directory.Delete(target_root)
Ejemplo n.º 7
0
import sys, os, os.path, pathlib
print(pathlib.Path(__file__).parent.parent / 'src')
sys.path.append(str(pathlib.Path(__file__).parent.parent / 'src'))
from Directory import Directory

if __name__ == '__main__':
    target_root = '/tmp/work/__TEST__'
    try:
        assert(True == Directory.IsExist('/'))
        assert(False == Directory.IsExist('/NotExistDir'))
        target = os.path.join(target_root, 'SUB1', 'SUB11', 'SUB111')
        print(target)
        assert('/tmp/work/__TEST__/SUB1/SUB11/SUB111' == target)
        assert(False ==  Directory.IsExist(target_root))
        Directory.Create(target)
        assert(True ==  Directory.IsExist(target))
        assert(True ==  os.path.isdir(target))
        assert(True ==  os.path.exists(target))
        
        Directory.Delete(target)
        assert(False ==  Directory.IsExist(target))
        assert(True ==  Directory.IsExist('/tmp/work/__TEST__/SUB1/SUB11'))
        
        target2 = os.path.join(target_root, '__TEST2__')
        assert(False ==  Directory.IsExist(target2))
        Directory.Copy(target_root, target2)
        assert(True ==  Directory.IsExist(target2))
        assert(True == Directory.IsExist(os.path.join(target2, 'SUB1', 'SUB11')))
        a = Directory.Archive(target_root, target_root + '.zip')
        print(a)
        print(target_root + '.zip')