Skip to content

Commit 86544b6

Browse files
authored
Improve python object constructors rendering (#2078)
1 parent 70be794 commit 86544b6

19 files changed

+227
-724
lines changed

utbot-python/src/main/kotlin/org/utbot/python/PythonEngine.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import kotlinx.coroutines.flow.Flow
44
import kotlinx.coroutines.flow.flow
55
import mu.KotlinLogging
66
import org.utbot.framework.plugin.api.*
7-
import org.utbot.fuzzer.UtFuzzedExecution
87
import org.utbot.fuzzing.Control
98
import org.utbot.fuzzing.fuzz
109
import org.utbot.fuzzing.utils.Trie
@@ -14,6 +13,7 @@ import org.utbot.python.evaluation.serialiation.toPythonTree
1413
import org.utbot.python.framework.api.python.PythonTree
1514
import org.utbot.python.framework.api.python.PythonTreeModel
1615
import org.utbot.python.framework.api.python.PythonTreeWrapper
16+
import org.utbot.python.framework.api.python.PythonUtExecution
1717
import org.utbot.python.fuzzing.*
1818
import org.utbot.python.newtyping.PythonTypeStorage
1919
import org.utbot.python.newtyping.general.Type
@@ -117,12 +117,15 @@ class PythonEngine(
117117

118118
val testMethodName = suggestExecutionName(methodUnderTestDescription, executionResult)
119119

120+
val (thisObject, initModelList) = transformModelList(hasThisObject, evaluationResult.stateInit, evaluationResult.modelListIds)
120121
val (beforeThisObject, beforeModelList) = transformModelList(hasThisObject, evaluationResult.stateBefore, evaluationResult.modelListIds)
121122
val (afterThisObject, afterModelList) = transformModelList(hasThisObject, evaluationResult.stateAfter, evaluationResult.modelListIds)
122123

123-
val utFuzzedExecution = UtFuzzedExecution(
124+
val utFuzzedExecution = PythonUtExecution(
125+
stateInit = EnvironmentModels(thisObject, initModelList, emptyMap()),
124126
stateBefore = EnvironmentModels(beforeThisObject, beforeModelList, emptyMap()),
125127
stateAfter = EnvironmentModels(afterThisObject, afterModelList, emptyMap()),
128+
diffIds = evaluationResult.diffIds,
126129
result = executionResult,
127130
coverage = evaluationResult.coverage,
128131
testMethodName = testMethodName.testName?.camelToSnakeCase(),

utbot-python/src/main/kotlin/org/utbot/python/PythonTestCaseGenerator.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import org.utbot.framework.minimization.minimizeExecutions
66
import org.utbot.framework.plugin.api.UtError
77
import org.utbot.framework.plugin.api.UtExecution
88
import org.utbot.framework.plugin.api.UtExecutionSuccess
9+
import org.utbot.python.framework.api.python.PythonUtExecution
910
import org.utbot.python.fuzzing.*
1011
import org.utbot.python.newtyping.*
1112
import org.utbot.python.newtyping.ast.visitor.Visitor
@@ -123,7 +124,7 @@ class PythonTestCaseGenerator(
123124
typeStorage: PythonTypeStorage,
124125
coveredLines: MutableSet<Int>,
125126
errors: MutableList<UtError>,
126-
executions: MutableList<UtExecution>,
127+
executions: MutableList<PythonUtExecution>,
127128
initMissingLines: Set<Int>?,
128129
until: Long,
129130
additionalVars: String = ""
@@ -218,7 +219,7 @@ class PythonTestCaseGenerator(
218219

219220
val typeStorage = PythonTypeStorage.get(mypyStorage)
220221

221-
val executions = mutableListOf<UtExecution>()
222+
val executions = mutableListOf<PythonUtExecution>()
222223
val errors = mutableListOf<UtError>()
223224
val coveredLines = mutableSetOf<Int>()
224225

utbot-python/src/main/kotlin/org/utbot/python/PythonTestGenerationProcessor.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,10 @@ object PythonTestGenerationProcessor {
190190
testFrameworkModule,
191191
sysImport
192192
)
193-
).filterNotNull().toSet()
193+
)
194+
.filterNotNull()
195+
// .filterNot { it.importName == pythonBuiltinsModuleName }
196+
.toSet()
194197

195198
val context = UtContext(this::class.java.classLoader)
196199
withUtContext(context) {

utbot-python/src/main/kotlin/org/utbot/python/evaluation/CodeEvaluationApi.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ data class PythonEvaluationTimeout(
3535
data class PythonEvaluationSuccess(
3636
val isException: Boolean,
3737
val coverage: Coverage,
38+
val stateInit: MemoryDump,
3839
val stateBefore: MemoryDump,
3940
val stateAfter: MemoryDump,
41+
val diffIds: List<Long>,
4042
val modelListIds: List<String>,
4143
val resultId: String,
4244
) : PythonEvaluationResult()

utbot-python/src/main/kotlin/org/utbot/python/evaluation/PythonCodeExecutorImpl.kt

Lines changed: 0 additions & 144 deletions
This file was deleted.

utbot-python/src/main/kotlin/org/utbot/python/evaluation/PythonCodeSocketExecutor.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class PythonCodeSocketExecutor(
6666
additionalModulesToImport.toList(),
6767
syspathDirectories.toList(),
6868
arguments,
69+
emptyMap(), // here can be only-kwargs arguments
6970
memory,
7071
method.moduleFilename,
7172
)
@@ -102,14 +103,18 @@ class PythonCodeSocketExecutor(
102103
)
103104
return when (executionResult) {
104105
is SuccessExecution -> {
106+
val stateInit = ExecutionResultDeserializer.parseMemoryDump(executionResult.stateInit) ?: return parsingException
105107
val stateBefore = ExecutionResultDeserializer.parseMemoryDump(executionResult.stateBefore) ?: return parsingException
106108
val stateAfter = ExecutionResultDeserializer.parseMemoryDump(executionResult.stateAfter) ?: return parsingException
109+
val diffIds = executionResult.diffIds.map {it.toLong()}
107110
PythonEvaluationSuccess(
108111
executionResult.isException,
109112
calculateCoverage(executionResult.statements, executionResult.missedStatements),
113+
stateInit,
110114
stateBefore,
111115
stateAfter,
112-
executionResult.argsIds + executionResult.kwargsIds,
116+
diffIds,
117+
executionResult.argsIds + executionResult.kwargsIds.values,
113118
executionResult.resultId,
114119
)
115120
}

utbot-python/src/main/kotlin/org/utbot/python/evaluation/serialiation/ExecutionRequestSerializer.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ data class ExecutionRequest(
2121
val imports: List<String>,
2222
val syspaths: List<String>,
2323
val argumentsIds: List<String>,
24+
val kwargumentsIds: Map<String, String>,
2425
val serializedMemory: String,
2526
val filepath: String,
2627
)

utbot-python/src/main/kotlin/org/utbot/python/evaluation/serialiation/ExecutionResultDeserializer.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,12 @@ data class SuccessExecution(
4545
val isException: Boolean,
4646
val statements: List<Int>,
4747
val missedStatements: List<Int>,
48+
val stateInit: String,
4849
val stateBefore: String,
4950
val stateAfter: String,
51+
val diffIds: List<String>,
5052
val argsIds: List<String>,
51-
val kwargsIds: List<String>,
53+
val kwargsIds: Map<String, String>,
5254
val resultId: String,
5355
): PythonExecutionResult()
5456

0 commit comments

Comments
 (0)