def test_remote_fna_kwargs(self): url = ('http://www.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?retmax=1' '00&retmode=text&tool=skbio&db=nucleotide&id=459567&rettype=fas' 'ta&retstart=0&[email protected]') with open_files([url], stream=True) as fhs: for f in fhs: self.assertEqual(f.read(), FASTA)
def test_files_closed(self): """File gets closed in decorator""" f = tempfile.NamedTemporaryFile('r') f2 = tempfile.NamedTemporaryFile('r') filepath = f.name filepath2 = f2.name with open_files([filepath, filepath2]) as fhs: pass for fh in fhs: self.assertTrue(fh.closed)
def test_files_closed_harder(self): """File gets closed in decorator, even if exceptions happen.""" f = tempfile.NamedTemporaryFile('r') f2 = tempfile.NamedTemporaryFile('r') filepath = f.name filepath2 = f2.name try: with open_files([filepath, filepath2]) as fhs: raise TypeError except TypeError: for fh in fhs: self.assertTrue(fh.closed) else: # If we're here, no exceptions have been raised inside the # try clause, so the context manager swallowed them. No # good. raise Exception("`open_file` didn't propagate exceptions")
def test_BytesIO(self): """BytesIO (useful e.g. for testing) slips through.""" f = BytesIO(b"File contents") with open_files([f]) as fhs: self.assertTrue(fhs[0] is f)
def test_remote_failing_fna(self): with self.assertRaises(HTTPError) as e: with open_files(['http://google.com/foo-seqs.fna']) as fhs: for f in fhs: f.read() self.assertEquals(str(e.exception), '404 Client Error: Not Found')
def test_remote_failing_fna(self): with self.assertRaises(HTTPError) as e: with open_files(['http://google.com/foo-seqs.fna']) as fhs: for f in fhs: f.read() self.assertEqual(str(e.exception), '404 Client Error: Not Found')