[evaluation-plugin] Implement a simple test runner for python

GitOrigin-RevId: 381ca34815eab4e495f51f1c8bdbb716931f8c4b
This commit is contained in:
Roman Vasiliev
2025-08-28 11:20:08 +02:00
committed by intellij-monorepo-bot
parent 36e42137f5
commit b9fec562cc
2 changed files with 58 additions and 0 deletions

View File

@@ -15,6 +15,7 @@
<completionEvaluationVisitor implementation="com.intellij.cce.python.visitor.PythonRenameVisitor"/>
<completionEvaluationVisitor implementation="com.intellij.cce.python.visitor.PythonTestGenerationVisitor"/>
<codeExecutionManager implementation="com.intellij.cce.python.execution.manager.PythonCodeExecutionManager"/>
<testRunner implementation="com.intellij.cce.python.test.PythonTestRunner"/>
<apiCallExtractor implementation="com.intellij.cce.python.chat.PythonApiCallExtractorProvider"/>
</extensions>
</idea-plugin>

View File

@@ -0,0 +1,57 @@
package com.intellij.cce.python.test
import com.intellij.cce.core.Language
import com.intellij.cce.test.TestRunRequest
import com.intellij.cce.test.TestRunResult
import com.intellij.cce.test.TestRunner
import com.intellij.cce.test.TestRunnerParams
import com.intellij.execution.configurations.GeneralCommandLine
import com.intellij.execution.process.CapturingProcessHandler
import com.intellij.openapi.project.guessProjectDir
class PythonTestRunner : TestRunner {
override fun isApplicable(params: TestRunnerParams): Boolean =
params.language == Language.PYTHON
override suspend fun runTests(request: TestRunRequest): TestRunResult {
// TODO unify with JavaTestRunner
val testCommand = System.getenv("EVALUATION_TEST_COMMAND")
requireNotNull(testCommand) { "Only test running via command is supported" }
val testCommandParts = testCommand.split(" ")
val commandLine = GeneralCommandLine(testCommandParts[0])
.withWorkingDirectory(request.project.guessProjectDir()!!.toNioPath())
.also {
testCommandParts.drop(1).forEach { param -> it.addParameter(param) }
}
val process = CapturingProcessHandler(commandLine).runProcess()
val passedTests = process.stdoutLines
.filter { it.contains("PASSED") }
.map { it.substringBefore("PASSED").trim() }
.filter { it.isNotEmpty() }
.map(::normalizeTestName)
val failedTests = process.stdoutLines
.filter { it.contains("FAILED") }
.map { it.substringBefore("FAILED").trim() }
.filter { it.isNotEmpty() }
.map(::normalizeTestName)
return TestRunResult(
exitCode = process.exitCode,
passed = passedTests,
failed = failedTests,
expected = request.tests,
compilationSuccessful = true,
projectIsResolvable = true,
output = process.stdout + "\n\nSTDERR\n\n" + process.stderr,
)
}
private fun normalizeTestName(testName: String): String =
testName.replace("::", ":None:")
}