Skip to content

Improve python object constructors rendering #2078

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions utbot-python/src/main/kotlin/org/utbot/python/PythonEngine.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import mu.KotlinLogging
import org.utbot.framework.plugin.api.*
import org.utbot.fuzzer.UtFuzzedExecution
import org.utbot.fuzzing.Control
import org.utbot.fuzzing.fuzz
import org.utbot.fuzzing.utils.Trie
Expand All @@ -14,6 +13,7 @@ import org.utbot.python.evaluation.serialiation.toPythonTree
import org.utbot.python.framework.api.python.PythonTree
import org.utbot.python.framework.api.python.PythonTreeModel
import org.utbot.python.framework.api.python.PythonTreeWrapper
import org.utbot.python.framework.api.python.PythonUtExecution
import org.utbot.python.fuzzing.*
import org.utbot.python.newtyping.PythonTypeStorage
import org.utbot.python.newtyping.general.Type
Expand Down Expand Up @@ -117,12 +117,15 @@ class PythonEngine(

val testMethodName = suggestExecutionName(methodUnderTestDescription, executionResult)

val (thisObject, initModelList) = transformModelList(hasThisObject, evaluationResult.stateInit, evaluationResult.modelListIds)
val (beforeThisObject, beforeModelList) = transformModelList(hasThisObject, evaluationResult.stateBefore, evaluationResult.modelListIds)
val (afterThisObject, afterModelList) = transformModelList(hasThisObject, evaluationResult.stateAfter, evaluationResult.modelListIds)

val utFuzzedExecution = UtFuzzedExecution(
val utFuzzedExecution = PythonUtExecution(
stateInit = EnvironmentModels(thisObject, initModelList, emptyMap()),
stateBefore = EnvironmentModels(beforeThisObject, beforeModelList, emptyMap()),
stateAfter = EnvironmentModels(afterThisObject, afterModelList, emptyMap()),
diffIds = evaluationResult.diffIds,
result = executionResult,
coverage = evaluationResult.coverage,
testMethodName = testMethodName.testName?.camelToSnakeCase(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import org.utbot.framework.minimization.minimizeExecutions
import org.utbot.framework.plugin.api.UtError
import org.utbot.framework.plugin.api.UtExecution
import org.utbot.framework.plugin.api.UtExecutionSuccess
import org.utbot.python.framework.api.python.PythonUtExecution
import org.utbot.python.fuzzing.*
import org.utbot.python.newtyping.*
import org.utbot.python.newtyping.ast.visitor.Visitor
Expand Down Expand Up @@ -123,7 +124,7 @@ class PythonTestCaseGenerator(
typeStorage: PythonTypeStorage,
coveredLines: MutableSet<Int>,
errors: MutableList<UtError>,
executions: MutableList<UtExecution>,
executions: MutableList<PythonUtExecution>,
initMissingLines: Set<Int>?,
until: Long,
additionalVars: String = ""
Expand Down Expand Up @@ -218,7 +219,7 @@ class PythonTestCaseGenerator(

val typeStorage = PythonTypeStorage.get(mypyStorage)

val executions = mutableListOf<UtExecution>()
val executions = mutableListOf<PythonUtExecution>()
val errors = mutableListOf<UtError>()
val coveredLines = mutableSetOf<Int>()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,10 @@ object PythonTestGenerationProcessor {
testFrameworkModule,
sysImport
)
).filterNotNull().toSet()
)
.filterNotNull()
// .filterNot { it.importName == pythonBuiltinsModuleName }
.toSet()

val context = UtContext(this::class.java.classLoader)
withUtContext(context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ data class PythonEvaluationTimeout(
data class PythonEvaluationSuccess(
val isException: Boolean,
val coverage: Coverage,
val stateInit: MemoryDump,
val stateBefore: MemoryDump,
val stateAfter: MemoryDump,
val diffIds: List<Long>,
val modelListIds: List<String>,
val resultId: String,
) : PythonEvaluationResult()

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class PythonCodeSocketExecutor(
additionalModulesToImport.toList(),
syspathDirectories.toList(),
arguments,
emptyMap(), // here can be only-kwargs arguments
memory,
method.moduleFilename,
)
Expand Down Expand Up @@ -102,14 +103,18 @@ class PythonCodeSocketExecutor(
)
return when (executionResult) {
is SuccessExecution -> {
val stateInit = ExecutionResultDeserializer.parseMemoryDump(executionResult.stateInit) ?: return parsingException
val stateBefore = ExecutionResultDeserializer.parseMemoryDump(executionResult.stateBefore) ?: return parsingException
val stateAfter = ExecutionResultDeserializer.parseMemoryDump(executionResult.stateAfter) ?: return parsingException
val diffIds = executionResult.diffIds.map {it.toLong()}
PythonEvaluationSuccess(
executionResult.isException,
calculateCoverage(executionResult.statements, executionResult.missedStatements),
stateInit,
stateBefore,
stateAfter,
executionResult.argsIds + executionResult.kwargsIds,
diffIds,
executionResult.argsIds + executionResult.kwargsIds.values,
executionResult.resultId,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ data class ExecutionRequest(
val imports: List<String>,
val syspaths: List<String>,
val argumentsIds: List<String>,
val kwargumentsIds: Map<String, String>,
val serializedMemory: String,
val filepath: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@ data class SuccessExecution(
val isException: Boolean,
val statements: List<Int>,
val missedStatements: List<Int>,
val stateInit: String,
val stateBefore: String,
val stateAfter: String,
val diffIds: List<String>,
val argsIds: List<String>,
val kwargsIds: List<String>,
val kwargsIds: Map<String, String>,
val resultId: String,
): PythonExecutionResult()

Expand Down
Loading