From b3ad580a3fb20d5a79a66f2cf1d6839b02fab790 Mon Sep 17 00:00:00 2001 From: Vyacheslav Tamarin Date: Sun, 5 Mar 2023 14:49:04 +0300 Subject: [PATCH] Integrate test framework installation to requirements installation --- .../language/python/PythonGenerateTestsCommand.kt | 3 --- .../language/python/PythonDialogProcessor.kt | 15 +++++++++------ .../utbot/python/PythonTestGenerationProcessor.kt | 10 ---------- 3 files changed, 9 insertions(+), 19 deletions(-) diff --git a/utbot-cli-python/src/main/kotlin/org/utbot/cli/language/python/PythonGenerateTestsCommand.kt b/utbot-cli-python/src/main/kotlin/org/utbot/cli/language/python/PythonGenerateTestsCommand.kt index 768bf49f88..37c4b73b64 100644 --- a/utbot-cli-python/src/main/kotlin/org/utbot/cli/language/python/PythonGenerateTestsCommand.kt +++ b/utbot-cli-python/src/main/kotlin/org/utbot/cli/language/python/PythonGenerateTestsCommand.kt @@ -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...") diff --git a/utbot-intellij-python/src/main/kotlin/org/utbot/intellij/plugin/language/python/PythonDialogProcessor.kt b/utbot-intellij-python/src/main/kotlin/org/utbot/intellij/plugin/language/python/PythonDialogProcessor.kt index c9b2b57ae2..54106700a3 100644 --- a/utbot-intellij-python/src/main/kotlin/org/utbot/intellij/plugin/language/python/PythonDialogProcessor.kt +++ b/utbot-intellij-python/src/main/kotlin/org/utbot/intellij/plugin/language/python/PythonDialogProcessor.kt @@ -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, @@ -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" }, @@ -245,11 +248,11 @@ object PythonDialogProcessor { } } - private fun askAndInstallRequirementsLater(project: Project, pythonPath: String) { + private fun askAndInstallRequirementsLater(project: Project, pythonPath: String, requirementsList: List) { val message = """ Some requirements are not installed. Requirements:
- ${requirements.joinToString("
")} + ${requirementsList.joinToString("
")}
Install them? """.trimIndent() @@ -267,7 +270,7 @@ 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( @@ -275,7 +278,7 @@ object PythonDialogProcessor { "Requirements installing failed.
" + "${installResult.stderr}

" + "Try to install with pip:
" + - " ${requirements.joinToString("
")}", + " ${requirementsList.joinToString("
")}", "Requirements error" ) } diff --git a/utbot-python/src/main/kotlin/org/utbot/python/PythonTestGenerationProcessor.kt b/utbot-python/src/main/kotlin/org/utbot/python/PythonTestGenerationProcessor.kt index b35d36a809..1f8c3d3e3b 100644 --- a/utbot-python/src/main/kotlin/org/utbot/python/PythonTestGenerationProcessor.kt +++ b/utbot-python/src/main/kotlin/org/utbot/python/PythonTestGenerationProcessor.kt @@ -2,7 +2,6 @@ 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 @@ -10,7 +9,6 @@ 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 @@ -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, @@ -58,7 +53,6 @@ object PythonTestGenerationProcessor { isCanceled: () -> Boolean = { false }, checkingRequirementsAction: () -> Unit = {}, installingRequirementsAction: () -> Unit = {}, - testFrameworkInstallationAction: () -> Unit = {}, requirementsAreNotInstalledAction: () -> MissingRequirementsActionResult = { MissingRequirementsActionResult.NOT_INSTALLED }, @@ -73,10 +67,6 @@ object PythonTestGenerationProcessor { Cleaner.restart() try { - if (!testFramework.isInstalled) { - testFrameworkInstallationAction() - installRequirements(pythonPath, listOf(testFramework.mainPackage)) - } if (!doNotCheckRequirements) { checkingRequirementsAction() if (!requirementsAreInstalled(pythonPath)) {