def test_string_constructors(): good_inputs = [ '', 'a b c', '{{a}} b {{c}}', '%d', unicodey('unic\u215bde should work too, yo!'), 1.0, 1, 1e3, 1.0e3 ] for input in good_inputs: str(String(input)) repr(String(input))
def test_hash(): map = { Integer(1): 'foo', String("bar"): 'baz', Float('{{herp}}'): 'derp', Boolean('true'): 'slerp' } assert Integer(1) in map assert String("bar") in map assert Float('{{herp}}') in map assert Float('{{derp}}') not in map assert Integer(2) not in map assert String("baz") not in map assert Boolean('false') not in map assert Boolean('true') in map
def test_bad_inputs(): for typ in Float, Integer, String, Boolean: with pytest.raises(TypeError): typ() with pytest.raises(TypeError): typ("1", "2") with pytest.raises(TypeError): typ(foo='123') bad_inputs = [{ 1: 2 }, None, type, Float, Integer, String, Boolean, Float(1), Integer(1), String(1), Boolean(1)] for inp in bad_inputs: with pytest.raises(SimpleObject.CoercionError): '%s' % typ(inp)
def test_cmp(): assert not Float(1) == Integer(1) assert Float(1) != Integer(1) assert not String(1) == Integer(1) assert Integer(1) < Integer(2) assert Integer(2) > Integer(1) assert Integer(1) == Integer(1) assert String("a") < String("b") assert String("a") == String("a") assert String("b") > String("a") assert Float(1) < Float(2) assert Float(2) > Float(1) assert Float(1) == Float(1) assert Float(1.1) > Float(1) # all types < for typ1 in (Float, String, Integer): for typ2 in (Float, String, Integer): if typ1 != typ2: assert typ1(1) < typ2(1) assert typ1(1) <= typ2(1) assert not typ1(1) > typ2(1) assert not typ1(1) >= typ2(1)