From patchwork Sun Feb 22 15:42:51 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1932 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=1771775063; bh=ShCeZLDV3QwPa3RgG9AJGUVDnNs1zYn6ooeXvipRXo4=; 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=OKMxLwgYKkrceLD9iY9TRjXJNf4iec0JEn2EZTzvrhZz5FPif0nYPgU/nR87XgsuV Lcyi3KHbjim8UEDn+dAjQYxAep1guylMAu8k9OFA/EdSZylYGLPVHGPd92C3coZiEN 5OPrDDnauVkCzG29tAMaiCMx7nk7CpwKgoaBm6TUvKoCltLUIRa6+oT98x7e8CqD2/ 2+hQ6w+GSppvpluaxWwM/bItVxlcOJ07AtL7GZKtOQFc/K/9EJ0ns7QVSpW8zBOwQC oDprPbhxPcckL9C+RqHYrKGHtMK5OcU5+bWIXPdOrn+65swzEyFFwuCNxdSnSZCBLa 3PCFbQNrZHZTw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 19C5169C5E for ; Sun, 22 Feb 2026 08:44:23 -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 c_qdoSyWoh5o for ; Sun, 22 Feb 2026 08:44:23 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1771775063; bh=ShCeZLDV3QwPa3RgG9AJGUVDnNs1zYn6ooeXvipRXo4=; 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=OKMxLwgYKkrceLD9iY9TRjXJNf4iec0JEn2EZTzvrhZz5FPif0nYPgU/nR87XgsuV Lcyi3KHbjim8UEDn+dAjQYxAep1guylMAu8k9OFA/EdSZylYGLPVHGPd92C3coZiEN 5OPrDDnauVkCzG29tAMaiCMx7nk7CpwKgoaBm6TUvKoCltLUIRa6+oT98x7e8CqD2/ 2+hQ6w+GSppvpluaxWwM/bItVxlcOJ07AtL7GZKtOQFc/K/9EJ0ns7QVSpW8zBOwQC oDprPbhxPcckL9C+RqHYrKGHtMK5OcU5+bWIXPdOrn+65swzEyFFwuCNxdSnSZCBLa 3PCFbQNrZHZTw== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 058CB69D3F for ; Sun, 22 Feb 2026 08:44:23 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1771775061; bh=Jne9q+uICiiAc/1mJy3d87ZMaCg+IrPmYMAWX3FerOs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Rggp44Ol3DyamgCZcHhnSP/Q5UauA0AtG4GzCLIIlv5Iymli0L/7uWAL/WR7bb5y9 QhaH/v+U7MaTh9qVscDIzh31l8NHPZ6H0Y2zm+2R0HPx3H5xUyqCmnrGhl4P/uO0d/ xdQJC55LtZ8lyx2YuwerhKjkpKDxn7sYtId5Y9u4bUAhIK+K/Pn1lDXhoLeG7lbBTO nMY4l2GuNPf4xe5dweTr5oUlWM4hmMPBPZ02Y+5C77LXBEARJns1ERH1Yf9rMS41of 7xNkjJTBpHeTfZ91qGxZN+n68J+gsx4I+cAjru/lHcvjVUExSrLrbdGkBw9TwJg3c2 YVBN1G8RrH5lQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 0B14269C5E; Sun, 22 Feb 2026 08:44:21 -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 sNpoOX-BqNAX; Sun, 22 Feb 2026 08:44:20 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1771775056; bh=PB7uhSWlf9/BoBctg3qaF+U+pun+ycHXls0AkdQNdjU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wul/trDo8F5Z8PVv9wLUvYGy4HnyFIEf29qwM91ZodQxL3P9LPmicN0QCJsdCpWBA w6jUWgSYYcGm8AiVq5dLLWgqCQ8oaXyD8BzLEfIpyqXViOgjDFf9uxVP/7x0+VFEQD wpiEW/o3VyLQ+KOskbdQ6pHEYGPBUytyX98rHCHXE6sdh6Hu2j4Bqc39GHYEocgBZS prhLUkeXS0yHPyOgj2KGAi7O0zlaovbac+7aIj93JFZkCoo+2Qji8jsU4acVDaWQy9 gJm2ZTscmVg92t2jpbXJg/+RiEPg7VGGebUFaLmeS99Vu8N43/T4hI7f2fKNeURuee x6nXN5WjM70qQ== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 3495969D59; Sun, 22 Feb 2026 08:44:16 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Sun, 22 Feb 2026 08:42:51 -0700 Message-ID: <20260222154303.2851319-12-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260222154303.2851319-1-sjg@u-boot.org> References: <20260222154303.2851319-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: ABZZHIUMLJBBG3ZBFI4SQVYVP6VFTYSP X-Message-ID-Hash: ABZZHIUMLJBBG3ZBFI4SQVYVP6VFTYSP 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: Simon Glass , "Claude Opus 4 . 6" X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 11/16] pickman: Use tools for file I/O in tests 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 manual open() calls with tools.read_file() and tools.write_file() in the test file for consistency. Co-developed-by: Claude Opus 4.6 Signed-off-by: Simon Glass --- tools/pickman/ftest.py | 41 +++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/tools/pickman/ftest.py b/tools/pickman/ftest.py index 42ce05962e2..4a58a9371ce 100644 --- a/tools/pickman/ftest.py +++ b/tools/pickman/ftest.py @@ -23,6 +23,7 @@ sys.path.insert(0, os.path.join(our_path, '..')) # pylint: disable=wrong-import-position,import-error,cyclic-import from u_boot_pylib import command from u_boot_pylib import terminal +from u_boot_pylib import tools from u_boot_pylib import tout from pickman import __main__ as pickman @@ -1634,8 +1635,9 @@ class TestConfigFile(unittest.TestCase): def test_get_token_from_config(self): """Test getting token from config file.""" - with open(self.config_file, 'w', encoding='utf-8') as fhandle: - fhandle.write('[gitlab]\ntoken = test-config-token\n') + tools.write_file(self.config_file, + '[gitlab]\ntoken = test-config-token\n', + binary=False) with mock.patch.object(gitlab, 'CONFIG_FILE', self.config_file): token = gitlab.get_token() @@ -1651,8 +1653,8 @@ class TestConfigFile(unittest.TestCase): def test_get_token_config_missing_section(self): """Test config file without gitlab section.""" - with open(self.config_file, 'w', encoding='utf-8') as fhandle: - fhandle.write('[other]\nkey = value\n') + tools.write_file(self.config_file, '[other]\nkey = value\n', + binary=False) with mock.patch.object(gitlab, 'CONFIG_FILE', self.config_file): with mock.patch.dict(os.environ, {'GITLAB_TOKEN': 'env-token'}): @@ -1661,8 +1663,8 @@ class TestConfigFile(unittest.TestCase): def test_get_config_value(self): """Test get_config_value function.""" - with open(self.config_file, 'w', encoding='utf-8') as fhandle: - fhandle.write('[section1]\nkey1 = value1\n') + tools.write_file(self.config_file, '[section1]\nkey1 = value1\n', + binary=False) with mock.patch.object(gitlab, 'CONFIG_FILE', self.config_file): value = gitlab.get_config_value('section1', 'key1') @@ -2149,8 +2151,7 @@ class TestUpdateHistoryWithReview(unittest.TestCase): # Check history file was created self.assertTrue(os.path.exists(control.HISTORY_FILE)) - with open(control.HISTORY_FILE, 'r', encoding='utf-8') as fhandle: - content = fhandle.read() + content = tools.read_file(control.HISTORY_FILE, binary=False) self.assertIn('### Review:', content) self.assertIn('Branch: cherry-abc123', content) @@ -2161,8 +2162,8 @@ class TestUpdateHistoryWithReview(unittest.TestCase): def test_update_history_appends(self): """Test that review handling appends to existing history.""" # Create existing history - with open(control.HISTORY_FILE, 'w', encoding='utf-8') as fhandle: - fhandle.write('Existing history content\n') + tools.write_file(control.HISTORY_FILE, + 'Existing history content\n', binary=False) subprocess.run(['git', 'add', control.HISTORY_FILE], check=True, capture_output=True) subprocess.run(['git', 'commit', '-m', 'Initial'], @@ -2173,8 +2174,7 @@ class TestUpdateHistoryWithReview(unittest.TestCase): resolved=False)] control.update_history('cherry-xyz', comms, 'Fixed it') - with open(control.HISTORY_FILE, 'r', encoding='utf-8') as fhandle: - content = fhandle.read() + content = tools.read_file(control.HISTORY_FILE, binary=False) self.assertIn('Existing history content', content) self.assertIn('### Review:', content) @@ -2496,15 +2496,14 @@ class TestGetHistory(unittest.TestCase): self.assertIn('- aaa111a First commit', commit_msg) # Verify file was written - with open(self.history_file, 'r', encoding='utf-8') as fhandle: - file_content = fhandle.read() + file_content = tools.read_file(self.history_file, binary=False) self.assertEqual(file_content, content) def test_get_history_with_existing(self): """Test get_history appends to existing content.""" # Create existing file - with open(self.history_file, 'w', encoding='utf-8') as fhandle: - fhandle.write('Previous history content\n') + tools.write_file(self.history_file, + 'Previous history content\n', binary=False) commits = [ control.CommitInfo('bbb222', 'bbb222b', 'New commit', 'Author 2'), @@ -2535,8 +2534,7 @@ Old conversation Other content """ - with open(self.history_file, 'w', encoding='utf-8') as fhandle: - fhandle.write(existing) + tools.write_file(self.history_file, existing, binary=False) commits = [ control.CommitInfo('ccc333', 'ccc333c', 'Updated commit', 'Author'), @@ -3055,8 +3053,8 @@ class TestSignalFile(unittest.TestCase): def test_read_signal_file_already_applied(self): """Test read_signal_file with already_applied status.""" - with open(self.signal_path, 'w', encoding='utf-8') as fhandle: - fhandle.write('already_applied\nabc123def456\n') + tools.write_file(self.signal_path, + 'already_applied\nabc123def456\n', binary=False) status, commit = agent.read_signal_file(self.test_dir) self.assertEqual(status, 'already_applied') @@ -3067,8 +3065,7 @@ class TestSignalFile(unittest.TestCase): def test_read_signal_file_status_only(self): """Test read_signal_file with only status line.""" - with open(self.signal_path, 'w', encoding='utf-8') as fhandle: - fhandle.write('conflict\n') + tools.write_file(self.signal_path, 'conflict\n', binary=False) status, commit = agent.read_signal_file(self.test_dir) self.assertEqual(status, 'conflict')