def test_attribute(): ir = transform(""" def test_func(): foo.value = 42 """) assert ir == [ AutowrapTest("test_func", [Assignment( Attribute('foo', 'value'), NumLiteral(42), )]) ]
def test_import(): ir = transform(""" def test_import(): import foo, bar a = foo.GLOBAL """) assert ir == [ AutowrapTest("test_import", [ Import("foo", []), Import("bar", []), Assignment( 'a', Attribute('foo', 'GLOBAL'), ) ]) ]
def test_assertion_call_method_on_lvalue(): ir = transform(""" def test_func(): obj.func(42, 3.3) """) assert ir == [ AutowrapTest("test_func", [ FunctionCall( Attribute( 'obj', 'func', ), [NumLiteral(42), NumLiteral(3.3)], ), ]) ]
def test_assertion_call_method_on_rvalue(): ir = transform(""" def test_func(): from mod import Klass Klass('ctor_arg').func(42, 3.3) """) assert ir == [ AutowrapTest("test_func", [ Import('mod', ['Klass']), FunctionCall( Attribute( FunctionCall('Klass', [StringLiteral('ctor_arg')]), 'func', ), [NumLiteral(42), NumLiteral(3.3)], ), ]) ]
def test_length(): ir = transform(""" def test_length(): lst = [1] len(lst) """) assert ir == [ AutowrapTest( "test_length", [ Assignment('lst', Sequence([NumLiteral(1)])), FunctionCall( Attribute( 'lst', 'length', ), [], # args ) ]) ]