[Concept,19/22] buildman: Split TestBuild into multiple classes in test.py

Message ID 20260106142834.2511220-20-sjg@u-boot.org
State New
Headers
Series buildman: Clean up test.py for pylint compliance |

Commit Message

Simon Glass Jan. 6, 2026, 2:28 p.m. UTC
  From: Simon Glass <simon.glass@canonical.com>

Split TestBuild into a base class and five subclasses to improve code
organisation and reduce method count per class:

- TestBuildBase: Common setUp/tearDown
- TestBuildOutput: Output and summary tests
- TestBuildBoards: Board-selection tests
- TestBuild: Output-directory and toolchain tests
- TestBuildConfig: Config-adjustment tests
- TestBuildMisc: Process-limit and other tests

Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
---

 tools/buildman/main.py |  6 ++++--
 tools/buildman/test.py | 31 +++++++++++++++++++++++++++----
 2 files changed, 31 insertions(+), 6 deletions(-)
  

Patch

diff --git a/tools/buildman/main.py b/tools/buildman/main.py
index 914dfe04988..d85e8dd428d 100755
--- a/tools/buildman/main.py
+++ b/tools/buildman/main.py
@@ -48,8 +48,10 @@  def run_tests(skip_net_tests, debug, verbose, args):
     # 'entry' module.
     result = test_util.run_test_suites(
         'buildman', debug, verbose, False, False, args.threads, test_name, [],
-        [test.TestBuild, func_test.TestFunctional, test_boards.TestBoards,
-         test_bsettings.TestBsettings, 'buildman.toolchain'])
+        [test.TestBuildOutput, test.TestBuildBoards, test.TestBuild,
+         test.TestBuildConfig, test.TestBuildMisc, func_test.TestFunctional,
+         test_boards.TestBoards, test_bsettings.TestBsettings,
+         'buildman.toolchain'])
 
     return (0 if result.wasSuccessful() else 1)
 
diff --git a/tools/buildman/test.py b/tools/buildman/test.py
index 904f4e9a212..40ddb351b3c 100644
--- a/tools/buildman/test.py
+++ b/tools/buildman/test.py
@@ -153,11 +153,10 @@  class Options:
         self.show_errors = False
         self.keep_outputs = False
 
-class TestBuild(unittest.TestCase):
-    """Test buildman
+# pylint: disable=too-many-instance-attributes
+class TestBuildBase(unittest.TestCase):
+    """Base class for buildman tests with common setup"""
 
-    TODO: Write tests for the rest of the functionality
-    """
     def setUp(self):
         # Set up commits to build
         self.commits = []
@@ -207,6 +206,10 @@  class TestBuild(unittest.TestCase):
     def tearDown(self):
         shutil.rmtree(self.base_dir)
 
+
+class TestBuildOutput(TestBuildBase):
+    """Tests for build output and summary display"""
+
     def make(self, cmt, brd, _stage, *_args, **_kwargs):
         """Mock make function for testing build output"""
         result = command.CommandResult()
@@ -518,6 +521,10 @@  class TestBuild(unittest.TestCase):
         args = ['tegra20']
         control.do_buildman(options, args)
 
+
+class TestBuildBoards(TestBuildBase):
+    """Tests for board selection"""
+
     def test_board_single(self):
         """Test single board selection"""
         self.assertEqual(self.brds.select_boards(['sandbox']),
@@ -578,6 +585,14 @@  class TestBuild(unittest.TestCase):
         self.assertEqual(self.brds.select_boards(['sandbox sandbox',
                                                    'sandbox']),
                          ({'all': ['board4'], 'sandbox': ['board4']}, []))
+
+
+class TestBuild(TestBuildBase):
+    """Tests for buildman functionality
+
+    TODO: Write tests for the rest of the functionality
+    """
+
     def check_dirs(self, build, dirname):
         """Check that the output directories are correct"""
         self.assertEqual(f'base{dirname}', build.get_output_dir(1))
@@ -720,6 +735,10 @@  class TestBuild(unittest.TestCase):
         expected = {os.path.join(base_dir, f) for f in to_remove}
         self.assertEqual(expected, result)
 
+
+class TestBuildConfig(TestBuildBase):
+    """Tests for config adjustment functionality"""
+
     def test_adjust_cfg_nop(self):
         """check various adjustments of config that are nops"""
         # enable an enabled CONFIG
@@ -854,6 +873,10 @@  class TestBuild(unittest.TestCase):
             ['MARY="mary"', 'Missing expected line: CONFIG_MARY="mary"']],
             result)
 
+
+class TestBuildMisc(TestBuildBase):
+    """Miscellaneous buildman tests"""
+
     def get_procs(self):
         """Get list of running process IDs from the running file"""
         running_fname = os.path.join(self.base_dir, control.RUNNING_FNAME)