@@ -16,6 +16,11 @@ import org.utbot.fuzzing.Control
16
16
import org.utbot.fuzzing.fuzz
17
17
import org.utbot.python.code.MemoryDump
18
18
import org.utbot.python.code.toPythonTree
19
+ import org.utbot.python.evaluation.PythonCodeExecutor
20
+ import org.utbot.python.evaluation.PythonCodeExecutorImpl
21
+ import org.utbot.python.evaluation.PythonEvaluationError
22
+ import org.utbot.python.evaluation.PythonEvaluationSuccess
23
+ import org.utbot.python.evaluation.PythonEvaluationTimeout
19
24
import org.utbot.python.framework.api.python.PythonTreeModel
20
25
import org.utbot.python.fuzzing.PythonFeedback
21
26
import org.utbot.python.fuzzing.PythonFuzzedConcreteValue
@@ -30,7 +35,6 @@ import org.utbot.python.utils.camelToSnakeCase
30
35
import org.utbot.summary.fuzzer.names.TestSuggestedInfo
31
36
32
37
private val logger = KotlinLogging .logger {}
33
- const val TIMEOUT : Long = 10
34
38
35
39
sealed interface FuzzingExecutionFeedback
36
40
class ValidExecution (val utFuzzedExecution : UtFuzzedExecution ): FuzzingExecutionFeedback
@@ -104,21 +108,23 @@ class PythonEngine(
104
108
" builtins.TypeError"
105
109
)
106
110
107
- if (evaluationResult.isException && (evaluationResult.result.type.name in prohibitedExceptions)) { // wrong type (sometimes mypy fails)
111
+ val resultModel = evaluationResult.stateAfter.getById(evaluationResult.resultId).toPythonTree(evaluationResult.stateAfter)
112
+
113
+ if (evaluationResult.isException && (resultModel.type.name in prohibitedExceptions)) { // wrong type (sometimes mypy fails)
108
114
val errorMessage = " Evaluation with prohibited exception. Substituted types: ${
109
115
types.joinToString { it.pythonTypeRepresentation() }
110
- } . Exception type: ${evaluationResult.result .type.name} "
116
+ } . Exception type: ${resultModel .type.name} "
111
117
112
118
logger.info(errorMessage)
113
119
return TypeErrorFeedback (errorMessage)
114
120
}
115
121
116
122
val executionResult =
117
123
if (evaluationResult.isException) {
118
- UtExplicitlyThrownException (Throwable (evaluationResult.result.output .type.toString()), false )
124
+ UtExplicitlyThrownException (Throwable (resultModel .type.toString()), false )
119
125
}
120
126
else {
121
- UtExecutionSuccess (PythonTreeModel (evaluationResult.result.output ))
127
+ UtExecutionSuccess (PythonTreeModel (resultModel ))
122
128
}
123
129
124
130
val testMethodName = suggestExecutionName(methodUnderTestDescription, executionResult)
@@ -138,7 +144,7 @@ class PythonEngine(
138
144
return ValidExecution (utFuzzedExecution)
139
145
}
140
146
141
- private fun constructEvaluationInput (arguments : List <PythonFuzzedValue >, additionalModules : List <String >): EvaluationInput {
147
+ private fun constructEvaluationInput (arguments : List <PythonFuzzedValue >, additionalModules : List <String >): PythonCodeExecutor {
142
148
val argumentValues = arguments.map { PythonTreeModel (it.tree, it.tree.type) }
143
149
144
150
val (thisObject, modelList) =
@@ -152,16 +158,15 @@ class PythonEngine(
152
158
.map { it.moduleName }
153
159
val localAdditionalModules = (additionalModules + argumentModules).toSet()
154
160
155
- return EvaluationInput (
161
+ return PythonCodeExecutorImpl (
156
162
methodUnderTest,
157
- directoriesForSysPath,
163
+ FunctionArguments (thisObject, methodUnderTest.thisObjectName, modelList, methodUnderTest.argumentsNames),
164
+ argumentValues.map { FuzzedValue (it) },
158
165
moduleToImport,
166
+ localAdditionalModules,
159
167
pythonPath,
168
+ directoriesForSysPath,
160
169
timeoutForRun,
161
- thisObject,
162
- modelList,
163
- argumentValues.map { FuzzedValue (it) },
164
- localAdditionalModules
165
170
)
166
171
}
167
172
@@ -188,10 +193,10 @@ class PythonEngine(
188
193
return @PythonFuzzing PythonFeedback (control = Control .STOP )
189
194
}
190
195
191
- val evaluationInput = constructEvaluationInput(arguments, additionalModules)
192
- val jobResult = evaluationInput.evaluate()
196
+ val codeExecutor = constructEvaluationInput(arguments, additionalModules)
197
+ // val jobResult = evaluationInput.evaluate()
193
198
194
- when (val evaluationResult = jobResult.evalResult ) {
199
+ when (val evaluationResult = codeExecutor. run () ) {
195
200
is PythonEvaluationError -> {
196
201
val utError = UtError (
197
202
" Error evaluation: ${evaluationResult.status} , ${evaluationResult.message} " ,
@@ -219,7 +224,7 @@ class PythonEngine(
219
224
.zip(methodUnderTest.arguments)
220
225
.mapNotNull { it.first.summary?.replace(" %var%" , it.second.name) }
221
226
222
- val hasThisObject = jobResult .thisObject != null
227
+ val hasThisObject = codeExecutor.methodArguments .thisObject != null
223
228
val result = handleSuccessResult(parameters, evaluationResult, description, hasThisObject, summary)
224
229
emit(result)
225
230
0 commit comments