Skip to content
Snippets Groups Projects
Verified Commit 3cd3df4b authored by David Runge's avatar David Runge :chipmunk:
Browse files

fix: Ensure Mock for testing config facilities is called properly


With the update to Python 3.12 the `Mock.has_calls` method has been
removed.
As we can not rely on checks on equality in a call with a
`BufferedReader`, convert those to string instead before comparison,
because life is suffering.

Signed-off-by: default avatarDavid Runge <dvzrv@archlinux.org>
parent 2e97b659
No related branches found
No related tags found
1 merge request!162Add fixes required for venv based builds and Python 3.12
......@@ -250,7 +250,14 @@ def test_usertomlconfig(
{SettingsTypeEnum.USER: override_dir},
):
settings.UserTomlConfig(Mock(spec=settings.UserSettings))()
toml_load_mock.has_calls(call([empty_toml_file] + sorted(empty_toml_files_in_dir.glob("*.toml"))))
# NOTE: ugly hack because we can't compare BufferedReader objects for equality
for required_call in [
call(open(toml_file, "rb"))
for toml_file in [empty_toml_file] + sorted(empty_toml_files_in_dir.glob("*.toml"))
]:
assert str(required_call) in [
str(mock_call) for mock_call in toml_load_mock.mock_calls
] # nosec: B101
with patch("repod.config.settings.SETTINGS_LOCATION", {SettingsTypeEnum.USER: tmp_path / "foo.toml"}):
settings.UserTomlConfig(Mock(spec=settings.UserSettings))
......@@ -259,7 +266,14 @@ def test_usertomlconfig(
{SettingsTypeEnum.USER: override_dir},
):
settings.UserTomlConfig(Mock(spec=settings.UserSettings))()
toml_load_mock.has_calls(call([empty_toml_file] + sorted(empty_toml_files_in_dir.glob("*.toml"))))
# NOTE: ugly hack because we can't compare BufferedReader objects for equality
for required_call in [
call(open(toml_file, "rb"))
for toml_file in [empty_toml_file] + sorted(empty_toml_files_in_dir.glob("*.toml"))
]:
assert str(required_call) in [
str(mock_call) for mock_call in toml_load_mock.mock_calls
] # nosec: B101
@mark.parametrize(
......@@ -294,7 +308,12 @@ def test_systemtomlconfig(
{SettingsTypeEnum.SYSTEM: override_dir},
):
settings.SystemTomlConfig(Mock(spec=settings.SystemSettings))()
toml_load_mock.has_calls(call([empty_toml_file] + sorted(empty_toml_files_in_dir.glob("*.toml"))))
# NOTE: ugly hack because we can't compare BufferedReader objects for equality
for required_call in [
call(open(toml_file, "rb"))
for toml_file in [empty_toml_file] + sorted(empty_toml_files_in_dir.glob("*.toml"))
]:
assert str(required_call) in [str(mock_call) for mock_call in toml_load_mock.mock_calls] # nosec: B101
with patch("repod.config.settings.SETTINGS_LOCATION", {SettingsTypeEnum.SYSTEM: tmp_path / "foo.toml"}):
settings.SystemTomlConfig(Mock(spec=settings.SystemSettings))()
......@@ -303,7 +322,12 @@ def test_systemtomlconfig(
{SettingsTypeEnum.SYSTEM: override_dir},
):
settings.SystemTomlConfig(Mock(spec=settings.SystemSettings))()
toml_load_mock.has_calls(call([empty_toml_file] + sorted(empty_toml_files_in_dir.glob("*.toml"))))
# NOTE: ugly hack because we can't compare BufferedReader objects for equality
for required_call in [
call(open(toml_file, "rb"))
for toml_file in [empty_toml_file] + sorted(empty_toml_files_in_dir.glob("*.toml"))
]:
assert str(required_call) in [str(mock_call) for mock_call in toml_load_mock.mock_calls] # nosec: B101
@mark.parametrize(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment