robotframework-mock 0.6.0__tar.gz → 0.7.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {robotframework_mock-0.6.0/src/robotframework_mock.egg-info → robotframework_mock-0.7.0}/PKG-INFO +24 -1
- {robotframework_mock-0.6.0 → robotframework_mock-0.7.0}/README.md +23 -0
- {robotframework_mock-0.6.0 → robotframework_mock-0.7.0}/setup.cfg +1 -1
- {robotframework_mock-0.6.0 → robotframework_mock-0.7.0}/src/MockResource/__init__.py +37 -5
- {robotframework_mock-0.6.0 → robotframework_mock-0.7.0/src/robotframework_mock.egg-info}/PKG-INFO +24 -1
- {robotframework_mock-0.6.0 → robotframework_mock-0.7.0}/LICENSE +0 -0
- {robotframework_mock-0.6.0 → robotframework_mock-0.7.0}/MANIFEST.in +0 -0
- {robotframework_mock-0.6.0 → robotframework_mock-0.7.0}/pyproject.toml +0 -0
- {robotframework_mock-0.6.0 → robotframework_mock-0.7.0}/setup.py +0 -0
- {robotframework_mock-0.6.0 → robotframework_mock-0.7.0}/src/MockCoverage/__init__.py +0 -0
- {robotframework_mock-0.6.0 → robotframework_mock-0.7.0}/src/MockLibrary/__init__.py +0 -0
- {robotframework_mock-0.6.0 → robotframework_mock-0.7.0}/src/_mock_core/__init__.py +0 -0
- {robotframework_mock-0.6.0 → robotframework_mock-0.7.0}/src/robotframework_mock.egg-info/SOURCES.txt +0 -0
- {robotframework_mock-0.6.0 → robotframework_mock-0.7.0}/src/robotframework_mock.egg-info/dependency_links.txt +0 -0
- {robotframework_mock-0.6.0 → robotframework_mock-0.7.0}/src/robotframework_mock.egg-info/requires.txt +0 -0
- {robotframework_mock-0.6.0 → robotframework_mock-0.7.0}/src/robotframework_mock.egg-info/top_level.txt +0 -0
{robotframework_mock-0.6.0/src/robotframework_mock.egg-info → robotframework_mock-0.7.0}/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: robotframework-mock
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.7.0
|
|
4
4
|
Summary: A Robot Framework library for mocking keywords in unit tests
|
|
5
5
|
Home-page: https://github.com/olesz/robotframework-mock
|
|
6
6
|
Author: Lajos Olah
|
|
@@ -328,6 +328,29 @@ ${rows}= Evaluate [['Europe/Budapest']]
|
|
|
328
328
|
MockRes.Mock Keyword Run Query return_value=${rows}
|
|
329
329
|
```
|
|
330
330
|
|
|
331
|
+
### Mocked keyword setup and teardown
|
|
332
|
+
|
|
333
|
+
`MockResource` replaces only a keyword's **body**. Its `[Setup]` and `[Teardown]`
|
|
334
|
+
still run, which keeps them observable — a test can assert that a teardown
|
|
335
|
+
released a lock, for instance.
|
|
336
|
+
|
|
337
|
+
That is a problem when the teardown cleans up state the replaced body would have
|
|
338
|
+
created, because it then fails on the mocked call. Suppress it per mock:
|
|
339
|
+
|
|
340
|
+
```robot
|
|
341
|
+
# Init Client acquires a lock in its body and releases it in its teardown.
|
|
342
|
+
# Without the body there is no lock to release, so skip the teardown.
|
|
343
|
+
MockRes.Mock Keyword Init Client return_value=alias skip_teardown=${True}
|
|
344
|
+
MockRes.Mock Keyword Init Client return_value=alias skip_setup=${True}
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
Both default to `False`, so existing tests are unaffected. `Reset Mocks`
|
|
348
|
+
restores a suppressed setup or teardown along with the body.
|
|
349
|
+
|
|
350
|
+
Prefer the default when the setup or teardown is part of the contract you are
|
|
351
|
+
testing, and skip it when it is an implementation detail of a keyword the test
|
|
352
|
+
is only standing in for.
|
|
353
|
+
|
|
331
354
|
### Reset Mocks
|
|
332
355
|
|
|
333
356
|
Restore all mocked keywords to their original implementations.
|
|
@@ -304,6 +304,29 @@ ${rows}= Evaluate [['Europe/Budapest']]
|
|
|
304
304
|
MockRes.Mock Keyword Run Query return_value=${rows}
|
|
305
305
|
```
|
|
306
306
|
|
|
307
|
+
### Mocked keyword setup and teardown
|
|
308
|
+
|
|
309
|
+
`MockResource` replaces only a keyword's **body**. Its `[Setup]` and `[Teardown]`
|
|
310
|
+
still run, which keeps them observable — a test can assert that a teardown
|
|
311
|
+
released a lock, for instance.
|
|
312
|
+
|
|
313
|
+
That is a problem when the teardown cleans up state the replaced body would have
|
|
314
|
+
created, because it then fails on the mocked call. Suppress it per mock:
|
|
315
|
+
|
|
316
|
+
```robot
|
|
317
|
+
# Init Client acquires a lock in its body and releases it in its teardown.
|
|
318
|
+
# Without the body there is no lock to release, so skip the teardown.
|
|
319
|
+
MockRes.Mock Keyword Init Client return_value=alias skip_teardown=${True}
|
|
320
|
+
MockRes.Mock Keyword Init Client return_value=alias skip_setup=${True}
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
Both default to `False`, so existing tests are unaffected. `Reset Mocks`
|
|
324
|
+
restores a suppressed setup or teardown along with the body.
|
|
325
|
+
|
|
326
|
+
Prefer the default when the setup or teardown is part of the contract you are
|
|
327
|
+
testing, and skip it when it is an implementation detail of a keyword the test
|
|
328
|
+
is only standing in for.
|
|
329
|
+
|
|
307
330
|
### Reset Mocks
|
|
308
331
|
|
|
309
332
|
Restore all mocked keywords to their original implementations.
|
|
@@ -74,6 +74,8 @@ class MockResource(CallInspectionMixin):
|
|
|
74
74
|
self._source = source
|
|
75
75
|
self._original_get_runner = Namespace.get_runner
|
|
76
76
|
self._original_items = {}
|
|
77
|
+
self._original_setups = {}
|
|
78
|
+
self._original_teardowns = {}
|
|
77
79
|
self._mocks = {}
|
|
78
80
|
self._install_patch()
|
|
79
81
|
|
|
@@ -112,22 +114,37 @@ class MockResource(CallInspectionMixin):
|
|
|
112
114
|
@keyword
|
|
113
115
|
def mock_keyword(
|
|
114
116
|
self, keyword_name: str,
|
|
115
|
-
return_value: Any = None, side_effect: Callable = None
|
|
117
|
+
return_value: Any = None, side_effect: Callable = None,
|
|
118
|
+
skip_setup: bool = False, skip_teardown: bool = False
|
|
116
119
|
):
|
|
117
120
|
"""Mock a keyword from the resource file.
|
|
118
|
-
|
|
121
|
+
|
|
122
|
+
Only the keyword's body is replaced. Its ``[Setup]`` and ``[Teardown]``
|
|
123
|
+
still run by default, which keeps them observable - a test can assert
|
|
124
|
+
that a teardown released a lock, for example. Suppress them when the
|
|
125
|
+
mocked keyword's own setup or teardown is an implementation detail the
|
|
126
|
+
test should not depend on, typically because it cleans up state that the
|
|
127
|
+
replaced body would have created and therefore fails.
|
|
128
|
+
|
|
119
129
|
Args:
|
|
120
130
|
keyword_name: Name of the keyword to mock
|
|
121
|
-
return_value: Value to return when the keyword is called
|
|
131
|
+
return_value: Value to return when the keyword is called. May be any
|
|
132
|
+
Python object.
|
|
122
133
|
side_effect: Callable to execute instead of returning a value.
|
|
123
134
|
Receives the call's resolved arguments, the same way a
|
|
124
135
|
``MockLibrary`` side effect does.
|
|
136
|
+
skip_setup: Do not run the keyword's ``[Setup]`` while mocked.
|
|
137
|
+
skip_teardown: Do not run the keyword's ``[Teardown]`` while mocked.
|
|
125
138
|
|
|
126
139
|
Returns:
|
|
127
140
|
The :class:`unittest.mock.Mock` backing the keyword.
|
|
128
141
|
|
|
142
|
+
Raises:
|
|
143
|
+
AttributeError: If the keyword is not found in the resource file.
|
|
144
|
+
|
|
129
145
|
Example:
|
|
130
146
|
| MockRes.Mock Keyword | My Keyword | return_value=test_data |
|
|
147
|
+
| MockRes.Mock Keyword | Init Client | skip_teardown=${True} |
|
|
131
148
|
"""
|
|
132
149
|
keyword_runner = BuiltIn()._namespace.get_runner(keyword_name, True) # pylint: disable=protected-access
|
|
133
150
|
resource_file = getattr(keyword_runner.keyword, "source", None)
|
|
@@ -136,6 +153,12 @@ class MockResource(CallInspectionMixin):
|
|
|
136
153
|
raise AttributeError("fKeyword '{keyword_name}' not found in {self._source}")
|
|
137
154
|
|
|
138
155
|
self._original_items[keyword_name] = keyword_runner.keyword.body._items # pylint: disable=protected-access
|
|
156
|
+
if skip_setup:
|
|
157
|
+
self._original_setups[keyword_name] = keyword_runner.keyword.setup
|
|
158
|
+
keyword_runner.keyword.setup = None
|
|
159
|
+
if skip_teardown:
|
|
160
|
+
self._original_teardowns[keyword_name] = keyword_runner.keyword.teardown
|
|
161
|
+
keyword_runner.keyword.teardown = None
|
|
139
162
|
mock = Mock(return_value=return_value, side_effect=side_effect)
|
|
140
163
|
self._mocks[keyword_name] = mock
|
|
141
164
|
return mock
|
|
@@ -144,8 +167,9 @@ class MockResource(CallInspectionMixin):
|
|
|
144
167
|
def reset_mocks(self):
|
|
145
168
|
"""Reset all mocks to their original implementations.
|
|
146
169
|
|
|
147
|
-
Restores all mocked keywords to their original behavior
|
|
148
|
-
|
|
170
|
+
Restores all mocked keywords to their original behavior, including any
|
|
171
|
+
``[Setup]`` or ``[Teardown]`` that was suppressed while mocked.
|
|
172
|
+
|
|
149
173
|
Example:
|
|
150
174
|
| MockRes.Reset Mocks |
|
|
151
175
|
"""
|
|
@@ -153,7 +177,15 @@ class MockResource(CallInspectionMixin):
|
|
|
153
177
|
for keyword_name, items in self._original_items.items():
|
|
154
178
|
keyword_runner = BuiltIn()._namespace.get_runner(keyword_name, True) # pylint: disable=protected-access
|
|
155
179
|
keyword_runner.keyword.body._items = items # pylint: disable=protected-access
|
|
180
|
+
for keyword_name, setup in self._original_setups.items():
|
|
181
|
+
keyword_runner = BuiltIn()._namespace.get_runner(keyword_name, True) # pylint: disable=protected-access
|
|
182
|
+
keyword_runner.keyword.setup = setup
|
|
183
|
+
for keyword_name, teardown in self._original_teardowns.items():
|
|
184
|
+
keyword_runner = BuiltIn()._namespace.get_runner(keyword_name, True) # pylint: disable=protected-access
|
|
185
|
+
keyword_runner.keyword.teardown = teardown
|
|
156
186
|
self._original_items.clear()
|
|
187
|
+
self._original_setups.clear()
|
|
188
|
+
self._original_teardowns.clear()
|
|
157
189
|
|
|
158
190
|
@keyword
|
|
159
191
|
def verify_keyword_called(self, keyword_name: str, times: int = None):
|
{robotframework_mock-0.6.0 → robotframework_mock-0.7.0/src/robotframework_mock.egg-info}/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: robotframework-mock
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.7.0
|
|
4
4
|
Summary: A Robot Framework library for mocking keywords in unit tests
|
|
5
5
|
Home-page: https://github.com/olesz/robotframework-mock
|
|
6
6
|
Author: Lajos Olah
|
|
@@ -328,6 +328,29 @@ ${rows}= Evaluate [['Europe/Budapest']]
|
|
|
328
328
|
MockRes.Mock Keyword Run Query return_value=${rows}
|
|
329
329
|
```
|
|
330
330
|
|
|
331
|
+
### Mocked keyword setup and teardown
|
|
332
|
+
|
|
333
|
+
`MockResource` replaces only a keyword's **body**. Its `[Setup]` and `[Teardown]`
|
|
334
|
+
still run, which keeps them observable — a test can assert that a teardown
|
|
335
|
+
released a lock, for instance.
|
|
336
|
+
|
|
337
|
+
That is a problem when the teardown cleans up state the replaced body would have
|
|
338
|
+
created, because it then fails on the mocked call. Suppress it per mock:
|
|
339
|
+
|
|
340
|
+
```robot
|
|
341
|
+
# Init Client acquires a lock in its body and releases it in its teardown.
|
|
342
|
+
# Without the body there is no lock to release, so skip the teardown.
|
|
343
|
+
MockRes.Mock Keyword Init Client return_value=alias skip_teardown=${True}
|
|
344
|
+
MockRes.Mock Keyword Init Client return_value=alias skip_setup=${True}
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
Both default to `False`, so existing tests are unaffected. `Reset Mocks`
|
|
348
|
+
restores a suppressed setup or teardown along with the body.
|
|
349
|
+
|
|
350
|
+
Prefer the default when the setup or teardown is part of the contract you are
|
|
351
|
+
testing, and skip it when it is an implementation detail of a keyword the test
|
|
352
|
+
is only standing in for.
|
|
353
|
+
|
|
331
354
|
### Reset Mocks
|
|
332
355
|
|
|
333
356
|
Restore all mocked keywords to their original implementations.
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{robotframework_mock-0.6.0 → robotframework_mock-0.7.0}/src/robotframework_mock.egg-info/SOURCES.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|