Skip to content

Commit 9c795ad

Browse files
committed
Fix python coverage database bug with access to database directory (#1553)
1 parent 200708f commit 9c795ad

File tree

7 files changed

+37
-24
lines changed

7 files changed

+37
-24
lines changed

utbot-intellij-python/src/main/kotlin/org/utbot/intellij/plugin/language/python/PythonDialogProcessor.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,10 @@ object PythonDialogProcessor {
233233
if (installResult.exitValue != 0) {
234234
showErrorDialogLater(
235235
project,
236-
"Requirements installing failed",
236+
"Requirements installing failed.<br>" +
237+
"${installResult.stderr}<br><br>" +
238+
"Try to install with pip:<br>" +
239+
" ${requirements.joinToString("<br>")}",
237240
"Requirements error"
238241
)
239242
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,13 +335,16 @@ class PythonEngine(
335335
when (val evaluationResult = jobResult.evalResult) {
336336
is PythonEvaluationError -> {
337337
if (evaluationResult.status != 0) {
338+
val errorMessage = "Error evaluation: ${evaluationResult.status}, ${evaluationResult.message}, ${evaluationResult.stackTrace}"
339+
logger.info { errorMessage }
338340
emit(
339341
UtError(
340-
"Error evaluation: ${evaluationResult.status}, ${evaluationResult.message}",
342+
errorMessage,
341343
Throwable(evaluationResult.stackTrace.joinToString("\n"))
342344
)
343345
)
344346
} else {
347+
logger.info { "Python evaluation error: ${evaluationResult.message}" }
345348
emit(
346349
UtError(
347350
evaluationResult.message,

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import org.utbot.python.utils.getResult
1515
import org.utbot.python.utils.startProcess
1616
import java.io.File
1717

18-
1918
sealed class PythonEvaluationResult
2019

2120
class PythonEvaluationError(
@@ -64,13 +63,18 @@ fun startEvaluationProcess(input: EvaluationInput): EvaluationProcess {
6463
tag = "out_" + input.method.name + ".py",
6564
addToCleaner = false
6665
)
66+
val coverageDatabasePath = TemporaryFileManager.assignTemporaryFile(
67+
tag = "coverage_db_" + input.method.name,
68+
addToCleaner = false,
69+
)
6770
val runCode = PythonCodeGenerator.generateRunFunctionCode(
6871
input.method,
6972
input.methodArguments,
7073
input.directoriesForSysPath,
7174
input.moduleToImport,
7275
input.additionalModulesToImport,
73-
fileForOutput.path.replace("\\", "\\\\")
76+
fileForOutput.path.replace("\\", "\\\\"),
77+
coverageDatabasePath.absolutePath.replace("\\", "\\\\")
7478
)
7579
val fileWithCode = TemporaryFileManager.createTemporaryFile(
7680
runCode,

utbot-python/src/main/kotlin/org/utbot/python/code/CodeGen.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ object PythonCodeGenerator {
2020
directoriesForSysPath: Set<String>,
2121
moduleToImport: String,
2222
additionalModules: Set<String> = emptySet(),
23-
fileForOutputName: String
23+
fileForOutputName: String,
24+
coverageDatabasePath: String,
2425
): String {
2526
val context = UtContext(this::class.java.classLoader)
2627
withUtContext(context) {
@@ -36,7 +37,8 @@ object PythonCodeGenerator {
3637
directoriesForSysPath,
3738
moduleToImport,
3839
additionalModules,
39-
fileForOutputName
40+
fileForOutputName,
41+
coverageDatabasePath,
4042
)
4143
}
4244
}

utbot-python/src/main/kotlin/org/utbot/python/framework/codegen/model/PythonCodeGenerator.kt

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ class PythonCodeGenerator(
108108
directoriesForSysPath: Set<String>,
109109
moduleToImport: String,
110110
additionalModules: Set<String> = emptySet(),
111-
fileForOutputName: String
111+
fileForOutputName: String,
112+
coverageDatabasePath: String,
112113
): String = withCustomContext(testClassCustomName = null) {
113114
context.withTestClassFileScope {
114115
clearContextRelatedStorage()
@@ -160,21 +161,22 @@ class PythonCodeGenerator(
160161
arguments.associateBy { argument -> CgLiteral(pythonStrClassId, "'${argument.name}'") }
161162
)
162163

163-
val fullpath = CgLiteral(pythonStrClassId, "'${method.moduleFilename}'")
164-
165-
val outputPath = CgLiteral(pythonStrClassId, "'$fileForOutputName'")
166-
167-
val executorCall = CgPythonFunctionCall(
168-
pythonNoneClassId,
169-
executorFunctionName,
170-
listOf(
171-
functionName,
172-
args,
173-
kwargs,
174-
fullpath,
175-
outputPath,
176-
)
164+
val fullpath = CgLiteral(pythonStrClassId, "'${method.moduleFilename.replace("\\", "\\\\")}'")
165+
val outputPath = CgLiteral(pythonStrClassId, "'$fileForOutputName'")
166+
val databasePath = CgLiteral(pythonStrClassId, "'$coverageDatabasePath'")
167+
168+
val executorCall = CgPythonFunctionCall(
169+
pythonNoneClassId,
170+
executorFunctionName,
171+
listOf(
172+
databasePath,
173+
functionName,
174+
args,
175+
kwargs,
176+
fullpath,
177+
outputPath,
177178
)
179+
)
178180

179181
parameters.forEach { it.accept(renderer) }
180182
executorCall.accept(renderer)

utbot-python/src/main/kotlin/org/utbot/python/utils/TemporaryFileManager.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@ import org.utbot.common.FileUtil
44
import java.io.File
55
import java.nio.file.Path
66
import java.nio.file.Paths
7-
import kotlin.io.path.deleteExisting
87

98
object TemporaryFileManager {
109
private lateinit var tmpDirectory: Path
1110
private var nextId = 0
1211

1312
fun setup() {
1413
tmpDirectory = FileUtil.createTempDirectory("python-test-generation-${nextId++}")
15-
Cleaner.addFunction { tmpDirectory.deleteExisting() }
14+
Cleaner.addFunction { tmpDirectory.toFile().deleteRecursively() }
1615
}
1716

1817
fun assignTemporaryFile(fileName_: String? = null, tag: String? = null, addToCleaner: Boolean = true): File {

utbot-python/src/main/resources/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ mypy==0.971
22
astor
33
typeshed-client
44
coverage
5-
utbot-executor==0.1.4
5+
utbot-executor==0.1.7
66
utbot-mypy-runner==0.1.10

0 commit comments

Comments
 (0)