[Concept,04/20] buildman: Fix pylint warnings in test_builder.py

Message ID 20260316154733.1587261-5-sjg@u-boot.org
State New
Headers
Series buildman: Add distributed builds |

Commit Message

Simon Glass March 16, 2026, 3:47 p.m. UTC
  From: Simon Glass <sjg@chromium.org>

Remove unused OUTCOME_WARNING import, prefix unused mock arguments with
underscore, and replace unnecessary lambda wrappers around datetime with
direct references.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 tools/buildman/test_builder.py | 61 ++++++++++++++++++----------------
 1 file changed, 33 insertions(+), 28 deletions(-)
  

Patch

diff --git a/tools/buildman/test_builder.py b/tools/buildman/test_builder.py
index ec1e0301a6e..70a8b365f2a 100644
--- a/tools/buildman/test_builder.py
+++ b/tools/buildman/test_builder.py
@@ -4,6 +4,8 @@ 
 
 """Unit tests for builder.py"""
 
+# pylint: disable=W0212
+
 from datetime import datetime
 import os
 import shutil
@@ -12,7 +14,7 @@  from unittest import mock
 
 from buildman import builder
 from buildman import builderthread
-from buildman.outcome import (DisplayOptions, OUTCOME_OK, OUTCOME_WARNING,
+from buildman.outcome import (DisplayOptions, OUTCOME_OK,
                               OUTCOME_ERROR, OUTCOME_UNKNOWN)
 from buildman.resulthandler import ResultHandler
 from u_boot_pylib import gitutil
@@ -183,7 +185,7 @@  class TestPrepareThread(unittest.TestCase):
     @mock.patch.object(gitutil, 'fetch')
     @mock.patch.object(os.path, 'isdir', return_value=True)
     @mock.patch.object(builderthread, 'mkdir')
-    def test_existing_clone(self, mock_mkdir, mock_isdir, mock_fetch):
+    def test_existing_clone(self, _mock_mkdir, _mock_isdir, mock_fetch):
         """Test with existing git clone (fetches updates)"""
         terminal.get_print_test_lines()  # Clear
         self.builder._prepare_thread(0, 'clone')
@@ -196,7 +198,7 @@  class TestPrepareThread(unittest.TestCase):
     @mock.patch.object(os.path, 'isfile', return_value=True)
     @mock.patch.object(os.path, 'isdir', return_value=False)
     @mock.patch.object(builderthread, 'mkdir')
-    def test_existing_worktree(self, mock_mkdir, mock_isdir, mock_isfile):
+    def test_existing_worktree(self, _mock_mkdir, _mock_isdir, _mock_isfile):
         """Test with existing worktree (no action needed)"""
         terminal.get_print_test_lines()  # Clear
         self.builder._prepare_thread(0, 'worktree')
@@ -209,8 +211,8 @@  class TestPrepareThread(unittest.TestCase):
     @mock.patch.object(os.path, 'isfile', return_value=False)
     @mock.patch.object(os.path, 'isdir', return_value=False)
     @mock.patch.object(builderthread, 'mkdir')
-    def test_invalid_git_dir(self, mock_mkdir, mock_isdir, mock_isfile,
-                             mock_exists):
+    def test_invalid_git_dir(self, _mock_mkdir, _mock_isdir, _mock_isfile,
+                             _mock_exists):
         """Test with git_dir that exists but is neither file nor directory"""
         with self.assertRaises(ValueError) as ctx:
             self.builder._prepare_thread(0, 'clone')
@@ -222,8 +224,8 @@  class TestPrepareThread(unittest.TestCase):
     @mock.patch.object(os.path, 'isfile', return_value=False)
     @mock.patch.object(os.path, 'isdir', return_value=False)
     @mock.patch.object(builderthread, 'mkdir')
-    def test_create_worktree(self, mock_mkdir, mock_isdir, mock_isfile,
-                             mock_exists, mock_add_worktree):
+    def test_create_worktree(self, _mock_mkdir, _mock_isdir, _mock_isfile,
+                             _mock_exists, mock_add_worktree):
         """Test creating a new worktree"""
         terminal.get_print_test_lines()  # Clear
         self.builder._prepare_thread(0, 'worktree')
@@ -238,8 +240,8 @@  class TestPrepareThread(unittest.TestCase):
     @mock.patch.object(os.path, 'isfile', return_value=False)
     @mock.patch.object(os.path, 'isdir', return_value=False)
     @mock.patch.object(builderthread, 'mkdir')
-    def test_create_clone(self, mock_mkdir, mock_isdir, mock_isfile,
-                          mock_exists, mock_clone):
+    def test_create_clone(self, _mock_mkdir, _mock_isdir, _mock_isfile,
+                          _mock_exists, mock_clone):
         """Test creating a new clone"""
         terminal.get_print_test_lines()  # Clear
         self.builder._prepare_thread(0, 'clone')
@@ -254,8 +256,8 @@  class TestPrepareThread(unittest.TestCase):
     @mock.patch.object(os.path, 'isfile', return_value=False)
     @mock.patch.object(os.path, 'isdir', return_value=False)
     @mock.patch.object(builderthread, 'mkdir')
-    def test_create_clone_with_true(self, mock_mkdir, mock_isdir, mock_isfile,
-                                    mock_exists, mock_clone):
+    def test_create_clone_with_true(self, _mock_mkdir, _mock_isdir,
+                                    _mock_isfile, _mock_exists, mock_clone):
         """Test creating a clone when setup_git=True"""
         terminal.get_print_test_lines()  # Clear
         self.builder._prepare_thread(0, True)
@@ -266,8 +268,8 @@  class TestPrepareThread(unittest.TestCase):
     @mock.patch.object(os.path, 'isfile', return_value=False)
     @mock.patch.object(os.path, 'isdir', return_value=False)
     @mock.patch.object(builderthread, 'mkdir')
-    def test_invalid_setup_git(self, mock_mkdir, mock_isdir, mock_isfile,
-                               mock_exists):
+    def test_invalid_setup_git(self, _mock_mkdir, _mock_isdir, _mock_isfile,
+                               _mock_exists):
         """Test with invalid setup_git value"""
         with self.assertRaises(ValueError) as ctx:
             self.builder._prepare_thread(0, 'invalid')
@@ -304,9 +306,10 @@  class TestPrepareWorkingSpace(unittest.TestCase):
 
     @mock.patch.object(builder.Builder, '_prepare_thread')
     @mock.patch.object(gitutil, 'prune_worktrees')
-    @mock.patch.object(gitutil, 'check_worktree_is_available', return_value=True)
+    @mock.patch.object(gitutil, 'check_worktree_is_available',
+                       return_value=True)
     @mock.patch.object(builderthread, 'mkdir')
-    def test_worktree_available(self, mock_mkdir, mock_check_worktree,
+    def test_worktree_available(self, _mock_mkdir, mock_check_worktree,
                                 mock_prune, mock_prepare_thread):
         """Test when worktree is available"""
         self.builder._prepare_working_space(3, True)
@@ -320,9 +323,10 @@  class TestPrepareWorkingSpace(unittest.TestCase):
         mock_prepare_thread.assert_any_call(2, 'worktree')
 
     @mock.patch.object(builder.Builder, '_prepare_thread')
-    @mock.patch.object(gitutil, 'check_worktree_is_available', return_value=False)
+    @mock.patch.object(gitutil, 'check_worktree_is_available',
+                       return_value=False)
     @mock.patch.object(builderthread, 'mkdir')
-    def test_worktree_not_available(self, mock_mkdir, mock_check_worktree,
+    def test_worktree_not_available(self, _mock_mkdir, mock_check_worktree,
                                     mock_prepare_thread):
         """Test when worktree is not available (falls back to clone)"""
         self.builder._prepare_working_space(2, True)
@@ -335,7 +339,7 @@  class TestPrepareWorkingSpace(unittest.TestCase):
 
     @mock.patch.object(builder.Builder, '_prepare_thread')
     @mock.patch.object(builderthread, 'mkdir')
-    def test_zero_threads(self, mock_mkdir, mock_prepare_thread):
+    def test_zero_threads(self, _mock_mkdir, mock_prepare_thread):
         """Test with max_threads=0 (should still prepare 1 thread)"""
         self.builder._prepare_working_space(0, False)
 
@@ -345,7 +349,7 @@  class TestPrepareWorkingSpace(unittest.TestCase):
 
     @mock.patch.object(builder.Builder, '_prepare_thread')
     @mock.patch.object(builderthread, 'mkdir')
-    def test_no_git_dir(self, mock_mkdir, mock_prepare_thread):
+    def test_no_git_dir(self, _mock_mkdir, mock_prepare_thread):
         """Test with no git_dir set"""
         self.builder.git_dir = None
         self.builder._prepare_working_space(2, True)
@@ -394,7 +398,7 @@  class TestShowNotBuilt(unittest.TestCase):
         self.assertEqual(len(lines), 0)
 
     def test_some_boards_unknown(self):
-        """Test when some boards have OUTCOME_UNKNOWN (e.g. missing toolchain)"""
+        """Test when some boards have OUTCOME_UNKNOWN"""
         board_selected = {'board1': None, 'board2': None, 'board3': None}
         board_dict = {
             'board1': self._make_outcome(OUTCOME_OK),
@@ -430,7 +434,7 @@  class TestShowNotBuilt(unittest.TestCase):
         self.assertIn('board2', lines[0].text)
 
     def test_build_error_not_counted(self):
-        """Test that build errors (not toolchain) are not counted as 'not built'"""
+        """Test that build errors are not counted as 'not built'"""
         board_selected = {'board1': None, 'board2': None}
         board_dict = {
             'board1': self._make_outcome(OUTCOME_OK),
@@ -450,8 +454,9 @@  class TestShowNotBuilt(unittest.TestCase):
         board_selected = {'board1': None, 'board2': None, 'board3': None}
         board_dict = {
             'board1': self._make_outcome(OUTCOME_OK),
-            'board2': self._make_outcome(OUTCOME_ERROR,
-                                         ['Tool chain error for arm: not found']),
+            'board2': self._make_outcome(
+                OUTCOME_ERROR,
+                ['Tool chain error for arm: not found']),
             'board3': self._make_outcome(OUTCOME_ERROR,
                                          ['error: some build error']),
         }
@@ -468,7 +473,7 @@  class TestShowNotBuilt(unittest.TestCase):
         self.assertNotIn('board3', lines[0].text)
 
     def test_board_not_in_dict(self):
-        """Test that boards missing from board_dict are counted as 'not built'"""
+        """Test boards missing from board_dict count as 'not built'"""
         board_selected = {'board1': None, 'board2': None, 'board3': None}
         board_dict = {
             'board1': self._make_outcome(OUTCOME_OK),
@@ -487,7 +492,7 @@  class TestShowNotBuilt(unittest.TestCase):
 
 
 class TestPrepareOutputSpace(unittest.TestCase):
-    """Tests for Builder._prepare_output_space() and _get_output_space_removals()"""
+    """Tests for _prepare_output_space() and _get_output_space_removals()"""
 
     def setUp(self):
         """Set up test fixtures"""
@@ -692,7 +697,7 @@  class TestMake(unittest.TestCase):
         mock_run_one.return_value = mock_result
 
         # Simulate loop detection by setting _terminated during the call
-        def side_effect(*args, **kwargs):
+        def side_effect(*_args, **kwargs):
             # Simulate output_func being called with loop data
             output_func = kwargs.get('output_func')
             if output_func:
@@ -822,7 +827,7 @@  class TestPrintBuildSummary(unittest.TestCase):
         start_time = datetime(2024, 1, 1, 12, 0, 0)
         end_time = datetime(2024, 1, 1, 12, 0, 10)
         mock_datetime.now.return_value = end_time
-        mock_datetime.side_effect = lambda *args, **kwargs: datetime(*args, **kwargs)
+        mock_datetime.side_effect = datetime
 
         terminal.get_print_test_lines()  # Clear
         self.handler.print_build_summary(100, 0, 0, start_time, [])
@@ -839,7 +844,7 @@  class TestPrintBuildSummary(unittest.TestCase):
         start_time = datetime(2024, 1, 1, 12, 0, 0)
         end_time = datetime(2024, 1, 1, 12, 0, 10, 600000)  # 10.6 seconds
         mock_datetime.now.return_value = end_time
-        mock_datetime.side_effect = lambda *args, **kwargs: datetime(*args, **kwargs)
+        mock_datetime.side_effect = datetime
 
         terminal.get_print_test_lines()  # Clear
         self.handler.print_build_summary(100, 0, 0, start_time, [])