def test_statements_in_module_body_are_transformed(self): module_node = nodes.module([nodes.expression_statement(nodes.ref("value"))], is_executable=True) module_type = types.module("blah", []) _assert_transform( module_node, cc.module([cc.expression_statement(cc.ref("value"))], is_executable=True, exported_names=[]), type_lookup=[(module_node, module_type)] )
def builtin_modules_are_typed(): cgi_module = BuiltinModule("cgi", types.module("cgi", [ types.attr("escape", types.none_type), ])) node = nodes.Import([nodes.import_alias("cgi", None)]) context = update_blank_context( node, module_resolver=FakeModuleResolver({("cgi",): cgi_module}), module_types=FakeModuleTypes({}), ) assert_equal(types.none_type, context.lookup_name("cgi").attrs.type_of("escape"))
def test_module_exports_are_set_directly_on_module(self): module_node = nodes.module( [nodes.assign([nodes.ref("value")], nodes.none())], is_executable=False ) module_type = types.module("blah", [types.attr("value", types.none_type)]) _assert_transform( module_node, cc.module( [ cc.declare("value"), cc.assign(cc.ref("value"), cc.none) ], is_executable=False, exported_names=["value"], ), type_lookup=[(module_node, module_type)] )
def value_in_builtin_module_can_be_resolved(self): # import cgi cgi_module = BuiltinModule( "cgi", types.module("cgi", [types.attr("escape", types.none_type)]) ) module_resolver = _module_resolver( _create_module("root/main.py", is_executable=True), builtin_modules={"cgi": cgi_module} ) resolved_import = module_resolver.resolve_import_value( ["cgi"], "escape", ) assert_is(cgi_module, resolved_import.module) assert_equal("escape", resolved_import.attr_name) assert_equal(["cgi"], resolved_import.module_name)
def module(name, attrs=None): if attrs is None: attrs = [] return types.module(name, attrs)