[Concept,08/22] buildman: Use tools.write_file() in test.py

Message ID 20260106142834.2511220-9-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>

Replace open() calls with tools.write_file() for consistency and to
fix pylint W1514 (unspecified-encoding) warnings.

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

 tools/buildman/test.py | 20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)
  

Patch

diff --git a/tools/buildman/test.py b/tools/buildman/test.py
index 430e9ee118c..8b015e22090 100644
--- a/tools/buildman/test.py
+++ b/tools/buildman/test.py
@@ -1128,8 +1128,7 @@  class TestBuild(unittest.TestCase):
         with tempfile.TemporaryDirectory() as tmpdir:
             # Create a reference file
             ref_file = os.path.join(tmpdir, 'done')
-            with open(ref_file, 'w') as f:
-                f.write('0\n')
+            tools.write_file(ref_file, b'0\n')
 
             # Test with no Kconfig files - should return False
             self.assertFalse(
@@ -1140,8 +1139,7 @@  class TestBuild(unittest.TestCase):
 
             # Create a Kconfig file newer than the reference
             kconfig = os.path.join(tmpdir, 'Kconfig')
-            with open(kconfig, 'w') as f:
-                f.write('config TEST\n')
+            tools.write_file(kconfig, b'config TEST\n')
 
             # Should now return True since Kconfig is newer
             self.assertTrue(
@@ -1149,8 +1147,7 @@  class TestBuild(unittest.TestCase):
 
             # Create a new reference file (newer than Kconfig)
             time.sleep(0.1)
-            with open(ref_file, 'w') as f:
-                f.write('0\n')
+            tools.write_file(ref_file, b'0\n')
 
             # Should now return False since reference is newer
             self.assertFalse(
@@ -1165,8 +1162,8 @@  class TestBuild(unittest.TestCase):
             subdir = os.path.join(tmpdir, 'sub')
             os.makedirs(subdir)
             time.sleep(0.1)
-            with open(os.path.join(subdir, 'Kconfig.sub'), 'w') as f:
-                f.write('config SUBTEST\n')
+            tools.write_file(os.path.join(subdir, 'Kconfig.sub'),
+                             b'config SUBTEST\n')
 
             # Should return True due to newer Kconfig.sub in subdir
             self.assertTrue(
@@ -1174,8 +1171,7 @@  class TestBuild(unittest.TestCase):
 
             # Create a new reference file (newer than all Kconfig files)
             time.sleep(0.1)
-            with open(ref_file, 'w') as f:
-                f.write('0\n')
+            tools.write_file(ref_file, b'0\n')
 
             # Should now return False
             self.assertFalse(
@@ -1185,8 +1181,8 @@  class TestBuild(unittest.TestCase):
             configs_dir = os.path.join(tmpdir, 'configs')
             os.makedirs(configs_dir)
             time.sleep(0.1)
-            with open(os.path.join(configs_dir, 'sandbox_defconfig'), 'w') as f:
-                f.write('CONFIG_SANDBOX=y\n')
+            tools.write_file(os.path.join(configs_dir, 'sandbox_defconfig'),
+                             b'CONFIG_SANDBOX=y\n')
 
             # Without target, defconfig is not checked
             self.assertFalse(