|
| 1 | +# UtBot Executor |
| 2 | + |
| 3 | +Util for python code execution and state serialization. |
| 4 | + |
| 5 | +## Installation |
| 6 | + |
| 7 | +You can install module from [PyPI](https://pypi.org/project/utbot-executor/): |
| 8 | + |
| 9 | +```bash |
| 10 | +python -m pip install utbot-executor |
| 11 | +``` |
| 12 | + |
| 13 | +## Usage |
| 14 | + |
| 15 | +### From console with socket listener |
| 16 | + |
| 17 | +Run with your `<hostname>` and `<port>` for socket connection |
| 18 | +```bash |
| 19 | +$ python -m utbot_executor <hostname> <port> <logfile> [<loglevel DEBUG | INFO | ERROR>] <coverage_hostname> <coverage_port> |
| 20 | +``` |
| 21 | + |
| 22 | +### Request format |
| 23 | +```json |
| 24 | +{ |
| 25 | + "functionName": "f", |
| 26 | + "functionModule": "my_module.submod1", |
| 27 | + "imports": ["sys", "math", "json"], |
| 28 | + "syspaths": ["/home/user/my_project/"], |
| 29 | + "argumentsIds": ["1", "2"], |
| 30 | + "kwargumentsIds": ["4", "5"], |
| 31 | + "serializedMemory": "string", |
| 32 | + "filepath": ["/home/user/my_project/my_module/submod1.py"], |
| 33 | + "coverageId": "1" |
| 34 | +} |
| 35 | +``` |
| 36 | + |
| 37 | +* `functionName` - name of the tested function |
| 38 | +* `functionModule` - name of the module of the tested function |
| 39 | +* `imports` - all modules which need to run function with current arguments |
| 40 | +* `syspaths` - all syspaths which need to import modules (usually it is a project root) |
| 41 | +* `argumentsIds` - list of argument's ids |
| 42 | +* `kwargumentsIds` - list of keyword argument's ids |
| 43 | +* `serializedMemory` - serialized memory throw `deep_serialization` algorithm |
| 44 | +* `filepath` - path to the tested function's containing file |
| 45 | +* `coverageId` - special id witch will be used for sending information about covered lines |
| 46 | + |
| 47 | +### Response format: |
| 48 | + |
| 49 | +If execution is successful: |
| 50 | +```json |
| 51 | +{ |
| 52 | + "status": "success", |
| 53 | + "isException": false, |
| 54 | + "statements": [1, 2, 3], |
| 55 | + "missedStatements": [4, 5], |
| 56 | + "stateInit": "string", |
| 57 | + "stateBefore": "string", |
| 58 | + "stateAfter": "string", |
| 59 | + "diffIds": ["3", "4"], |
| 60 | + "argsIds": ["1", "2", "3"], |
| 61 | + "kwargs": ["4", "5", "6"], |
| 62 | + "resultId": "7" |
| 63 | +} |
| 64 | +``` |
| 65 | + |
| 66 | +* `status` - always "success" |
| 67 | +* `isException` - boolean value, if it is `true`, execution ended with an exception |
| 68 | +* `statements` - list of the numbers of covered rows |
| 69 | +* `missedStatements` - list of numbers of uncovered rows |
| 70 | +* `stateInit` - serialized states from request |
| 71 | +* `stateBefore` - serialized states of arguments before execution |
| 72 | +* `stateAfter` - serialized states of arguments after execution |
| 73 | +* `diffIds` - ids of the objects which have been changed |
| 74 | +* `argsIds` - ids of the function's arguments |
| 75 | +* `kwargsIds` - ids of the function's keyword arguments |
| 76 | +* `resultId` - id of the returned value |
| 77 | + |
| 78 | +or error format if there was exception in running algorith: |
| 79 | + |
| 80 | +```json |
| 81 | +{ |
| 82 | + "status": "fail", |
| 83 | + "exception": "stacktrace" |
| 84 | +} |
| 85 | +``` |
| 86 | +* `status` - always "fail" |
| 87 | +* `exception` - string representation of the exception stack trace |
| 88 | + |
| 89 | +### Submodule `deep_serialization` |
| 90 | + |
| 91 | +JSON serializer and deserializer for python objects |
| 92 | + |
| 93 | +#### States memory json-format |
| 94 | + |
| 95 | +```json |
| 96 | +{ |
| 97 | + "objects": { |
| 98 | + "id": { |
| 99 | + "id": "1", |
| 100 | + "strategy": "strategy name", |
| 101 | + "typeinfo": { |
| 102 | + "module": "builtins", |
| 103 | + "kind": "int" |
| 104 | + }, |
| 105 | + "comparable": true, |
| 106 | + |
| 107 | + // iff strategy is 'repr' |
| 108 | + "value": "1", |
| 109 | + |
| 110 | + // iff strategy is 'list' or 'dict' |
| 111 | + "items": ["3", "2"], |
| 112 | + |
| 113 | + // iff strategy = 'reduce' |
| 114 | + "constructor": "mymod.A.__new__", |
| 115 | + "args": ["mymod.A"], |
| 116 | + "state": {"a": "4", "b": "5"}, |
| 117 | + "listitems": ["7", "8"], |
| 118 | + "dictitems": {"ka": "10"} |
| 119 | + } |
| 120 | + } |
| 121 | +} |
| 122 | +``` |
| 123 | + |
| 124 | + |
| 125 | +## Source |
| 126 | + |
| 127 | +GitHub [repository](https://github.com/tamarinvs19/utbot_executor) |
0 commit comments