From a69a7ffee6f69f45bbc798eb3521553d9df3bfe9 Mon Sep 17 00:00:00 2001 From: andrecs <12188364+andrecsilva@users.noreply.github.com> Date: Thu, 11 Jan 2024 08:20:55 -0300 Subject: [PATCH] New test for builtin base name detection --- tests/test_nameresolution_mixin.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/tests/test_nameresolution_mixin.py b/tests/test_nameresolution_mixin.py index c8b519cd..1bf6ce35 100644 --- a/tests/test_nameresolution_mixin.py +++ b/tests/test_nameresolution_mixin.py @@ -84,7 +84,26 @@ def transform_module_impl(self, tree: cst.Module) -> cst.Module: tree = cst.parse_module(input_code) TestCodemod(CodemodContext()).transform_module(tree) - def test_get_base_name_no_import(self): + def test_get_base_name_no_assignment(self): + class TestCodemod(Codemod, NameResolutionMixin): + def transform_module_impl(self, tree: cst.Module) -> cst.Module: + stmt = cst.ensure_type(tree.body[-1], cst.SimpleStatementLine) + expr = cst.ensure_type(stmt.body[0], cst.Expr) + node = expr.value + + maybe_name = self.find_base_name(node.func) + assert maybe_name == "foo" + return tree + + input_code = dedent( + """\ + foo('hello world') + """ + ) + tree = cst.parse_module(input_code) + TestCodemod(CodemodContext()).transform_module(tree) + + def test_get_base_name_built_in(self): class TestCodemod(Codemod, NameResolutionMixin): def transform_module_impl(self, tree: cst.Module) -> cst.Module: stmt = cst.ensure_type(tree.body[-1], cst.SimpleStatementLine)