Пример #1
0
 def test_multiple_imported_names_in_one_statement_generates_multiple_assignments(self):
     _assert_transform(
         nodes.import_from(["."], [
             nodes.import_alias("x", None),
             nodes.import_alias("y", None),
         ]),
         cc.statements([
             cc.assign(cc.ref("x"), cc.attr(cc.module_ref(["."]), "x")),
             cc.assign(cc.ref("y"), cc.attr(cc.module_ref(["."]), "y")),
         ]),
     )
Пример #2
0
 def test_import_of_module_in_package_assigns_values_for_both_package_and_module(self):
     _assert_transform(
         nodes.import_([
             nodes.import_alias("os.path", None),
         ]),
         cc.statements([
             cc.assign(cc.ref("os"), cc.module_ref(["os"])),
             cc.assign(cc.attr(cc.ref("os"), "path"), cc.module_ref(["os", "path"])),
         ])
     )
Пример #3
0
def test_transform_attribute_access():
    _assert_transform(
        cc.attr(cc.ref("x"), "y"),
        js.call(js.ref("$nope.builtins.getattr"), [js.ref("x"), js.string("y")])
    )
Пример #4
0
def test_transform_assignment_to_attribute_sets_property_directly():
    _assert_transform(
        cc.assign(cc.attr(cc.ref("x"), "y"), cc.ref("z")),
        js.expression_statement(js.assign(js.property_access(js.ref("x"), "y"), js.ref("z"))),
    )
Пример #5
0
 def test_import_from_assigns_value_to_asname_if_asname_is_set(self):
     _assert_transform(
         nodes.import_from(["os", "path"], [nodes.import_alias("join", "j")]),
         cc.assign(cc.ref("j"), cc.attr(cc.module_ref(["os", "path"]), "join")),
     )
Пример #6
0
 def test_transform_getitem(self):
     _assert_transform(
         nodes.subscript(nodes.ref("x"), nodes.ref("y")),
         cc.call(cc.attr(cc.ref("x"), "__getitem__"), [cc.ref("y")])
     )
Пример #7
0
 def test_transform_unary_operation_is_converted_to_call_on_class(self):
     _assert_transform(
         nodes.neg(nodes.ref("x")),
         cc.call(cc.attr(cc.ref("x"), "__neg__"), [])
     )
Пример #8
0
 def test_transform_binary_operation_is_converted_to_call_on_class(self):
     _assert_transform(
         nodes.add(nodes.ref("x"), nodes.ref("y")),
         cc.call(cc.attr(cc.ref("x"), "__add__"), [cc.ref("y")])
     )
Пример #9
0
 def test_import_from_uses_two_dots_to_indicate_import_from_parent_package(self):
     _assert_transform(
         nodes.import_from([".."], [nodes.import_alias("x", None)]),
         cc.assign(cc.ref("x"), cc.attr(cc.module_ref([".."]), "x")),
     )