def test_infer_argument(): func, _ = function(0)( 'def double(x):\n' ' return x * 2') ret, constrains = infer_function(func) eq_(ret, SymbolType('x')) eq_(constrains, {(SymbolType('x'), Types.Integer)})
def test_infer_function(): func, _ = function(0)( 'def just_two(x):\n' ' if x > 5:\n' ' return 3\n' ' return 2') eq_(infer_function(func), (Types.Integer, {(SymbolType('x'), Types.Integer)}))
def test_no_arguments(self): p = function(0) node, r = p( 'def just_five():\n' ' return 5') eq_(node.name, 'just_five') eq_(node.args, []) eq_(node.body.body, [ Return(NumericLiteral('5'))])
def test_simple(self): p = function(0) node, r = p( 'def test_func(arg1, arg2):\n' ' x = 5') eq_(r, '') assert_is_instance(node, Function) eq_(node.name, 'test_func') eq_(node.args[0], 'arg1') eq_(node.args[1], 'arg2') eq_(node.body.body, [ Assignment(NumericLiteral('5'), Symbol('x'))])
def test_missing_body(self): p = function(0) eq_(p( 'def test_func(arg1, arg2):\n(!)@#!('), None)
def test_infer_error(): func, _ = function(0)( 'def just_two(x):\n' ' if x > 5:\n' ' return "hello"\n' ' return 2')