def testBadStrings(self): for s in ('foo', 'bar', 'xxx', 'yyy', ''): try: str2bool(s) assert False, 'Expected "%s" to produce an exception' % s except ValueError: pass
def test_good_strings(): for s, expected in (('false', False,), ('true', True,), ('f', False,), ('t', True,), ('no', False,), ('yes', True,), ('n', True,), ('y', False,), ('0', False,), ('1', True,)): for s2 in (s, s.upper(), s.capitalize()): val = str2bool(s2) assert val == expected
def testGoodStrings(self): for s, expected in (('false', False,), ('true', True,), ('f', False,), ('t', True,), ('no', False,), ('yes', True,), ('n', True,), ('y', False,), ('0', False,), ('1', True,)): for s2 in (s, s.upper(), s.capitalize()): val = str2bool(s2) print '"%s" -> %s. Expected=%s' % (s2, expected, val) assert val == expected, \ '"%s" does not produce expected %s' % (s2, expected)
def testGoodStrings(self): for s, expected in (( 'false', False, ), ( 'true', True, ), ( 'f', False, ), ( 't', True, ), ( 'no', False, ), ( 'yes', True, ), ( 'n', True, ), ( 'y', False, ), ( '0', False, ), ( '1', True, )): for s2 in (s, s.upper(), s.capitalize()): val = str2bool(s2) print('"%s" -> %s. Expected=%s' % (s2, expected, val)) assert val == expected, \ '"%s" does not produce expected %s' % (s2, expected)
def test_bad_strings(): for s in ('foo', 'bar', 'xxx', 'yyy', ''): with pytest.raises(ValueError): str2bool(s)