diff mbox series

[1/6] tests.data: add test for inline python calling a def'd function

Message ID 20230801143813.2206785-1-richard.purdie@linuxfoundation.org
State Accepted, archived
Commit 9f7cb22febd557817c164e25a93f5660e9c06358
Headers show
Series [1/6] tests.data: add test for inline python calling a def'd function | expand

Commit Message

Richard Purdie Aug. 1, 2023, 2:38 p.m. UTC
From: Christopher Larson <kergoth@gmail.com>

This is a test for an issue seen long ago, to avoid regressions, where a
reference to a def'd function in the metadata would return the string
value from the metadata rather than the function in inline python.

Signed-off-by: Christopher Larson <kergoth@gmail.com>
---
 lib/bb/tests/data.py | 9 +++++++++
 1 file changed, 9 insertions(+)
diff mbox series

Patch

diff --git a/lib/bb/tests/data.py b/lib/bb/tests/data.py
index 8c043b709d..251130b857 100644
--- a/lib/bb/tests/data.py
+++ b/lib/bb/tests/data.py
@@ -77,6 +77,15 @@  class DataExpansions(unittest.TestCase):
         val = self.d.expand("${@d.getVar('foo') + ' ${bar}'}")
         self.assertEqual(str(val), "value_of_foo value_of_bar")
 
+    def test_python_snippet_function_reference(self):
+        self.d.setVar("TESTVAL", "testvalue")
+        self.d.setVar("testfunc", 'd.getVar("TESTVAL")')
+        self.d.setVarFlag("testfunc", "func", "1")
+        context = bb.utils.get_context()
+        context["testfunc"] = lambda d: d.getVar("TESTVAL")
+        val = self.d.expand("${@testfunc(d)}")
+        self.assertEqual(str(val), "testvalue")
+
     def test_python_unexpanded(self):
         self.d.setVar("bar", "${unsetvar}")
         val = self.d.expand("${@d.getVar('foo') + ' ${bar}'}")