From patchwork Sun Jan 4 20:08:33 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1263 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767557355; bh=i5BcgVqSj799QkbLxlGBwjEQ8pXB4+VMWzPHpNzXHg4=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=CahAbbNE+z33fwbRYOXzvKjLd5sUdlBqFCgyI6eItPYe4h8kMxX3P5+IZZR8NEFCT b9rpfSIneqGFa8rzZQU9tjUUbQh01nMG8gz7wLME/r7Itbv/hfZxbXIBtB36Yyq3lN XUzIX76d2qVwFyUSrnTs4jTAtuaBhn0nhHH5+eylJ6ma/dWFL1hWgmrD9n/1VHk3B0 IDc8j46O5b/ERktt2yJx1ZL9lULF1fJVLFghsZNc7b6b3XXG+zTjx1mw165Q9YjrjC O+CVY43L6+xS5P/EUSeYJXIegxQEg8wyrqxnfKCPasSJLtWqbvJqoVqVVIi/PCEwQi fMTAOSS4Sun4Q== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 56B1D690D9 for ; Sun, 4 Jan 2026 13:09:15 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id JwIbvl4ytK5Z for ; Sun, 4 Jan 2026 13:09:15 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767557355; bh=i5BcgVqSj799QkbLxlGBwjEQ8pXB4+VMWzPHpNzXHg4=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=CahAbbNE+z33fwbRYOXzvKjLd5sUdlBqFCgyI6eItPYe4h8kMxX3P5+IZZR8NEFCT b9rpfSIneqGFa8rzZQU9tjUUbQh01nMG8gz7wLME/r7Itbv/hfZxbXIBtB36Yyq3lN XUzIX76d2qVwFyUSrnTs4jTAtuaBhn0nhHH5+eylJ6ma/dWFL1hWgmrD9n/1VHk3B0 IDc8j46O5b/ERktt2yJx1ZL9lULF1fJVLFghsZNc7b6b3XXG+zTjx1mw165Q9YjrjC O+CVY43L6+xS5P/EUSeYJXIegxQEg8wyrqxnfKCPasSJLtWqbvJqoVqVVIi/PCEwQi fMTAOSS4Sun4Q== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 46476690D1 for ; Sun, 4 Jan 2026 13:09:15 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767557353; bh=cSsd5HXB9UNr1XTR650BeFB9xNF2AOJEL1wGEgiGd6E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uGS5D3ZWtApBMzLVmAQ0RLKCiZ5ZbRUZRSl1Hbg1PL5QBezx2vc4dksyBO4/Zyysu RLUBQe1Jl6xufD+uw6EgfLd9++obJRWvqHoPmFzlSb00BjYw3nVvSuzRN4h0XKXE2J DkfFYZUnxJ/xy+dCRYu6epebMqpqlylmNsDcCUkX0TwzSZNDWJiB80Ll45GopmoADX IAxuxA74LTuCPkYCJnoT5n0ShBslgxT92p/iNG0IzW0TMJ9kR5mw6b62jr48bv2jJY BAfrlC+JyCAXUo2xOSb72fXd2AWFJGdFCzGZfU0z+kDfZus3tQPO++zDk/dha8LHHI va8hWllyCHutg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 41F23690D1; Sun, 4 Jan 2026 13:09:13 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id U5_0dgb4wv3T; Sun, 4 Jan 2026 13:09:13 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767557349; bh=SynG139dLRrR5duEsrCXWPsn6nK6qQLEGL4XPc30wtQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WgMRZZZOIDqoG9e2af3e17LCuHz0yEENfMe8d86yK0zbvyqW+E8pJMgKmKYNhSD6T CwiqMSqCidAwwWY/43BpdIUhh/N6X2eNmU4b1k4PNTSLStWMtbTn3hrP5FGfokk1Qf tCr1M4LMAlOA05Pk4OXzPfX+un8ojhqBcalKeBWOy3KiyoprRSXlt6Mnd7JqmFG09v 72VpYjtfFUoKyTX3hbX51CF91EOaYHm3HrN60C/LIG5R5IMW5lsk8nxB+90g1mxhm7 UHWKlOQ6cSDj4tgm7Drr7DCA933989+pwh/NyXEWLoXorSFE7yYutOLMX87XsVfFKP 1VrUqvHdQmRgw== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 097F469003; Sun, 4 Jan 2026 13:09:08 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Sun, 4 Jan 2026 13:08:33 -0700 Message-ID: <20260104200844.481633-5-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260104200844.481633-1-sjg@u-boot.org> References: <20260104200844.481633-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: QL5FARGLCNPXRFZCXDH2SGLJ2O4I6CJF X-Message-ID-Hash: QL5FARGLCNPXRFZCXDH2SGLJ2O4I6CJF X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Heinrich Schuchardt , Simon Glass , Claude X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 04/11] buildman: Use tools.read_file/write_file in test_bsettings.py List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass 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 Signed-off-by: Simon Glass --- tools/buildman/test_bsettings.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) 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)