Пример #1
0
    def DISABLED_test_abs_path_folder(self):
        if os.name == 'nt':
            os.mkdir('C:/test_imageZIP')
            os.mkdir('C:/test_imageZIP/test folder/')
            original_folder_name = 'C:/test_imageZIP/test folder/'
            zip_path = 'C:/test_imageZIP/test folder_zip.png'
        else:
            os.mkdir('/test_imageZIP/')
            os.mkdir('/test_imageZIP/test folder/')
            original_folder_name = '/test_imageZIP/test folder/'
            zip_path = '/test_imageZIP/test folder_zip.png'
        path_file = os.path.join(original_folder_name, '0')
        with open(path_file, 'w') as file:
            file.write('testing 123')
        with open(path_file, 'rb') as file:
            text_file = file.read()

        imageZIP.zip(original_folder_name)
        self.assertTrue(os.path.exists(zip_path))
        self.assertFalse(os.path.exists('test folder_zip.png'))

        if os.name == 'nt':
            shutil.rmtree(original_folder_name, ignore_errors=True)
        else:
            shutil.rmtree(original_folder_name, ignore_errors=True)

        imageZIP.unzip(zip_path)
        with open(path_file, 'rb') as file:
            text_file_new = file.read()
        self.assertEqual(text_file_new, text_file)

        if os.name == 'nt':
            shutil.rmtree('C:/test_imageZIP', ignore_errors=True)
        else:
            shutil.rmtree('/test_imageZIP/', ignore_errors=True)
Пример #2
0
    def test_folder(self):
        original_folder_name = 'tests/test folder/'
        zip_path = 'tests/test folder_zip.png'
        path_empty_file = os.path.join(original_folder_name, '0')
        with open(path_empty_file, 'rb') as file:
            empty_file = file.read()
        path_image_file = os.path.join(original_folder_name,
                                       'inner folder/image.jpg')
        with open(path_image_file, 'rb') as file:
            image_file = file.read()

        imageZIP.zip(original_folder_name)
        self.assertTrue(os.path.exists(zip_path))
        self.assertFalse(os.path.exists('test folder_zip.png'))

        shutil.rmtree(original_folder_name, ignore_errors=True)

        imageZIP.unzip(zip_path)
        with open(path_empty_file, 'rb') as file:
            empty_file_new = file.read()
        self.assertEqual(empty_file_new, empty_file)
        with open(path_image_file, 'rb') as file:
            image_file_new = file.read()
        self.assertEqual(image_file_new, image_file)
        self.assertFalse(
            os.path.exists('test folder\\0')
            and os.path.isdir('test folder\\0'))

        os.remove(zip_path)
Пример #3
0
    def test_file(self):
        original_file_name = 'tests/test file ☆.txt'
        zip_path = 'tests/test file ☆.txt_zip.png'
        with open(original_file_name, 'r', encoding='UTF-8') as file:
            original_file = file.read()

        imageZIP.zip(original_file_name)
        self.assertTrue(os.path.exists(zip_path))
        self.assertFalse(os.path.exists('test file ☆.txt_zip.png'))

        os.remove(original_file_name)

        imageZIP.unzip(zip_path)
        with open(original_file_name, 'r', encoding='UTF-8') as file:
            unzipped_file = file.read()
        self.assertTrue(os.path.exists(original_file_name))
        self.assertEqual(unzipped_file, original_file)

        os.remove(zip_path)
Пример #4
0
    def test_binary_file(self):
        original_file_name = 'tests/test folder/inner folder/image.jpg'
        zip_path = 'tests/test folder/inner folder/image.jpg_zip.png'
        with open(original_file_name, 'rb') as file:
            original_file = file.read()

        imageZIP.zip(original_file_name)
        self.assertTrue(os.path.exists(zip_path))
        self.assertFalse(os.path.exists('image.jpg_zip.png'))

        os.remove(original_file_name)

        imageZIP.unzip(zip_path)
        with open(original_file_name, 'rb') as file:
            unzipped_file = file.read()
        self.assertTrue(os.path.exists(original_file_name))
        self.assertEqual(unzipped_file, original_file)

        os.remove(zip_path)