Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
p.num()
ret = p.num("3")
self.assertEqual(p.persistent_count, 3)
self.assertEqual(ret, "3")
p.num()
ret = p.num(count=3, show=1)
self.assertEqual(p.persistent_count, 3)
self.assertEqual(ret, "3")
p.num()
ret = p.num(count=3, show=0)
self.assertEqual(p.persistent_count, 3)
self.assertEqual(ret, "")
self.assertRaises(BadNumValueError, p.num, "text")
p.num()
ret = p.num("3")
self.assertEqual(p.persistent_count, 3)
self.assertEqual(ret, '3')
p.num()
ret = p.num(count=3, show=1)
self.assertEqual(p.persistent_count, 3)
self.assertEqual(ret, '3')
p.num()
ret = p.num(count=3, show=0)
self.assertEqual(p.persistent_count, 3)
self.assertEqual(ret, '')
self.assertRaises(BadNumValueError, p.num, 'text')
p.num()
ret = p.num("3")
self.assertEqual(p.persistent_count, 3)
self.assertEqual(ret, '3')
p.num()
ret = p.num(count=3, show=1)
self.assertEqual(p.persistent_count, 3)
self.assertEqual(ret, '3')
p.num()
ret = p.num(count=3, show=0)
self.assertEqual(p.persistent_count, 3)
self.assertEqual(ret, '')
self.assertRaises(BadNumValueError, p.num, 'text')
def num(self, count=None, show=None): # (;$count,$show)
"""
Set the number to be used in other method calls.
Returns count.
Set show to False to return '' instead.
"""
if count is not None:
try:
self.persistent_count = int(count)
except ValueError:
raise BadNumValueError
if (show is None) or show:
return str(count)
else:
self.persistent_count = None
return ""