diff mbox series

[5/6] bitbake-setup: tests: move duplicate code into 'check_setupdir_files'

Message ID 20251105190636.679388-5-alex.kanavin@gmail.com
State Accepted, archived
Commit 16d77c83ae3ce92ddab84d714a93fd3bb7def5e2
Headers show
Series [1/6] bitbake-setup: rename function 'default_settings_path' to 'topdir_settings_path' | expand

Commit Message

Alexander Kanavin Nov. 5, 2025, 7:06 p.m. UTC
From: Johannes Schneider <johannes.schneider@leica-geosystems.com>

All places that called into 'check_setupdir_files' did the same
preparation step to load the upstream-config.json and then pass it
into the function.

Since the 'setuppath' is already passed into the function, and the
name and relative location of the upstream-config.json is fixed,
constructing the file path and loading the json could be done in the
function.

De-duplicate code by loading the json inside the function instead.

Signed-off-by: Johannes Schneider <johannes.schneider@leica-geosystems.com>
---
 lib/bb/tests/setup.py | 20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)
diff mbox series

Patch

diff --git a/lib/bb/tests/setup.py b/lib/bb/tests/setup.py
index a17b8ac46..e18d6fc6a 100644
--- a/lib/bb/tests/setup.py
+++ b/lib/bb/tests/setup.py
@@ -177,10 +177,12 @@  print("BBPATH is {{}}".format(os.environ["BBPATH"]))
         self.git('add {}'.format(name), cwd=self.testrepopath)
         self.git('commit -m "Adding {}"'.format(name), cwd=self.testrepopath)
 
-    def check_setupdir_files(self, setuppath, test_file_content, json_config):
+    def check_setupdir_files(self, setuppath, test_file_content):
+        with open(os.path.join(setuppath, 'config', "config-upstream.json")) as f:
+            config_upstream = json.load(f)
         with open(os.path.join(setuppath, 'layers', 'test-repo', 'test-file')) as f:
             self.assertEqual(f.read(), test_file_content)
-        bitbake_config = json_config["bitbake-config"]
+        bitbake_config = config_upstream["bitbake-config"]
         bb_build_path = os.path.join(setuppath, 'build')
         bb_conf_path = os.path.join(bb_build_path, 'conf')
         self.assertTrue(os.path.exists(os.path.join(bb_build_path, 'init-build-env')))
@@ -198,7 +200,7 @@  print("BBPATH is {{}}".format(os.environ["BBPATH"]))
                 for l in bitbake_config["bb-layers"]:
                     if l.startswith('{THISDIR}/'):
                         thisdir_layer = os.path.join(
-                            os.path.dirname(json_config["path"]),
+                            os.path.dirname(config_upstream["path"]),
                             l.removeprefix("{THISDIR}/"),
                         )
                         self.assertIn(thisdir_layer, bblayers)
@@ -296,9 +298,7 @@  print("BBPATH is {{}}".format(os.environ["BBPATH"]))
             for c in v['buildconfigs']:
                 out = self.runbbsetup("init --non-interactive {} {}".format(v['cmdline'], c))
                 setuppath = os.path.join(self.tempdir, 'bitbake-builds', '{}-{}'.format(cf, c))
-                with open(os.path.join(setuppath, 'config', "config-upstream.json")) as f:
-                    config_upstream = json.load(f)
-                self.check_setupdir_files(setuppath, test_file_content, config_upstream)
+                self.check_setupdir_files(setuppath, test_file_content)
                 os.environ['BBPATH'] = os.path.join(setuppath, 'build')
                 out = self.runbbsetup("status")
                 self.assertIn("Configuration in {} has not changed".format(setuppath), out[0])
@@ -327,9 +327,7 @@  print("BBPATH is {{}}".format(os.environ["BBPATH"]))
             if c in ('gadget', 'gizmo'):
                 self.assertIn("Existing bitbake configuration directory renamed to {}/build/conf-backup.".format(setuppath), out[0])
                 self.assertIn('-{}+{}'.format(prev_test_file_content, test_file_content), out[0])
-            with open(os.path.join(setuppath, 'config', "config-upstream.json")) as f:
-                config_upstream = json.load(f)
-            self.check_setupdir_files(setuppath, test_file_content, config_upstream)
+            self.check_setupdir_files(setuppath, test_file_content)
 
         # make a new branch in the test layer repo, change a file on that branch,
         # make a new commit, update the top level json config to refer to that branch,
@@ -353,6 +351,4 @@  print("BBPATH is {{}}".format(os.environ["BBPATH"]))
             if c in ('gadget', 'gizmo'):
                 self.assertIn("Existing bitbake configuration directory renamed to {}/build/conf-backup.".format(setuppath), out[0])
                 self.assertIn('-{}+{}'.format(prev_test_file_content, test_file_content), out[0])
-            with open(os.path.join(setuppath, 'config', "config-upstream.json")) as f:
-                config_upstream = json.load(f)
-            self.check_setupdir_files(setuppath, test_file_content, config_upstream)
+            self.check_setupdir_files(setuppath, test_file_content)