示例#1
0
    def test_tar_challenge_dir_unable_to_write_tarfile(self):
        temp_dir = tempfile.mkdtemp()
        try:
            params = D3RParameters()

            task = ChallengeDataTask(temp_dir, params)

            chall_dir = task.get_celpp_challenge_data_dir_name()
            try:
                task._tar_challenge_dir(chall_dir)
                self.fail('Expected IOError')
            except IOError:
                pass

        finally:
            shutil.rmtree(temp_dir)
示例#2
0
    def test_tar_challenge_dir(self):
        temp_dir = tempfile.mkdtemp()
        try:
            params = D3RParameters()
            dimport = DataImportTask(temp_dir, params)
            dimport.create_dir()
            open(dimport.get_sequence_tsv(), 'a').close()
            open(dimport.get_nonpolymer_tsv(), 'a').close()
            open(dimport.get_crystalph_tsv(), 'a').close()

            task = ChallengeDataTask(temp_dir, params)
            task.create_dir()
            chall_dir = task._create_challenge_dir()

            final_log = os.path.join(chall_dir, 'final.log')
            open(final_log, 'a').close()

            task._create_readme(chall_dir)
            task._copy_over_tsv_files(chall_dir)

            # make a fake candidate
            file_list = self.make_fake_candidate_dir(chall_dir, '5hib',
                                                     '2eb2', 'CSX')

            self.assertEqual(os.path.isdir(chall_dir), True)
            name = task.get_celpp_challenge_data_dir_name()
            tfile = task._tar_challenge_dir(name)
            self.assertEqual(os.path.isfile(tfile), True)

            foodir = os.path.join(temp_dir, 'foo')
            tar = tarfile.open(tfile, 'r:*')
            tar.extractall(path=foodir)
            tar.close()
            cdir = os.path.join(foodir, name)
            readme = os.path.join(cdir, ChallengeDataTask.README_TXT_FILE)
            self.assertEqual(os.path.isfile(readme), True)

            final_log = os.path.join(foodir, 'final.log')
            self.assertEqual(os.path.isfile(final_log), False)

            for fname in file_list:
                chk = os.path.join(cdir, fname)
                self.assertEqual(os.path.isfile(chk), True, chk)

        finally:
            shutil.rmtree(temp_dir)
示例#3
0
    def test_tar_challenge_dir_nothing_but_readme(self):
        temp_dir = tempfile.mkdtemp()
        try:
            params = D3RParameters()
            task = ChallengeDataTask(temp_dir, params)
            task.create_dir()
            chall_dir = task._create_challenge_dir()
            task._create_readme(chall_dir)

            self.assertEqual(os.path.isdir(chall_dir), True)
            name = task.get_celpp_challenge_data_dir_name()
            tfile = task._tar_challenge_dir(name)
            self.assertEqual(os.path.isfile(tfile), True)

            foodir = os.path.join(temp_dir, 'foo')
            tar = tarfile.open(tfile, 'r:*')
            tar.extractall(path=foodir)
            tar.close()
            cdir = os.path.join(foodir, name)
            readme = os.path.join(cdir, ChallengeDataTask.README_TXT_FILE)
            self.assertEqual(os.path.isfile(readme), True)

        finally:
            shutil.rmtree(temp_dir)