Best Python code snippet using refurb_python
test_errorcode.py
Source: test_errorcode.py
1from mpi4py import MPI2import mpiunittest as unittest3class TestErrorCode(unittest.TestCase):4 errorclasses = [item[1] for item in vars(MPI).items()5 if item[0].startswith('ERR_')]6 errorclasses.insert(0, MPI.SUCCESS)7 errorclasses.remove(MPI.ERR_LASTCODE)8 def testGetErrorClass(self):9 self.assertEqual(self.errorclasses[0], 0)10 for ierr in self.errorclasses:11 errcls = MPI.Get_error_class(ierr)12 self.assertTrue(errcls >= MPI.SUCCESS)13 self.assertTrue(errcls <= MPI.ERR_LASTCODE)14 self.assertEqual(errcls, ierr)15 def testGetErrorStrings(self):16 for ierr in self.errorclasses:17 errstr = MPI.Get_error_string(ierr)18 def testException(self):19 from sys import version_info as py_version20 success = MPI.Exception(MPI.SUCCESS)21 lasterr = MPI.Exception(MPI.ERR_LASTCODE)22 for ierr in self.errorclasses:23 errstr = MPI.Get_error_string(ierr)24 errcls = MPI.Get_error_class(ierr)25 errexc = MPI.Exception(ierr)26 if py_version >= (2,5):27 self.assertEqual(errexc.error_code, ierr)28 self.assertEqual(errexc.error_class, ierr)29 self.assertEqual(errexc.error_string, errstr)30 self.assertEqual(repr(errexc), "MPI.Exception(%d)" % ierr)31 self.assertEqual(str(errexc), errstr)32 self.assertEqual(int(errexc), ierr)33 self.assertEqual(hash(errexc), hash(errexc.error_code))34 self.assertTrue(errexc == ierr)35 self.assertTrue(errexc == errexc)36 self.assertFalse(errexc != ierr)37 self.assertFalse(errexc != errexc)38 self.assertTrue(success <= ierr <= lasterr)39 self.assertTrue(success <= errexc <= lasterr)40 self.assertTrue(errexc >= ierr)41 self.assertTrue(errexc >= success)42 self.assertTrue(lasterr >= ierr)43 self.assertTrue(lasterr >= errexc)44 if errexc == success:45 self.assertFalse(errexc)46 else:47 self.assertTrue(errexc)48 self.assertTrue(errexc > success)49 self.assertTrue(success < errexc)50 exc = MPI.Exception(MPI.SUCCESS-1)51 self.assertTrue(exc, MPI.ERR_UNKNOWN)52 exc = MPI.Exception(MPI.ERR_LASTCODE+1)53 self.assertTrue(exc, MPI.ERR_UNKNOWN)54 @unittest.skipMPI('openmpi(<1.10.0)')55 def testAddErrorClass(self):56 try:57 errclass = MPI.Add_error_class()58 except NotImplementedError:59 self.skipTest('mpi-add_error_class')60 self.assertTrue(errclass >= MPI.ERR_LASTCODE)61 @unittest.skipMPI('openmpi(<1.10.0)')62 def testAddErrorClassCodeString(self):63 try:64 errclass = MPI.Add_error_class()65 except NotImplementedError:66 self.skipTest('mpi-add_error_class')67 lastused = MPI.COMM_WORLD.Get_attr(MPI.LASTUSEDCODE)68 self.assertTrue(errclass == lastused)69 errstr = MPI.Get_error_string(errclass)70 self.assertEqual(errstr, "")71 MPI.Add_error_string(errclass, "error class")72 self.assertEqual(MPI.Get_error_string(errclass), "error class")73 errcode1 = MPI.Add_error_code(errclass)74 errstr = MPI.Get_error_string(errcode1)75 self.assertEqual(errstr, "")76 MPI.Add_error_string(errcode1, "error code 1")77 self.assertEqual(MPI.Get_error_class(errcode1), errclass)78 self.assertEqual(MPI.Get_error_string(errcode1), "error code 1")79 errcode2 = MPI.Add_error_code(errclass)80 errstr = MPI.Get_error_string(errcode2)81 self.assertEqual(errstr, "")82 MPI.Add_error_string(errcode2, "error code 2")83 self.assertEqual(MPI.Get_error_class(errcode2), errclass)84 self.assertEqual(MPI.Get_error_string(errcode2), "error code 2")85if __name__ == '__main__':...
exc.py
Source: exc.py
...53class HTTPErrorType(type):54 __classes = {}55 56 @classmethod57 def get_error_class(cls, status):58 try:59 status = int(status)60 except (TypeError, ValueError):61 raise ValueError("Not a valid HTTP error code: '%s'" % (status, ))62 63 try:64 errorcls = cls.__classes[status]65 except KeyError:66 if status < STATUS_MIN or status > STATUS_MAX:67 raise ValueError("Not a valid HTTP error code: %s" % (status, ))68 name = "HTTPError%s" % (status, ) 69 errorcls = cls(name, (HTTPError, ), {"__init__": cls._make_init(status)})70 cls.__classes[status] = errorcls71 globals()[name] = errorcls72 73 return errorcls 74 75 def __call__(self, *args, **kw):76 if self is HTTPError and args:77 self = self.get_error_class(args[0])78 args = args[1:]79 return super(HTTPErrorType, self).__call__(*args, **kw)80 81 @classmethod82 def _make_init(cls, status):83 def __init__(self, msg = None, reason = None, *args, **kw):84 super(self.__class__, self).__init__(status = status, reason = reason, msg = msg, *args, **kw)85 return __init__86 87get_error_class = HTTPErrorType.get_error_class88class HTTPError(NetworkError):89 __metaclass__ = HTTPErrorType90 91 def __init__(self, status, reason = None, msg = None, *args, **kw):...
Check out the latest blogs from LambdaTest on this topic:
I routinely come across test strategy documents when working with customers. They are lengthy—100 pages or more—and packed with monotonous text that is routinely reused from one project to another. Yawn once more— the test halt and resume circumstances, the defect management procedure, entrance and exit criteria, unnecessary generic risks, and in fact, one often-used model replicates the requirements of textbook testing, from stress to systems integration.
These days, development teams depend heavily on feedback from automated tests to evaluate the quality of the system they are working on.
Entering the world of testers, one question started to formulate in my mind: “what is the reason that bugs happen?”.
Are members of agile teams different from members of other teams? Both yes and no. Yes, because some of the behaviors we observe in agile teams are more distinct than in non-agile teams. And no, because we are talking about individuals!
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!