def test_get_uploadable_files(self): temp_dir = tempfile.mkdtemp() try: # test where directory doesn't even exist params = D3RParameters() task = ChallengeDataTask(temp_dir, params) self.assertEqual(task.get_uploadable_files(), []) # test on empty dir task.create_dir() self.assertEqual(task.get_uploadable_files(), []) # test with tarfile tarfile = task.get_celpp_challenge_data_tar_file() open(tarfile, 'a').close() flist = task.get_uploadable_files() self.assertEqual(len(flist), 1) flist.index(tarfile) # test with additional stderr/stdout files errfile = os.path.join(task.get_dir(), 'genchallengedata.py.stderr') open(errfile, 'a').close() flist = task.get_uploadable_files() self.assertEqual(len(flist), 2) flist.index(errfile) outfile = os.path.join(task.get_dir(), 'genchallengedata.py.stdout') open(outfile, 'a').close() flist = task.get_uploadable_files() self.assertEqual(len(flist), 3) flist.index(outfile) flist.index(errfile) flist.index(tarfile) finally: shutil.rmtree(temp_dir)
def test_run_succeeds_no_ftp(self): temp_dir = tempfile.mkdtemp() try: script = self.create_gen_challenge_script(temp_dir) params = D3RParameters() params.genchallenge = script params.pdbdb = '/foo' params.version = '1' blastnfilter = BlastNFilterTask(temp_dir, params) blastnfilter.create_dir() open(os.path.join(blastnfilter.get_dir(), D3RTask.COMPLETE_FILE), 'a').close() chall = ChallengeDataTask(temp_dir, params) dimport = DataImportTask(temp_dir, params) dimport.create_dir() ctsv = dimport.get_crystalph_tsv() f = open(ctsv, 'w') f.write('crystal') f.flush() f.close() nonpoly = dimport.get_nonpolymer_tsv() f = open(nonpoly, 'w') f.write('nonpoly') f.flush() f.close() seq = dimport.get_sequence_tsv() f = open(seq, 'w') f.write('seq') f.flush() f.close() chall.run() self.assertEqual(chall.get_error(), None) # verify test files get created errfile = os.path.join(chall.get_dir(), D3RTask.ERROR_FILE) self.assertEqual(os.path.isfile(errfile), False) compfile = os.path.join(chall.get_dir(), D3RTask.COMPLETE_FILE) self.assertEqual(os.path.isfile(compfile), True) stderr = os.path.join(chall.get_dir(), 'genchallenge.py.stderr') self.assertEqual(os.path.isfile(stderr), True) stdout = os.path.join(chall.get_dir(), 'genchallenge.py.stdout') self.assertEqual(os.path.isfile(stdout), True) # verify challenge directory is created and # filled with valid files chall_dir = os.path.join(chall.get_dir(), chall.get_celpp_challenge_data_dir_name()) self.assertEqual(os.path.isdir(chall_dir), True) readme = os.path.join(chall_dir, ChallengeDataTask.README_TXT_FILE) self.assertEqual(os.path.isfile(readme), True) crystal = os.path.join(chall_dir, DataImportTask.CRYSTALPH_TSV) self.assertEqual(os.path.isfile(crystal), True) seq = os.path.join(chall_dir, DataImportTask.SEQUENCE_TSV) self.assertEqual(os.path.isfile(seq), True) nonpoly = os.path.join(chall_dir, DataImportTask.NONPOLYMER_TSV) self.assertEqual(os.path.isfile(nonpoly), True) fivehibdir = os.path.join(chall_dir, '5hib') fivehibtxt = os.path.join(fivehibdir, '5hib.txt') self.assertEqual(os.path.isfile(fivehibtxt), True) fivehibfas = os.path.join(fivehibdir, '5hib.fasta') self.assertEqual(os.path.isfile(fivehibfas), True) fivehicdir = os.path.join(chall_dir, '5hic') fivehictxt = os.path.join(fivehicdir, '5hic.txt') self.assertEqual(os.path.isfile(fivehictxt), True) fivehicfas = os.path.join(fivehicdir, '5hic.fasta') self.assertEqual(os.path.isfile(fivehicfas), True) # verify tarball is created tfile = chall.get_celpp_challenge_data_tar_file() self.assertEqual(os.path.isfile(tfile), True) foodir = os.path.join(temp_dir, 'foo') os.mkdir(foodir) tar = tarfile.open(tfile, 'r:*') tar.extractall(path=foodir) tar.close() name = chall.get_celpp_challenge_data_dir_name() cdir = os.path.join(foodir, name) readme = os.path.join(cdir, ChallengeDataTask.README_TXT_FILE) self.assertEqual(os.path.isfile(readme), True) final = os.path.join(foodir, name, 'final.log') self.assertEqual(os.path.isfile(final), False) e_con = os.path.join(foodir, name, 'error_container') self.assertEqual(os.path.isdir(e_con), False) finally: shutil.rmtree(temp_dir)