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.
@@ -1,179 +1,209 @@
1
- Metadata-Version: 2.4
2
- Name: robotframework-mock
3
- Version: 0.1.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's BuiltIn keywords
50
- - Support for keywords with custom names via @keyword decorator
51
- - Verify keyword calls and call counts
52
- - Simple API with three main keywords
53
-
54
- ## Usage
55
-
56
- ### Mock Library Keywords
57
-
58
- Import the library you want to mock, then create a MockLibrary instance for it:
59
-
60
- ```robot
61
- *** Settings ***
62
- Library DatabaseLibrary
63
- Library MockLibrary DatabaseLibrary WITH NAME MockDB
64
-
65
- *** Test Cases ***
66
- Test With Mocked Keyword
67
- MockDB.Mock Keyword query return_value=test_data
68
- ${result}= DatabaseLibrary.Query SELECT * FROM users
69
- Should Be Equal ${result} test_data
70
- MockDB.Reset Mocks
71
- ```
72
-
73
- ### Verify Calls
74
-
75
- Verify that a keyword was called and optionally check the call count:
76
-
77
- ```robot
78
- *** Test Cases ***
79
- Test Keyword Was Called
80
- MockDB.Mock Keyword execute_sql return_value=${None}
81
- Process User Registration
82
- MockDB.Verify Keyword Called execute_sql times=1
83
- MockDB.Reset Mocks
84
- ```
85
-
86
- ### Mock BuiltIn Keywords
87
-
88
- Mock Robot Framework's built-in keywords using the same MockLibrary with "BuiltIn" as the library name:
89
-
90
- ```robot
91
- *** Settings ***
92
- Library MockLibrary BuiltIn WITH NAME MockBin
93
-
94
- *** Test Cases ***
95
- Test BuiltIn Mock
96
- MockBin.Mock Keyword Convert To Binary return_value=test_data
97
- ${result}= Convert To Binary aaa
98
- Should Be Equal ${result} test_data
99
- MockBin.Reset Mocks
100
- ```
101
-
102
- ### Mock Multiple Libraries
103
-
104
- You can mock multiple libraries in the same test:
105
-
106
- ```robot
107
- *** Settings ***
108
- Library DatabaseLibrary
109
- Library RequestsLibrary
110
- Library MockLibrary DatabaseLibrary WITH NAME MockDB
111
- Library MockLibrary RequestsLibrary WITH NAME MockReq
112
-
113
- *** Test Cases ***
114
- Test Multiple Mocks
115
- MockDB.Mock Keyword query return_value=user_data
116
- MockReq.Mock Keyword get return_value=api_response
117
- # Your test code here
118
- MockDB.Reset Mocks
119
- MockReq.Reset Mocks
120
- ```
121
-
122
- ## Keywords
123
-
124
- ### Mock Keyword
125
-
126
- Mock a keyword with a return value or side effect.
127
-
128
- **Arguments:**
129
- - `keyword_name` - Name of the keyword to mock
130
- - `return_value` - Value to return when called (optional)
131
- - `side_effect` - Callable to execute instead (optional)
132
-
133
- **Example:**
134
- ```robot
135
- MockDB.Mock Keyword query return_value=test_data
136
- ```
137
-
138
- ### Reset Mocks
139
-
140
- Restore all mocked keywords to their original implementations.
141
-
142
- **Example:**
143
- ```robot
144
- MockDB.Reset Mocks
145
- ```
146
-
147
- ### Verify Keyword Called
148
-
149
- Verify a keyword was called, optionally checking call count.
150
-
151
- **Arguments:**
152
- - `keyword_name` - Name of the keyword to verify
153
- - `times` - Expected number of calls (optional)
154
-
155
- **Example:**
156
- ```robot
157
- MockDB.Verify Keyword Called execute_sql times=1
158
- ```
159
-
160
- ## How It Works
161
-
162
- MockLibrary dynamically replaces keyword implementations:
163
- 1. Wraps the target library instance
164
- 2. Resolves keyword names to function names (handles @keyword decorator)
165
- 3. Stores original methods before mocking
166
- 4. Replaces methods with mock implementations using Python's unittest.mock.Mock
167
- 5. Returns mocked values or executes side effects
168
- 6. Tracks call counts for verification
169
- 7. Raises AttributeError if attempting to mock a non-existent keyword
170
-
171
- ## Notes
172
-
173
- - The library uses `ROBOT_LIBRARY_SCOPE = 'GLOBAL'` to maintain state across test cases
174
- - Built on Python's unittest.mock.Mock for robust mocking capabilities
175
- - Supports any Robot Framework library, including BuiltIn
176
-
177
- ## License
178
-
179
- See LICENSE file for details.
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
- - The library uses `ROBOT_LIBRARY_SCOPE = 'GLOBAL'` to maintain state across test cases
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
- - Supports any Robot Framework library, including BuiltIn
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.1.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
+