robotframework-mock 0.1.0__tar.gz → 0.3.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.1.0/src/robotframework_mock.egg-info → robotframework_mock-0.3.0}/PKG-INFO +209 -179
- {robotframework_mock-0.1.0 → robotframework_mock-0.3.0}/README.md +32 -2
- {robotframework_mock-0.1.0 → robotframework_mock-0.3.0}/setup.cfg +31 -31
- robotframework_mock-0.3.0/src/MockLibrary/__init__.py +206 -0
- robotframework_mock-0.3.0/src/MockResource/__init__.py +113 -0
- {robotframework_mock-0.1.0 → robotframework_mock-0.3.0/src/robotframework_mock.egg-info}/PKG-INFO +209 -179
- {robotframework_mock-0.1.0 → robotframework_mock-0.3.0}/src/robotframework_mock.egg-info/SOURCES.txt +1 -0
- robotframework_mock-0.3.0/src/robotframework_mock.egg-info/top_level.txt +2 -0
- robotframework_mock-0.1.0/src/MockLibrary/__init__.py +0 -116
- robotframework_mock-0.1.0/src/robotframework_mock.egg-info/top_level.txt +0 -1
- {robotframework_mock-0.1.0 → robotframework_mock-0.3.0}/LICENSE +0 -0
- {robotframework_mock-0.1.0 → robotframework_mock-0.3.0}/MANIFEST.in +0 -0
- {robotframework_mock-0.1.0 → robotframework_mock-0.3.0}/pyproject.toml +0 -0
- {robotframework_mock-0.1.0 → robotframework_mock-0.3.0}/setup.py +0 -0
- {robotframework_mock-0.1.0 → robotframework_mock-0.3.0}/src/robotframework_mock.egg-info/dependency_links.txt +0 -0
- {robotframework_mock-0.1.0 → robotframework_mock-0.3.0}/src/robotframework_mock.egg-info/requires.txt +0 -0
{robotframework_mock-0.1.0/src/robotframework_mock.egg-info → robotframework_mock-0.3.0}/PKG-INFO
RENAMED
|
@@ -1,179 +1,209 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: robotframework-mock
|
|
3
|
-
Version: 0.
|
|
4
|
-
Summary: A Robot Framework library for mocking keywords in unit tests
|
|
5
|
-
Home-page: https://github.com/olesz/robotframework-mock
|
|
6
|
-
Author: Lajos Olah
|
|
7
|
-
Author-email: lajos.olah.jr@gmail.com
|
|
8
|
-
License: Apache-2.0
|
|
9
|
-
Classifier: Programming Language :: Python :: 3
|
|
10
|
-
Classifier: Operating System :: OS Independent
|
|
11
|
-
Classifier: Framework :: Robot Framework
|
|
12
|
-
Classifier: Framework :: Robot Framework :: Library
|
|
13
|
-
Requires-Python: >=3.7
|
|
14
|
-
Description-Content-Type: text/markdown
|
|
15
|
-
License-File: LICENSE
|
|
16
|
-
Requires-Dist: robotframework>=7.0
|
|
17
|
-
Dynamic: license-file
|
|
18
|
-
|
|
19
|
-
# robotframework-mock
|
|
20
|
-
|
|
21
|
-
A Robot Framework library for mocking keywords in unit tests.
|
|
22
|
-
|
|
23
|
-
## Installation
|
|
24
|
-
|
|
25
|
-
### From PyPI (once published)
|
|
26
|
-
|
|
27
|
-
```bash
|
|
28
|
-
pip install robotframework-mock
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
### From source
|
|
32
|
-
|
|
33
|
-
```bash
|
|
34
|
-
git clone https://github.com/yourusername/robotframework-mock.git
|
|
35
|
-
cd robotframework-mock
|
|
36
|
-
pip install .
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
### For development
|
|
40
|
-
|
|
41
|
-
```bash
|
|
42
|
-
pip install -e .
|
|
43
|
-
pip install -r requirements-dev.txt
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
## Features
|
|
47
|
-
|
|
48
|
-
- Mock keywords from any Robot Framework library
|
|
49
|
-
- Mock Robot Framework
|
|
50
|
-
-
|
|
51
|
-
-
|
|
52
|
-
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
Library
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
Test
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
Test
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
MockDB.
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
Test
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
Library
|
|
110
|
-
Library
|
|
111
|
-
Library MockLibrary
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
Test
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
**
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: robotframework-mock
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: A Robot Framework library for mocking keywords in unit tests
|
|
5
|
+
Home-page: https://github.com/olesz/robotframework-mock
|
|
6
|
+
Author: Lajos Olah
|
|
7
|
+
Author-email: lajos.olah.jr@gmail.com
|
|
8
|
+
License: Apache-2.0
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Classifier: Framework :: Robot Framework
|
|
12
|
+
Classifier: Framework :: Robot Framework :: Library
|
|
13
|
+
Requires-Python: >=3.7
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
License-File: LICENSE
|
|
16
|
+
Requires-Dist: robotframework>=7.0
|
|
17
|
+
Dynamic: license-file
|
|
18
|
+
|
|
19
|
+
# robotframework-mock
|
|
20
|
+
|
|
21
|
+
A Robot Framework library for mocking keywords in unit tests.
|
|
22
|
+
|
|
23
|
+
## Installation
|
|
24
|
+
|
|
25
|
+
### From PyPI (once published)
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
pip install robotframework-mock
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### From source
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
git clone https://github.com/yourusername/robotframework-mock.git
|
|
35
|
+
cd robotframework-mock
|
|
36
|
+
pip install .
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### For development
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
pip install -e .
|
|
43
|
+
pip install -r requirements-dev.txt
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Features
|
|
47
|
+
|
|
48
|
+
- Mock keywords from any Robot Framework library
|
|
49
|
+
- Mock keywords from Robot Framework resource files
|
|
50
|
+
- Mock Robot Framework's BuiltIn keywords
|
|
51
|
+
- Support for keywords with custom names via @keyword decorator
|
|
52
|
+
- Verify keyword calls and call counts
|
|
53
|
+
- Simple API with three main keywords
|
|
54
|
+
|
|
55
|
+
## Usage
|
|
56
|
+
|
|
57
|
+
### Mock Library Keywords
|
|
58
|
+
|
|
59
|
+
Import the library you want to mock, then create a MockLibrary instance for it:
|
|
60
|
+
|
|
61
|
+
```robot
|
|
62
|
+
*** Settings ***
|
|
63
|
+
Library DatabaseLibrary
|
|
64
|
+
Library MockLibrary DatabaseLibrary WITH NAME MockDB
|
|
65
|
+
|
|
66
|
+
*** Test Cases ***
|
|
67
|
+
Test With Mocked Keyword
|
|
68
|
+
MockDB.Mock Keyword query return_value=test_data
|
|
69
|
+
${result}= DatabaseLibrary.Query SELECT * FROM users
|
|
70
|
+
Should Be Equal ${result} test_data
|
|
71
|
+
MockDB.Reset Mocks
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Verify Calls
|
|
75
|
+
|
|
76
|
+
Verify that a keyword was called and optionally check the call count:
|
|
77
|
+
|
|
78
|
+
```robot
|
|
79
|
+
*** Test Cases ***
|
|
80
|
+
Test Keyword Was Called
|
|
81
|
+
MockDB.Mock Keyword execute_sql return_value=${None}
|
|
82
|
+
Process User Registration
|
|
83
|
+
MockDB.Verify Keyword Called execute_sql times=1
|
|
84
|
+
MockDB.Reset Mocks
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Mock BuiltIn Keywords
|
|
88
|
+
|
|
89
|
+
Mock Robot Framework's built-in keywords using the same MockLibrary with "BuiltIn" as the library name:
|
|
90
|
+
|
|
91
|
+
```robot
|
|
92
|
+
*** Settings ***
|
|
93
|
+
Library MockLibrary BuiltIn WITH NAME MockBin
|
|
94
|
+
|
|
95
|
+
*** Test Cases ***
|
|
96
|
+
Test BuiltIn Mock
|
|
97
|
+
MockBin.Mock Keyword Convert To Binary return_value=test_data
|
|
98
|
+
${result}= Convert To Binary aaa
|
|
99
|
+
Should Be Equal ${result} test_data
|
|
100
|
+
MockBin.Reset Mocks
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Mock Multiple Libraries
|
|
104
|
+
|
|
105
|
+
You can mock multiple libraries in the same test:
|
|
106
|
+
|
|
107
|
+
```robot
|
|
108
|
+
*** Settings ***
|
|
109
|
+
Library DatabaseLibrary
|
|
110
|
+
Library RequestsLibrary
|
|
111
|
+
Library MockLibrary DatabaseLibrary WITH NAME MockDB
|
|
112
|
+
Library MockLibrary RequestsLibrary WITH NAME MockReq
|
|
113
|
+
|
|
114
|
+
*** Test Cases ***
|
|
115
|
+
Test Multiple Mocks
|
|
116
|
+
MockDB.Mock Keyword query return_value=user_data
|
|
117
|
+
MockReq.Mock Keyword get return_value=api_response
|
|
118
|
+
# Your test code here
|
|
119
|
+
MockDB.Reset Mocks
|
|
120
|
+
MockReq.Reset Mocks
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### Mock Resource Keywords
|
|
124
|
+
|
|
125
|
+
Mock keywords from Robot Framework resource files:
|
|
126
|
+
|
|
127
|
+
```robot
|
|
128
|
+
*** Settings ***
|
|
129
|
+
Resource my_resource.robot
|
|
130
|
+
Library MockResource my_resource.robot WITH NAME MockRes
|
|
131
|
+
|
|
132
|
+
*** Test Cases ***
|
|
133
|
+
Test Resource Keyword Mock
|
|
134
|
+
MockRes.Mock Keyword My Custom Keyword return_value=mocked_value
|
|
135
|
+
${result}= My Custom Keyword
|
|
136
|
+
Should Be Equal ${result} mocked_value
|
|
137
|
+
MockRes.Reset Mocks
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## Keywords
|
|
141
|
+
|
|
142
|
+
### Mock Keyword
|
|
143
|
+
|
|
144
|
+
Mock a keyword with a return value or side effect.
|
|
145
|
+
|
|
146
|
+
**Arguments:**
|
|
147
|
+
- `keyword_name` - Name of the keyword to mock
|
|
148
|
+
- `return_value` - Value to return when called (optional)
|
|
149
|
+
- `side_effect` - Callable to execute instead (optional)
|
|
150
|
+
|
|
151
|
+
**Example:**
|
|
152
|
+
```robot
|
|
153
|
+
MockDB.Mock Keyword query return_value=test_data
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### Reset Mocks
|
|
157
|
+
|
|
158
|
+
Restore all mocked keywords to their original implementations.
|
|
159
|
+
|
|
160
|
+
**Example:**
|
|
161
|
+
```robot
|
|
162
|
+
MockDB.Reset Mocks
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### Verify Keyword Called
|
|
166
|
+
|
|
167
|
+
Verify a keyword was called, optionally checking call count.
|
|
168
|
+
|
|
169
|
+
**Arguments:**
|
|
170
|
+
- `keyword_name` - Name of the keyword to verify
|
|
171
|
+
- `times` - Expected number of calls (optional)
|
|
172
|
+
|
|
173
|
+
**Example:**
|
|
174
|
+
```robot
|
|
175
|
+
MockDB.Verify Keyword Called execute_sql times=1
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
## How It Works
|
|
179
|
+
|
|
180
|
+
### MockLibrary
|
|
181
|
+
|
|
182
|
+
MockLibrary dynamically replaces keyword implementations:
|
|
183
|
+
1. Wraps the target library instance
|
|
184
|
+
2. Resolves keyword names to function names (handles @keyword decorator)
|
|
185
|
+
3. Stores original methods before mocking
|
|
186
|
+
4. Replaces methods with mock implementations using Python's unittest.mock.Mock
|
|
187
|
+
5. Returns mocked values or executes side effects
|
|
188
|
+
6. Tracks call counts for verification
|
|
189
|
+
7. Raises AttributeError if attempting to mock a non-existent keyword
|
|
190
|
+
|
|
191
|
+
### MockResource
|
|
192
|
+
|
|
193
|
+
MockResource patches Robot Framework's keyword execution:
|
|
194
|
+
1. Patches the Namespace.get_runner method
|
|
195
|
+
2. Intercepts keyword execution for the specified resource file
|
|
196
|
+
3. Replaces keyword body with Return statement containing mocked value
|
|
197
|
+
4. Tracks call counts for verification
|
|
198
|
+
5. Restores original keyword body on reset
|
|
199
|
+
|
|
200
|
+
## Notes
|
|
201
|
+
|
|
202
|
+
- Both libraries use `ROBOT_LIBRARY_SCOPE = 'GLOBAL'` to maintain state across test cases
|
|
203
|
+
- Built on Python's unittest.mock.Mock for robust mocking capabilities
|
|
204
|
+
- MockLibrary supports any Robot Framework library, including BuiltIn
|
|
205
|
+
- MockResource works with resource files by patching the keyword execution pipeline
|
|
206
|
+
|
|
207
|
+
## License
|
|
208
|
+
|
|
209
|
+
See LICENSE file for details.
|
|
@@ -28,6 +28,7 @@ pip install -r requirements-dev.txt
|
|
|
28
28
|
## Features
|
|
29
29
|
|
|
30
30
|
- Mock keywords from any Robot Framework library
|
|
31
|
+
- Mock keywords from Robot Framework resource files
|
|
31
32
|
- Mock Robot Framework's BuiltIn keywords
|
|
32
33
|
- Support for keywords with custom names via @keyword decorator
|
|
33
34
|
- Verify keyword calls and call counts
|
|
@@ -101,6 +102,23 @@ Test Multiple Mocks
|
|
|
101
102
|
MockReq.Reset Mocks
|
|
102
103
|
```
|
|
103
104
|
|
|
105
|
+
### Mock Resource Keywords
|
|
106
|
+
|
|
107
|
+
Mock keywords from Robot Framework resource files:
|
|
108
|
+
|
|
109
|
+
```robot
|
|
110
|
+
*** Settings ***
|
|
111
|
+
Resource my_resource.robot
|
|
112
|
+
Library MockResource my_resource.robot WITH NAME MockRes
|
|
113
|
+
|
|
114
|
+
*** Test Cases ***
|
|
115
|
+
Test Resource Keyword Mock
|
|
116
|
+
MockRes.Mock Keyword My Custom Keyword return_value=mocked_value
|
|
117
|
+
${result}= My Custom Keyword
|
|
118
|
+
Should Be Equal ${result} mocked_value
|
|
119
|
+
MockRes.Reset Mocks
|
|
120
|
+
```
|
|
121
|
+
|
|
104
122
|
## Keywords
|
|
105
123
|
|
|
106
124
|
### Mock Keyword
|
|
@@ -141,6 +159,8 @@ MockDB.Verify Keyword Called execute_sql times=1
|
|
|
141
159
|
|
|
142
160
|
## How It Works
|
|
143
161
|
|
|
162
|
+
### MockLibrary
|
|
163
|
+
|
|
144
164
|
MockLibrary dynamically replaces keyword implementations:
|
|
145
165
|
1. Wraps the target library instance
|
|
146
166
|
2. Resolves keyword names to function names (handles @keyword decorator)
|
|
@@ -150,11 +170,21 @@ MockLibrary dynamically replaces keyword implementations:
|
|
|
150
170
|
6. Tracks call counts for verification
|
|
151
171
|
7. Raises AttributeError if attempting to mock a non-existent keyword
|
|
152
172
|
|
|
173
|
+
### MockResource
|
|
174
|
+
|
|
175
|
+
MockResource patches Robot Framework's keyword execution:
|
|
176
|
+
1. Patches the Namespace.get_runner method
|
|
177
|
+
2. Intercepts keyword execution for the specified resource file
|
|
178
|
+
3. Replaces keyword body with Return statement containing mocked value
|
|
179
|
+
4. Tracks call counts for verification
|
|
180
|
+
5. Restores original keyword body on reset
|
|
181
|
+
|
|
153
182
|
## Notes
|
|
154
183
|
|
|
155
|
-
-
|
|
184
|
+
- Both libraries use `ROBOT_LIBRARY_SCOPE = 'GLOBAL'` to maintain state across test cases
|
|
156
185
|
- Built on Python's unittest.mock.Mock for robust mocking capabilities
|
|
157
|
-
-
|
|
186
|
+
- MockLibrary supports any Robot Framework library, including BuiltIn
|
|
187
|
+
- MockResource works with resource files by patching the keyword execution pipeline
|
|
158
188
|
|
|
159
189
|
## License
|
|
160
190
|
|
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
[metadata]
|
|
2
|
-
name = robotframework-mock
|
|
3
|
-
version = 0.
|
|
4
|
-
author = Lajos Olah
|
|
5
|
-
author_email = lajos.olah.jr@gmail.com
|
|
6
|
-
description = A Robot Framework library for mocking keywords in unit tests
|
|
7
|
-
long_description = file: README.md
|
|
8
|
-
long_description_content_type = text/markdown
|
|
9
|
-
url = https://github.com/olesz/robotframework-mock
|
|
10
|
-
license = Apache-2.0
|
|
11
|
-
classifiers =
|
|
12
|
-
Programming Language :: Python :: 3
|
|
13
|
-
Operating System :: OS Independent
|
|
14
|
-
Framework :: Robot Framework
|
|
15
|
-
Framework :: Robot Framework :: Library
|
|
16
|
-
|
|
17
|
-
[options]
|
|
18
|
-
package_dir =
|
|
19
|
-
= src
|
|
20
|
-
packages = find:
|
|
21
|
-
python_requires = >=3.7
|
|
22
|
-
install_requires =
|
|
23
|
-
robotframework>=7.0
|
|
24
|
-
|
|
25
|
-
[options.packages.find]
|
|
26
|
-
where = src
|
|
27
|
-
|
|
28
|
-
[egg_info]
|
|
29
|
-
tag_build =
|
|
30
|
-
tag_date = 0
|
|
31
|
-
|
|
1
|
+
[metadata]
|
|
2
|
+
name = robotframework-mock
|
|
3
|
+
version = 0.3.0
|
|
4
|
+
author = Lajos Olah
|
|
5
|
+
author_email = lajos.olah.jr@gmail.com
|
|
6
|
+
description = A Robot Framework library for mocking keywords in unit tests
|
|
7
|
+
long_description = file: README.md
|
|
8
|
+
long_description_content_type = text/markdown
|
|
9
|
+
url = https://github.com/olesz/robotframework-mock
|
|
10
|
+
license = Apache-2.0
|
|
11
|
+
classifiers =
|
|
12
|
+
Programming Language :: Python :: 3
|
|
13
|
+
Operating System :: OS Independent
|
|
14
|
+
Framework :: Robot Framework
|
|
15
|
+
Framework :: Robot Framework :: Library
|
|
16
|
+
|
|
17
|
+
[options]
|
|
18
|
+
package_dir =
|
|
19
|
+
= src
|
|
20
|
+
packages = find:
|
|
21
|
+
python_requires = >=3.7
|
|
22
|
+
install_requires =
|
|
23
|
+
robotframework>=7.0
|
|
24
|
+
|
|
25
|
+
[options.packages.find]
|
|
26
|
+
where = src
|
|
27
|
+
|
|
28
|
+
[egg_info]
|
|
29
|
+
tag_build =
|
|
30
|
+
tag_date = 0
|
|
31
|
+
|