def test_run_where_everything_is_successful(self): temp_dir = tempfile.mkdtemp() try: params = D3RParameters() fakegz = os.path.join(temp_dir, 'fake.gz') f = gzip.open(fakegz, 'wb') f.write('hello\n') f.flush() f.close() params.pdbsequrl = 'file://' + fakegz params.makeblastdb = 'echo' task = MakeBlastDBTask(temp_dir, params) task._retrysleep = 0 task._maxretries = 1 task.run() self.assertEqual(task.get_error(), None) # check echo.stdout file for valid arguments f = open(os.path.join(task.get_dir(), 'echo.stdout'), 'r') line = f.readline() self.assertEqual( line, '-in ' + task.get_pdb_seqres_txt() + ' -out ' + os.path.join(task.get_dir(), 'pdb_db') + ' -dbtype prot\n') f.close() lines = task.get_email_log().split('\n') self.assertEqual(lines[2], '# sequence(s): 0') f.close() finally: shutil.rmtree(temp_dir)
def test_run_where_pdbsequrl_is_not_set(self): temp_dir = tempfile.mkdtemp() try: params = D3RParameters() task = MakeBlastDBTask(temp_dir, params) task.run() self.assertEqual( task.get_error(), 'cannot download files cause ' 'pdbsequrl not set') finally: shutil.rmtree(temp_dir)
def test_run_where_makeblastdb_is_not_set(self): temp_dir = tempfile.mkdtemp() try: params = D3RParameters() params.pdbsequrl = 'pdbsequrl' task = MakeBlastDBTask(temp_dir, params) task.run() self.assertEqual( task.get_error(), 'cannot make blast database ' 'cause makeblastdb not set') finally: shutil.rmtree(temp_dir)
def test_run_where_can_run_is_false(self): temp_dir = tempfile.mkdtemp() try: params = D3RParameters() task = MakeBlastDBTask(temp_dir, params) task.create_dir() open(os.path.join(task.get_dir(), 'error'), 'a').close() task.run() self.assertEqual(task._can_run, False) finally: shutil.rmtree(temp_dir)
def test_run_where_download_fails(self): temp_dir = tempfile.mkdtemp() try: params = D3RParameters() params.pdbsequrl = 'file://doesnotexist' params.makeblastdb = 'makeblastdb' task = MakeBlastDBTask(temp_dir, params) task._retrysleep = 0 task._maxretries = 1 task.run() self.assertEqual( task.get_error(), 'Unable to download file: ' + 'file://doesnotexist') finally: shutil.rmtree(temp_dir)
def test_run_where_gunzip_fails(self): temp_dir = tempfile.mkdtemp() try: params = D3RParameters() fakegz = os.path.join(temp_dir, 'fake.gz') f = open(fakegz, 'w') f.write('hello\n') f.flush() f.close() params.pdbsequrl = 'file://' + fakegz params.makeblastdb = 'makeblastdb' task = MakeBlastDBTask(temp_dir, params) task._retrysleep = 0 task._maxretries = 1 task.run() self.assertEqual( task.get_error(), 'Unable to uncompress file: ' + task.get_pdb_seqres_txt()) finally: shutil.rmtree(temp_dir)
def test_run_where_makeblastdb_fails(self): temp_dir = tempfile.mkdtemp() try: params = D3RParameters() fakegz = os.path.join(temp_dir, 'fake.gz') f = gzip.open(fakegz, 'wb') f.write('hello\n') f.flush() f.close() params.pdbsequrl = 'file://' + fakegz params.makeblastdb = 'false' task = MakeBlastDBTask(temp_dir, params) task._retrysleep = 0 task._maxretries = 1 task.run() self.assertEqual( task.get_error(), 'Non zero exit code: 1 ' 'received. Standard out:' ' Standard error: ') finally: shutil.rmtree(temp_dir)