Skip to content

Commit ee1ce9b

Browse files
Scrub test_utils.py
1 parent 3c37358 commit ee1ce9b

File tree

2 files changed

+155
-261
lines changed

2 files changed

+155
-261
lines changed

tests/python/test_helpers.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@
1717
# PATCH HELPERS
1818
# ------------------------------
1919

20+
def suppress_module_functions(monkeypatch, module, names: list[str]) -> None:
21+
"""Suppress noisy functions on a module by replacing them with a no-op."""
22+
23+
def _noop(*args, **kwargs):
24+
return None
25+
26+
for name in names:
27+
monkeypatch.setattr(module, name, _noop)
28+
2029
def patch_open_for_text_read(
2130
monkeypatch,
2231
*,
@@ -89,6 +98,35 @@ def patch_os_paths(
8998
monkeypatch.setattr('os.path.basename', MagicMock(return_value=basename))
9099

91100

101+
def patch_create_bicep_deployment_group_dependencies(
102+
monkeypatch,
103+
*,
104+
az_module,
105+
run_success: bool = True,
106+
cwd: str = '/test/dir',
107+
exists: bool | Callable[[str], bool] = True,
108+
basename: str | Callable[[str], str] = 'test-dir'
109+
):
110+
"""Patch common dependencies for utils.create_bicep_deployment_group tests.
111+
112+
Returns:
113+
tuple: (mock_create_resource_group, mock_az_run, mock_open)
114+
"""
115+
mock_create_rg = MagicMock()
116+
monkeypatch.setattr(az_module, 'create_resource_group', mock_create_rg)
117+
118+
mock_run = MagicMock(return_value=MagicMock(success=run_success))
119+
monkeypatch.setattr(az_module, 'run', mock_run)
120+
121+
open_mock = mock_open()
122+
monkeypatch.setattr(builtins, 'open', open_mock)
123+
monkeypatch.setattr(builtins, 'print', MagicMock())
124+
125+
patch_os_paths(monkeypatch, cwd=cwd, exists=exists, basename=basename)
126+
127+
return mock_create_rg, mock_run, open_mock
128+
129+
92130
# ------------------------------
93131
# MOCK FACTORIES
94132
# ------------------------------

0 commit comments

Comments
 (0)