def test_tar_obj_on_error(self): """Test whether the method return nothing in case of error""" repo = GraalRepository('http://example.git', self.git_path) file_obj = io.BytesIO(b'abcdefghilmnopqrstuvz') tar_obj = repo.tar_obj(file_obj) self.assertIsNone(tar_obj)
def test_tar_obj(self): """Test whether a BytesIO object is converted to a tar object""" repo = GraalRepository('http://example.git', self.git_path) file_obj = repo.archive("825b4da7ca740f7f2abbae1b3402908a44d130cd") tar_obj = repo.tar_obj(file_obj) self.assertIsInstance(tar_obj, tarfile.TarFile)
def test_filter_tar_no_members(self): """Test whether an null object is returned if not members are present""" repo = GraalRepository('http://example.git', self.git_path) file_obj = repo.archive("825b4da7ca740f7f2abbae1b3402908a44d130cd") tar_obj = repo.tar_obj(file_obj) to_select = [] filtered_obj = repo.filter_tar(tar_obj, to_select) self.assertIsNone(filtered_obj)
def test_filter_tar(self): """Test whether tar object members are filtered""" repo = GraalRepository('http://example.git', self.git_path) file_obj = repo.archive("825b4da7ca740f7f2abbae1b3402908a44d130cd") tar_obj = repo.tar_obj(file_obj) self.assertEqual(len(tar_obj.getmembers()), 18) to_select = ['.gitignore'] filtered_obj = repo.filter_tar(tar_obj, to_select) self.assertEqual(len(filtered_obj.getmembers()), 1) self.assertEqual(filtered_obj.getmembers()[0].name, '.gitignore')
def test_untar(self): """Test whether tar file is untarred""" untar_path = os.path.join(self.tmp_path, 'untesttar') repo = GraalRepository('http://example.git', self.git_path) file_obj = repo.archive("825b4da7ca740f7f2abbae1b3402908a44d130cd") tar_obj = repo.tar_obj(file_obj) repo.untar(tar_obj, untar_path) self.assertTrue(os.path.exists(untar_path)) self.assertTrue(os.path.isdir(untar_path)) shutil.rmtree(untar_path)
def test_tar(self): """Test whether tar object is saved to disk""" tar_path = os.path.join(self.tmp_path, 'testtar.tar.gz') repo = GraalRepository('http://example.git', self.git_path) file_obj = repo.archive("825b4da7ca740f7f2abbae1b3402908a44d130cd") tar_obj = repo.tar_obj(file_obj) repo.tar(tar_obj, tar_path) self.assertTrue(os.path.exists(tar_path)) self.assertTrue(os.path.isfile(tar_path)) os.remove(tar_path)