def test_strToIntInRange_badNumbers(self): self.assertRaises(ValueError, lambda: objcheck.strToIntInRange("1.", -3, 3)) self.assertRaises(ValueError, lambda: objcheck.strToIntInRange("1.0", -3, 3)) self.assertRaises(ValueError, lambda: objcheck.strToIntInRange("1.5", -3, 3)) self.assertRaises(ValueError, lambda: objcheck.strToIntInRange("-0", -3, 3)) self.assertRaises(ValueError, lambda: objcheck.strToIntInRange("", -3, 3)) self.assertRaises(ValueError, lambda: objcheck.strToIntInRange("x", -3, 3)) self.assertRaises(ValueError, lambda: objcheck.strToIntInRange("-", -3, 3))
def sackStringToSack(sackString): """ C{sackString} is a C{str}. Returns a L{window.SACK}. """ try: # If not enough args for split, Python raises ValueError joinedSackList, ackNumberStr = sackString.rsplit('|', 1) ackNumber = strToIntInRange(ackNumberStr, -1, 2**53) sackList = tuple(strToNonNegLimit(s, 2**53) for s in joinedSackList.split(',')) if joinedSackList else () except ValueError: raise InvalidSackString("bad sack") return SACK(ackNumber, sackList)
def test_strToIntInRange_withinLimit(self): self.assertEqual(3, objcheck.strToIntInRange("3", 3, 3)) self.assertEqual(3, objcheck.strToIntInRange("3", -3, 3)) self.assertEqual(-3, objcheck.strToIntInRange("-3", -3, 3)) self.assertEqual(0, objcheck.strToIntInRange("0", 0, 0))
def test_strToIntInRange_outsideLimit(self): self.assertRaises(ValueError, lambda: objcheck.strToIntInRange("-4", -3, 3)) self.assertRaises(ValueError, lambda: objcheck.strToIntInRange("4", -3, 3))
def test_strToIntInRange_TypeErrors(self): self.assertRaises(TypeError, lambda: objcheck.strToIntInRange(None)) self.assertRaises(TypeError, lambda: objcheck.strToIntInRange([])) self.assertRaises(TypeError, lambda: objcheck.strToIntInRange({}))