Debian Codegraph @

misc/tools/kemi/python_mock/README.md

raw
1 # Python Mocking Framework for testing #
2
3 Generate a mocking framework base on the output of app_python.api_list
4
5 ### Usage:
6 ```
7 /usr/sbin/kamctl rpc app_python.api_list > api.json
8 ./kemi_mock.py api.json > KSR.py
9 ```
10
11 *Note:* Python 3.2 doesn't support the Union type. To generate KSR.py without
12 the Union type add the --no-union flag
13
14 ```
15 ./kemi_mock.py api.json --no-union > KSR.py
16 ```
17
18 ### Usage with Documentation:
19 run the generate.py from the following project
20
21 https://github.com/braams/vscode-kamailio-hover
22
23 this creates a modules.json file in a tmp directory. This file can be used to generate the KSR.py file with documentation
24
25 pass the modules.json as a 2nd parameter to kemi_mock.py
26 ```
27 ./kemi_mock.py api.json modules.json > KSR.py
28 ```
29
30 ## Mocking
31 Return values can be injected through the dictionary \_mock\_data
32
33 ```python
34
35 #set return value for all calls to the function
36 _mock_data[module][function] = value
37
38 #set return value for specific parameters being passed
39 _mock_data[module][function][param_value] = value
40
41 #call the function myFunc when func is passed, return of myFunc will
42 #be the value module.function returns
43 _mock_data[module][function] = myFunc
44 ```
45
46 see test.py for example usage
47
48