From 20f860017b2128c6f946eac93ccbfbe7fabaebf4 Mon Sep 17 00:00:00 2001 From: Eric Brown Date: Sat, 22 Apr 2023 20:58:11 -0700 Subject: [PATCH] Add testcase of an import within a function Due to scope, an import shouldn't be found if defined in a function but accessed outside of that function. Signed-off-by: Eric Brown --- .../python/third_party/PyYAML/test_yaml_load.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/unit/rules/python/third_party/PyYAML/test_yaml_load.py b/tests/unit/rules/python/third_party/PyYAML/test_yaml_load.py index b8b54cf2..f7b23597 100644 --- a/tests/unit/rules/python/third_party/PyYAML/test_yaml_load.py +++ b/tests/unit/rules/python/third_party/PyYAML/test_yaml_load.py @@ -123,6 +123,19 @@ def test_incomplete_import_yaml_load(self): results = self.parser.parse("test.py", str.encode(fdata)) self.assertEqual(0, len(results)) + def test_import_in_func_yaml_load(self): + fdata = textwrap.dedent( + """ + def test_func(): + import yaml + yaml.load("{}") + """ + ) + results = self.parser.parse("test.py", str.encode(fdata)) + # FIX(ericwb): false positive, shouldn't be able to find import due + # to scope. + self.assertEqual(1, len(results)) + def test_yaml_load_positional_loader(self): fdata = textwrap.dedent( """