def is_integer(cls, s): return isinstance(StringCleaner.safe_int(s), (int,))
def test_safe_int(self): self.assertEqual(StringCleaner.safe_int('0'), 0) self.assertEqual(StringCleaner.safe_int('1'), 1) self.assertEqual(StringCleaner.safe_int('a'), None) self.assertEqual(StringCleaner.safe_int('12.3'), 123) self.assertEqual(StringCleaner.safe_int('1a2b3c'), 123) self.assertEqual(StringCleaner.safe_int('<1a2b3c/>'), 123) self.assertEqual(StringCleaner.safe_int(None), None) self.assertEqual(StringCleaner.safe_int('None'), None) self.assertEqual(StringCleaner.safe_int(1), 1) self.assertEqual(StringCleaner.safe_int(u''), None) self.assertEqual(StringCleaner.safe_int(1, None), 1) self.assertEqual(StringCleaner.safe_int('hi', 0), 0) self.assertEqual(StringCleaner.safe_int(None, 0), 0) self.assertEqual(StringCleaner.safe_int(None, None), None) self.assertEqual(StringCleaner.safe_int(u'', 0), 0) self.assertEqual(StringCleaner.safe_int(u'-1'), -1) self.assertEqual(StringCleaner.safe_int('0044500'), 44500)