def test_utils_cexc_hashes(self): to_test_in = [{ zde: 1 }, { ae: 1, zde: 2 }, { zde: False, None: 0, True: 1, False: 0 }] to_test_not_in = [{ 1: zde }, { 1: zde, 2: ae }, { ae: False, None: 0, True: 1, False: 0 }, { ae: 1 }, { 1: ae }] for it in to_test_in: self.assertIn(self.e, utils.Exceptions(it)) for it in to_test_not_in: self.assertNotIn(self.e, utils.Exceptions(it))
def test_utils_cexc_sets(self): to_test_in = [(zde, ), [zde], {zde}, (ae, zde), [ae, zde]] to_test_not_in = [(ae, ), [ae], {ae}] for it in to_test_in: self.assertIn(self.e, utils.Exceptions(set(it))) self.assertIn(self.e, utils.Exceptions(frozenset(it))) for it in to_test_not_in: self.assertNotIn(self.e, utils.Exceptions(set(it))) self.assertNotIn(self.e, utils.Exceptions(frozenset(it)))
def test_utils_cexc_compatible_excs(self): # Compatible Exceptions self.assertIn(self.e, utils.Exceptions(zde)) self.assertNotIn(self.e, utils.Exceptions(ae)) # Those two are equivalent self.assertIn(self.e, utils.Exceptions(zde, ae)) self.assertIn( self.e, utils.Exceptions( ZeroDivisionError(zde_msg), ArithmeticError(zde_msg), ))
def doit(self, delete=False): '''Decompress the file's data, in self.block_size chunks''' ret = True try: with self.opener(self.fin_name, 'rb') as fin: delout = False try: with open(self.fout_name, 'wb') as fout: try: utils.block_read_filedesc(fin, fout.write, self.block_size) except IOError as exc: delout = True ret = False if exc not in utils.Exceptions(IOError('Not a gzipped file')): raise exc if delout: vprint('Error happened: deleting output file') os.remove(self.fout_name) except IOError: ret = False except Exception: ret = False if ret and delete: os.remove(self.fin_name) return ret, self.fout_name
def test_utils_loop(self): for exc in self.excs: try: if isinstance(exc, Exception): # Should not raise e directly, make a copy raise exc.__class__(*exc.args) elif type(exc) == type(Exception): raise exc else: self.assertTrue(exc is None) except Exception as e: self.assertFalse(e is exc) self.assertIn(e, utils.Exceptions(self.excs)) a = list(self.excs) a.remove(exc) self.assertNotIn(e, utils.Exceptions(a))