From: Tamir Duberstein <tamird@gmail.com>
To: "Kernel.org Tools" <tools@kernel.org>
Cc: Konstantin Ryabitsev <konstantin@linuxfoundation.org>,
Tamir Duberstein <tamird@gmail.com>
Subject: [PATCH 12/14] Use CompletedProcess in git config tests
Date: Fri, 10 Apr 2026 18:38:03 -0400 [thread overview]
Message-ID: <20260410-harden-type-checking-v1-12-fcf314d9d748@gmail.com> (raw)
In-Reply-To: <20260410-harden-type-checking-v1-0-fcf314d9d748@gmail.com>
Replace MagicMock subprocess results with real
subprocess.CompletedProcess values in the git config helper tests. This
keeps the behavior the same while giving the mocks a concrete,
type-checked shape.
Signed-off-by: Tamir Duberstein <tamird@gmail.com>
---
tests/test_node.py | 77 +++++++++++++++++++++++++++++++-----------------------
1 file changed, 45 insertions(+), 32 deletions(-)
diff --git a/tests/test_node.py b/tests/test_node.py
index 73c79a3..89be909 100644
--- a/tests/test_node.py
+++ b/tests/test_node.py
@@ -5,6 +5,7 @@ from __future__ import annotations
import gzip
import os
+import subprocess
from datetime import datetime, timezone
from email.message import EmailMessage
from unittest.mock import MagicMock, call, patch
@@ -1557,15 +1558,17 @@ class TestGetConfigFromGit:
"""Parses git config -z output correctly."""
from liblore.node import _get_config_from_git
- mock_result = MagicMock()
- mock_result.returncode = 0
- mock_result.stdout = (
- 'lore.fallback\nhttps://tor.lore.kernel.org\x00'
- 'lore.fallback\nhttps://sea.lore.kernel.org\x00'
- 'lore.autoprobe\ntrue\x00'
- 'lore.probettl\n7200\x00'
+ result = subprocess.CompletedProcess[str](
+ args=['git'],
+ returncode=0,
+ stdout=(
+ 'lore.fallback\nhttps://tor.lore.kernel.org\x00'
+ 'lore.fallback\nhttps://sea.lore.kernel.org\x00'
+ 'lore.autoprobe\ntrue\x00'
+ 'lore.probettl\n7200\x00'
+ ),
)
- with patch('liblore.node.subprocess.run', return_value=mock_result):
+ with patch('liblore.node.subprocess.run', return_value=result):
cfg = _get_config_from_git(r'^lore\.', multivals=['fallback'])
assert cfg == {
@@ -1593,10 +1596,12 @@ class TestGetConfigFromGit:
"""Returns empty dict when no keys match the regexp."""
from liblore.node import _get_config_from_git
- mock_result = MagicMock()
- mock_result.returncode = 1
- mock_result.stdout = ''
- with patch('liblore.node.subprocess.run', return_value=mock_result):
+ result = subprocess.CompletedProcess[str](
+ args=['git'],
+ returncode=1,
+ stdout='',
+ )
+ with patch('liblore.node.subprocess.run', return_value=result):
cfg = _get_config_from_git(r'^lore\.')
assert cfg == {}
@@ -1605,10 +1610,12 @@ class TestGetConfigFromGit:
"""A key without a value (no newline) defaults to 'true'."""
from liblore.node import _get_config_from_git
- mock_result = MagicMock()
- mock_result.returncode = 0
- mock_result.stdout = 'lore.autoprobe\x00'
- with patch('liblore.node.subprocess.run', return_value=mock_result):
+ result = subprocess.CompletedProcess[str](
+ args=['git'],
+ returncode=0,
+ stdout='lore.autoprobe\x00',
+ )
+ with patch('liblore.node.subprocess.run', return_value=result):
cfg = _get_config_from_git(r'^lore\.')
assert cfg == {'autoprobe': 'true'}
@@ -1621,15 +1628,17 @@ class TestGetSubsectionConfig:
"""Parses keys from [liblore "https://lore.kernel.org"]."""
from liblore.node import _get_subsection_config
- mock_result = MagicMock()
- mock_result.returncode = 0
- mock_result.stdout = (
- 'liblore.https://lore.kernel.org.fallback\nhttps://tor.lore.kernel.org\x00'
- 'liblore.https://lore.kernel.org.fallback\nhttps://sea.lore.kernel.org\x00'
- 'liblore.https://lore.kernel.org.autoprobe\ntrue\x00'
- 'liblore.https://lore.kernel.org.useragentplus\nmyuuid\x00'
+ result = subprocess.CompletedProcess[str](
+ args=['git'],
+ returncode=0,
+ stdout=(
+ 'liblore.https://lore.kernel.org.fallback\nhttps://tor.lore.kernel.org\x00'
+ 'liblore.https://lore.kernel.org.fallback\nhttps://sea.lore.kernel.org\x00'
+ 'liblore.https://lore.kernel.org.autoprobe\ntrue\x00'
+ 'liblore.https://lore.kernel.org.useragentplus\nmyuuid\x00'
+ ),
)
- with patch('liblore.node.subprocess.run', return_value=mock_result):
+ with patch('liblore.node.subprocess.run', return_value=result):
cfg = _get_subsection_config(
'liblore',
'https://lore.kernel.org',
@@ -1649,10 +1658,12 @@ class TestGetSubsectionConfig:
"""Subsection names with dots (URLs) are parsed correctly."""
from liblore.node import _get_subsection_config
- mock_result = MagicMock()
- mock_result.returncode = 0
- mock_result.stdout = 'liblore.https://subspace.kernel.org.fallback\nhttps://mirror.example.com\x00'
- with patch('liblore.node.subprocess.run', return_value=mock_result):
+ result = subprocess.CompletedProcess[str](
+ args=['git'],
+ returncode=0,
+ stdout='liblore.https://subspace.kernel.org.fallback\nhttps://mirror.example.com\x00',
+ )
+ with patch('liblore.node.subprocess.run', return_value=result):
cfg = _get_subsection_config(
'liblore',
'https://subspace.kernel.org',
@@ -1667,10 +1678,12 @@ class TestGetSubsectionConfig:
"""Returns empty dict when no keys match the subsection."""
from liblore.node import _get_subsection_config
- mock_result = MagicMock()
- mock_result.returncode = 1
- mock_result.stdout = ''
- with patch('liblore.node.subprocess.run', return_value=mock_result):
+ result = subprocess.CompletedProcess[str](
+ args=['git'],
+ returncode=1,
+ stdout='',
+ )
+ with patch('liblore.node.subprocess.run', return_value=result):
cfg = _get_subsection_config(
'liblore',
'https://nonexistent.example.com',
--
2.53.0
next prev parent reply other threads:[~2026-04-10 22:38 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-10 22:37 [PATCH 00/14] Harden local type checking and test mocking Tamir Duberstein
2026-04-10 22:37 ` [PATCH 01/14] Add b4 CI checks and mypy suppressions Tamir Duberstein
2026-04-10 22:37 ` [PATCH 02/14] Type make_msg and drop test suppressions Tamir Duberstein
2026-04-10 22:37 ` [PATCH 03/14] Add ruff import checks to b4 CI Tamir Duberstein
2026-04-10 22:37 ` [PATCH 04/14] Add ruff format check to CI Tamir Duberstein
2026-04-10 22:37 ` [PATCH 05/14] Add pyright strict checks " Tamir Duberstein
2026-04-10 22:37 ` [PATCH 06/14] Replace HTTP session mocks with responses Tamir Duberstein
2026-04-10 22:37 ` [PATCH 07/14] Add ty checks to CI Tamir Duberstein
2026-04-10 22:37 ` [PATCH 08/14] Drop redundant read-only property test Tamir Duberstein
2026-04-10 22:38 ` [PATCH 09/14] Type from_git_config keyword arguments Tamir Duberstein
2026-04-10 22:38 ` [PATCH 10/14] Add authheaders stub and typed callable Tamir Duberstein
2026-04-10 22:38 ` [PATCH 11/14] Replace batch mocks with subclasses Tamir Duberstein
2026-04-10 22:38 ` Tamir Duberstein [this message]
2026-04-10 22:38 ` [PATCH 13/14] Update README for uv-based dev checks Tamir Duberstein
2026-04-10 22:38 ` [PATCH 14/14] Add b4 send configuration Tamir Duberstein
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260410-harden-type-checking-v1-12-fcf314d9d748@gmail.com \
--to=tamird@gmail.com \
--cc=konstantin@linuxfoundation.org \
--cc=tools@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox