def test_compress_bz2(self): """Test compress format: bz2""" for file_item in self.files: output_name = archive.compress(file_item, 'bz2') self.assertEqual('%s.bz2' % file_item, output_name) self.assertTrue(os.path.exists(output_name)) os.remove(output_name)
def _test_compress_lzo(self): """Test compress format: lzo""" for file_item in self.files: output_name = archive.compress(file_item, 'lzo') self.assertEqual('%s.lzo' % file_item, output_name) self.assertTrue(os.path.exists(output_name)) os.remove(output_name)
def test_decompress_compress_format_is_empty(self): """Test if the second parameter: compress format is empty string""" output_name = archive.compress(self.relative_file, 'gz') self.assertEqual('%s.gz' % self.relative_file, output_name) self.assertTrue(os.path.exists(output_name)) self.assertFalse(os.path.exists(self.relative_file)) archive.decompress(output_name, '') self.assertTrue(os.path.exists(self.relative_file))
def _test_decompress_lzo_no_compress_format(self): """Test decompress Format: lzo one parameters is given, only target file""" for file_item in self.files: output_name = archive.compress(file_item, 'lzo') self.assertEqual('%s.lzo' % file_item, output_name) self.assertTrue(os.path.exists(output_name)) self.assertFalse(os.path.exists(file_item)) archive.decompress(output_name) self.assertTrue(os.path.exists(file_item))
def _test_decompress_lzo(self): """Test decompress Format: lzo both two parameters are given, one is target file, the other is corresponding compress format""" for file_item in self.files: output_name = archive.compress(file_item, 'lzo') self.assertEqual('%s.lzo' % file_item, output_name) self.assertTrue(os.path.exists(output_name)) self.assertFalse(os.path.exists(file_item)) archive.decompress(output_name, 'lzo') self.assertTrue(os.path.exists(file_item))
def test_compress_negtive_wrong_compress_format(self): """Test wrong compress format""" with self.assertRaises(ValueError): archive.compress(self.relative_file, 'bzip2')
def test_compress_negtive_file_is_dir(self): """Test target is one direcoty, which is not supported""" with self.assertRaises(OSError): archive.compress(self.relative_dir, 'bz2')
def test_compress_negtive_file_not_exist(self): """Test target file does not exist""" with self.assertRaises(OSError): archive.compress('a.py', 'bz2')
def test_compress_negtive_parameters_are_all_required(self): """Test if two parameters are both empty""" with self.assertRaises(OSError): archive.compress('', '')
def test_compress_negtive_compress_format_is_required(self): """Test if the second parameter: compress format is empty""" with self.assertRaises(ValueError): archive.compress(self.relative_file, '')
def test_compress_negtive_file_path_is_required(self): """Test if the first parameter: file path is empty""" with self.assertRaises(OSError): archive.compress('', 'bz2')