Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,6 @@ class PythonGenerateTestsCommand : CliktCommand(
installingRequirementsAction = {
logger.info("Installing requirements...")
},
testFrameworkInstallationAction = {
logger.info("Test framework installation...")
},
requirementsAreNotInstalledAction = ::processMissingRequirements,
startedLoadingPythonTypesAction = {
logger.info("Loading information about Python types...")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ object PythonDialogProcessor {
}
try {
val methods = findSelectedPythonMethods(model)
val requirementsList = requirements.toMutableList()
if (!model.testFramework.isInstalled) {
requirementsList += model.testFramework.mainPackage
}

processTestGeneration(
pythonPath = model.pythonPath,
Expand All @@ -185,9 +189,8 @@ object PythonDialogProcessor {
isCanceled = { indicator.isCanceled },
checkingRequirementsAction = { indicator.text = "Checking requirements" },
installingRequirementsAction = { indicator.text = "Installing requirements..." },
testFrameworkInstallationAction = { indicator.text = "Test framework installation" },
requirementsAreNotInstalledAction = {
askAndInstallRequirementsLater(model.project, model.pythonPath)
askAndInstallRequirementsLater(model.project, model.pythonPath, requirementsList)
PythonTestGenerationProcessor.MissingRequirementsActionResult.NOT_INSTALLED
},
startedLoadingPythonTypesAction = { indicator.text = "Loading information about Python types" },
Expand Down Expand Up @@ -245,11 +248,11 @@ object PythonDialogProcessor {
}
}

private fun askAndInstallRequirementsLater(project: Project, pythonPath: String) {
private fun askAndInstallRequirementsLater(project: Project, pythonPath: String, requirementsList: List<String>) {
val message = """
Some requirements are not installed.
Requirements: <br>
${requirements.joinToString("<br>")}
${requirementsList.joinToString("<br>")}
<br>
Install them?
""".trimIndent()
Expand All @@ -267,15 +270,15 @@ object PythonDialogProcessor {

ProgressManager.getInstance().run(object : Backgroundable(project, "Installing requirements") {
override fun run(indicator: ProgressIndicator) {
val installResult = installRequirements(pythonPath)
val installResult = installRequirements(pythonPath, requirementsList)

if (installResult.exitValue != 0) {
showErrorDialogLater(
project,
"Requirements installing failed.<br>" +
"${installResult.stderr}<br><br>" +
"Try to install with pip:<br>" +
" ${requirements.joinToString("<br>")}",
" ${requirementsList.joinToString("<br>")}",
"Requirements error"
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ package org.utbot.python

import com.squareup.moshi.Moshi
import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory
import mu.KotlinLogging
import org.parsers.python.PythonParser
import org.utbot.python.framework.codegen.model.PythonSysPathImport
import org.utbot.python.framework.codegen.model.PythonSystemImport
import org.utbot.python.framework.codegen.model.PythonUserImport
import org.utbot.framework.codegen.domain.TestFramework
import org.utbot.framework.codegen.domain.models.CgMethodTestSet
import org.utbot.framework.plugin.api.ExecutableId
import org.utbot.framework.plugin.api.TimeoutException
import org.utbot.framework.plugin.api.UtClusterInfo
import org.utbot.framework.plugin.api.UtExecutionSuccess
import org.utbot.framework.plugin.api.util.UtContext
Expand All @@ -30,15 +28,12 @@ import org.utbot.python.newtyping.mypy.readMypyAnnotationStorageAndInitialErrors
import org.utbot.python.newtyping.mypy.setConfigFile
import org.utbot.python.typing.MypyAnnotations
import org.utbot.python.utils.Cleaner
import org.utbot.python.utils.RequirementsUtils.installRequirements
import org.utbot.python.utils.RequirementsUtils.requirementsAreInstalled
import org.utbot.python.utils.getLineOfFunction
import java.nio.file.Path
import kotlin.io.path.Path
import kotlin.io.path.pathString

private val logger = KotlinLogging.logger {}

object PythonTestGenerationProcessor {
fun processTestGeneration(
pythonPath: String,
Expand All @@ -58,7 +53,6 @@ object PythonTestGenerationProcessor {
isCanceled: () -> Boolean = { false },
checkingRequirementsAction: () -> Unit = {},
installingRequirementsAction: () -> Unit = {},
testFrameworkInstallationAction: () -> Unit = {},
requirementsAreNotInstalledAction: () -> MissingRequirementsActionResult = {
MissingRequirementsActionResult.NOT_INSTALLED
},
Expand All @@ -73,10 +67,6 @@ object PythonTestGenerationProcessor {
Cleaner.restart()

try {
if (!testFramework.isInstalled) {
testFrameworkInstallationAction()
installRequirements(pythonPath, listOf(testFramework.mainPackage))
}
if (!doNotCheckRequirements) {
checkingRequirementsAction()
if (!requirementsAreInstalled(pythonPath)) {
Expand Down