[Concept,04/11] buildman: Use tools.read_file/write_file in test_bsettings.py

Message ID 20260104200844.481633-5-sjg@u-boot.org
State New
Headers
Series buildman: Pylint cleanups |

Commit Message

Simon Glass Jan. 4, 2026, 8:08 p.m. UTC
  From: Simon Glass <simon.glass@canonical.com>

Replace direct open() calls with tools.read_file() and
tools.write_file() for consistency with other U-Boot Python code.

Also move shutil import to top level.

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

 tools/buildman/test_bsettings.py | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)
  

Patch

diff --git a/tools/buildman/test_bsettings.py b/tools/buildman/test_bsettings.py
index 524281f49b0..87cc3c19dd9 100644
--- a/tools/buildman/test_bsettings.py
+++ b/tools/buildman/test_bsettings.py
@@ -4,11 +4,13 @@ 
 """Tests for bsettings.py"""
 
 import os
+import shutil
 import tempfile
 import unittest
 from unittest import mock
 
 from buildman import bsettings
+from u_boot_pylib import tools
 
 
 class TestBsettings(unittest.TestCase):
@@ -18,7 +20,6 @@  class TestBsettings(unittest.TestCase):
         self._tmpdir = tempfile.mkdtemp()
 
     def tearDown(self):
-        import shutil
         shutil.rmtree(self._tmpdir)
 
     def test_setup_no_file(self):
@@ -44,8 +45,8 @@  class TestBsettings(unittest.TestCase):
     def test_setup_existing_file(self):
         """Test setup() reads existing config file"""
         config_file = os.path.join(self._tmpdir, 'test.buildman')
-        with open(config_file, 'w') as f:
-            f.write('[toolchain]\narm = /opt/arm\n')
+        tools.write_file(config_file, '[toolchain]\narm = /opt/arm\n',
+                         binary=False)
 
         bsettings.setup(config_file)
         items = bsettings.get_items('toolchain')
@@ -88,8 +89,7 @@  class TestBsettings(unittest.TestCase):
     def test_set_item(self):
         """Test set_item() sets value and writes to file"""
         config_file = os.path.join(self._tmpdir, 'test_set.buildman')
-        with open(config_file, 'w') as f:
-            f.write('[toolchain]\n')
+        tools.write_file(config_file, '[toolchain]\n', binary=False)
 
         bsettings.setup(config_file)
         bsettings.set_item('toolchain', 'newkey', 'newvalue')
@@ -99,8 +99,7 @@  class TestBsettings(unittest.TestCase):
         self.assertEqual('newvalue', items['newkey'])
 
         # Value should be written to file
-        with open(config_file) as f:
-            content = f.read()
+        content = tools.read_file(config_file, binary=False)
         self.assertIn('newkey', content)
         self.assertIn('newvalue', content)
 
@@ -122,8 +121,7 @@  class TestBsettings(unittest.TestCase):
         bsettings.create_buildman_config_file(config_file)
 
         self.assertTrue(os.path.exists(config_file))
-        with open(config_file) as f:
-            content = f.read()
+        content = tools.read_file(config_file, binary=False)
         self.assertIn('[toolchain]', content)
         self.assertIn('[toolchain-prefix]', content)
         self.assertIn('[toolchain-alias]', content)