From fbdc3ba878e8d22489ec4b1ac4358f339dc81466 Mon Sep 17 00:00:00 2001 From: Vyacheslav Tamarin Date: Mon, 24 Apr 2023 18:54:35 +0300 Subject: [PATCH 1/3] Save python settings --- .../language/python/PythonDialogProcessor.kt | 5 +- .../language/python/PythonDialogWindow.kt | 69 +++++++++---------- .../language/python/settings/Settings.kt | 17 +++++ 3 files changed, 54 insertions(+), 37 deletions(-) create mode 100644 utbot-intellij-python/src/main/kotlin/org/utbot/intellij/plugin/language/python/settings/Settings.kt 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 f8aa3ffb6d..1b5fdf1cc9 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 @@ -3,6 +3,7 @@ package org.utbot.intellij.plugin.language.python import com.intellij.codeInsight.CodeInsightUtil import com.intellij.openapi.application.invokeLater import com.intellij.openapi.application.readAction +import com.intellij.openapi.components.service import com.intellij.openapi.editor.Editor import com.intellij.openapi.fileEditor.FileDocumentManager import com.intellij.openapi.module.Module @@ -27,8 +28,8 @@ import org.jetbrains.kotlin.idea.util.module import org.jetbrains.kotlin.idea.util.projectStructure.sdk import org.utbot.common.PathUtil.toPath import org.utbot.common.appendHtmlLine -import org.utbot.framework.UtSettings import org.utbot.framework.plugin.api.util.LockFile +import org.utbot.intellij.plugin.settings.Settings import org.utbot.intellij.plugin.ui.WarningTestsReportNotifier import org.utbot.intellij.plugin.ui.utils.showErrorDialogLater import org.utbot.intellij.plugin.ui.utils.testModules @@ -112,7 +113,7 @@ object PythonDialogProcessor { file, directoriesForSysPath, moduleToImport, - UtSettings.utBotGenerationTimeoutInMillis, + project.service().generationTimeoutInMillis, DEFAULT_TIMEOUT_FOR_RUN_IN_MILLIS, cgLanguageAssistant = PythonCgLanguageAssistant, pythonPath = pythonPath, diff --git a/utbot-intellij-python/src/main/kotlin/org/utbot/intellij/plugin/language/python/PythonDialogWindow.kt b/utbot-intellij-python/src/main/kotlin/org/utbot/intellij/plugin/language/python/PythonDialogWindow.kt index 7f15e519f7..38f6b8deff 100644 --- a/utbot-intellij-python/src/main/kotlin/org/utbot/intellij/plugin/language/python/PythonDialogWindow.kt +++ b/utbot-intellij-python/src/main/kotlin/org/utbot/intellij/plugin/language/python/PythonDialogWindow.kt @@ -3,30 +3,29 @@ package org.utbot.intellij.plugin.language.python import com.intellij.openapi.components.service import com.intellij.openapi.project.Project import com.intellij.openapi.ui.* -import com.intellij.ui.ContextHelpLabel import com.intellij.ui.JBIntSpinner -import com.intellij.ui.components.Panel -import com.intellij.ui.layout.CellBuilder -import com.intellij.ui.layout.Row -import com.intellij.ui.layout.panel +import com.intellij.ui.components.JBLabel +import com.intellij.ui.components.JBScrollPane +import com.intellij.ui.dsl.builder.Align +import com.intellij.ui.dsl.builder.panel import com.intellij.util.ui.JBUI +import com.intellij.util.ui.components.BorderLayoutPanel import com.jetbrains.python.psi.* import com.jetbrains.python.refactoring.classes.PyMemberInfoStorage import com.jetbrains.python.refactoring.classes.membersManager.PyMemberInfo import com.jetbrains.python.refactoring.classes.ui.PyMemberSelectionTable -import org.utbot.framework.UtSettings import org.utbot.framework.codegen.domain.ProjectType +import org.utbot.framework.codegen.domain.TestFramework +import org.utbot.intellij.plugin.language.python.settings.loadStateFromModel import org.utbot.intellij.plugin.settings.Settings -import java.awt.BorderLayout import java.util.concurrent.TimeUnit import org.utbot.intellij.plugin.ui.components.TestSourceDirectoryChooser import org.utbot.intellij.plugin.ui.utils.createTestFrameworksRenderer import java.awt.event.ActionEvent import javax.swing.* - private const val WILL_BE_INSTALLED_LABEL = " (will be installed)" -private const val MINIMUM_TIMEOUT_VALUE_IN_SECONDS = 1 +private const val MINIMUM_TIMEOUT_VALUE_IN_SECONDS = 5 private const val ACTION_GENERATE = "Generate Tests" class PythonDialogWindow(val model: PythonTestsModel) : DialogWrapper(model.project) { @@ -35,7 +34,7 @@ class PythonDialogWindow(val model: PythonTestsModel) : DialogWrapper(model.proj private val testSourceFolderField = TestSourceDirectoryChooser(model, model.file.virtualFile) private val timeoutSpinnerForTotalTimeout = JBIntSpinner( - TimeUnit.MILLISECONDS.toSeconds(UtSettings.utBotGenerationTimeoutInMillis).toInt(), + TimeUnit.MILLISECONDS.toSeconds(model.timeout).toInt(), MINIMUM_TIMEOUT_VALUE_IN_SECONDS, Int.MAX_VALUE, MINIMUM_TIMEOUT_VALUE_IN_SECONDS @@ -44,6 +43,7 @@ class PythonDialogWindow(val model: PythonTestsModel) : DialogWrapper(model.proj ComboBox(DefaultComboBoxModel(model.cgLanguageAssistant.getLanguageTestFrameworkManager().testFrameworks.toTypedArray())) private lateinit var panel: DialogPanel + private lateinit var currentFrameworkItem: TestFramework init { title = "Generate Tests with UnitTestBot" @@ -57,36 +57,42 @@ class PythonDialogWindow(val model: PythonTestsModel) : DialogWrapper(model.proj } override fun createCenterPanel(): JComponent { - panel = panel { row("Test sources root:") { - component(testSourceFolderField) + cell(testSourceFolderField).align(Align.FILL) } - row("Test framework:") { - makePanelWithHelpTooltip( - testFrameworks, - null - ) + row("Testing framework:") { + cell(testFrameworks) } - row("Timeout for all selected functions:") { - cell { - component(timeoutSpinnerForTotalTimeout) - label("seconds") - component(ContextHelpLabel.create("Set the timeout for all test generation processes.")) - } + row("Test generation timeout:") { + cell(BorderLayoutPanel().apply { + addToLeft(timeoutSpinnerForTotalTimeout) + addToRight(JBLabel("seconds per function")) + }) + contextHelp("Set the timeout for all test generation processes per function to complete.") } - row("Generate test methods for:") {} + row("Generate tests for:") {} row { - scrollPane(functionsTable) + cell(JBScrollPane(functionsTable)).align(Align.FILL) } } + initDefaultValues() updateFunctionsTable() - updateTestFrameworksList() return panel } + private fun initDefaultValues() { + val settings = model.project.service() + + val installedTestFramework = TestFramework.allItems.singleOrNull { it.isInstalled } + currentFrameworkItem = installedTestFramework ?: settings.testFramework + + updateTestFrameworksList() + } + private fun updateTestFrameworksList() { + testFrameworks.item = currentFrameworkItem testFrameworks.renderer = createTestFrameworksRenderer(WILL_BE_INSTALLED_LABEL) } @@ -144,15 +150,6 @@ class PythonDialogWindow(val model: PythonTestsModel) : DialogWrapper(model.proj private fun checkMembers(members: Collection>) = members.forEach { it.isChecked = true } - private fun Row.makePanelWithHelpTooltip( - mainComponent: JComponent, - contextHelpLabel: ContextHelpLabel? - ): CellBuilder = - component(Panel().apply { - add(mainComponent, BorderLayout.LINE_START) - contextHelpLabel?.let { add(it, BorderLayout.LINE_END) } - }) - class OKOptionAction(private val okAction: Action) : AbstractAction(ACTION_GENERATE) { init { putValue(DEFAULT_ACTION, java.lang.Boolean.TRUE) @@ -180,6 +177,8 @@ class PythonDialogWindow(val model: PythonTestsModel) : DialogWrapper(model.proj model.runtimeExceptionTestsBehaviour = runtimeExceptionTestsBehaviour } + loadStateFromModel(settings, model) + super.doOKAction() } diff --git a/utbot-intellij-python/src/main/kotlin/org/utbot/intellij/plugin/language/python/settings/Settings.kt b/utbot-intellij-python/src/main/kotlin/org/utbot/intellij/plugin/language/python/settings/Settings.kt new file mode 100644 index 0000000000..931a462a6e --- /dev/null +++ b/utbot-intellij-python/src/main/kotlin/org/utbot/intellij/plugin/language/python/settings/Settings.kt @@ -0,0 +1,17 @@ +package org.utbot.intellij.plugin.language.python.settings + +import org.utbot.intellij.plugin.language.python.PythonTestsModel +import org.utbot.intellij.plugin.settings.Settings + +fun loadStateFromModel(settings: Settings, model: PythonTestsModel) { + settings.loadState(fromGenerateTestsModel(model)) +} + +private fun fromGenerateTestsModel(model: PythonTestsModel): Settings.State { + return Settings.State( + sourceRootHistory = model.sourceRootHistory, + testFramework = model.testFramework, + generationTimeoutInMillis = model.timeout, + enableExperimentalLanguagesSupport = true, + ) +} From 3acc2c87eba99a1f636c83a092af20671ebba0f7 Mon Sep 17 00:00:00 2001 From: Vyacheslav Tamarin Date: Mon, 24 Apr 2023 23:59:54 -0700 Subject: [PATCH 2/3] Fix merge error with variable name --- .../language/python/PythonDialogWindow.kt | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/utbot-intellij-python/src/main/kotlin/org/utbot/intellij/plugin/language/python/PythonDialogWindow.kt b/utbot-intellij-python/src/main/kotlin/org/utbot/intellij/plugin/language/python/PythonDialogWindow.kt index a396daf36d..56fdf4cd40 100644 --- a/utbot-intellij-python/src/main/kotlin/org/utbot/intellij/plugin/language/python/PythonDialogWindow.kt +++ b/utbot-intellij-python/src/main/kotlin/org/utbot/intellij/plugin/language/python/PythonDialogWindow.kt @@ -1,8 +1,10 @@ package org.utbot.intellij.plugin.language.python import com.intellij.openapi.components.service -import com.intellij.openapi.project.Project -import com.intellij.openapi.ui.* +import com.intellij.openapi.ui.ComboBox +import com.intellij.openapi.ui.DialogPanel +import com.intellij.openapi.ui.DialogWrapper +import com.intellij.openapi.ui.ValidationInfo import com.intellij.ui.JBIntSpinner import com.intellij.ui.components.JBLabel import com.intellij.ui.components.JBScrollPane @@ -10,8 +12,8 @@ import com.intellij.ui.dsl.builder.Align import com.intellij.ui.dsl.builder.panel import com.intellij.util.ui.JBUI import com.intellij.util.ui.components.BorderLayoutPanel -import com.jetbrains.python.psi.* - +import com.jetbrains.python.psi.PyClass +import com.jetbrains.python.psi.PyFunction import org.utbot.framework.codegen.domain.ProjectType import org.utbot.framework.codegen.domain.TestFramework import org.utbot.intellij.plugin.language.python.settings.loadStateFromModel @@ -19,13 +21,15 @@ import org.utbot.intellij.plugin.language.python.table.UtPyClassItem import org.utbot.intellij.plugin.language.python.table.UtPyFunctionItem import org.utbot.intellij.plugin.language.python.table.UtPyMemberSelectionTable import org.utbot.intellij.plugin.language.python.table.UtPyTableItem - import org.utbot.intellij.plugin.settings.Settings -import java.util.concurrent.TimeUnit import org.utbot.intellij.plugin.ui.components.TestSourceDirectoryChooser import org.utbot.intellij.plugin.ui.utils.createTestFrameworksRenderer import java.awt.event.ActionEvent -import javax.swing.* +import java.util.concurrent.TimeUnit +import javax.swing.AbstractAction +import javax.swing.Action +import javax.swing.DefaultComboBoxModel +import javax.swing.JComponent private const val WILL_BE_INSTALLED_LABEL = " (will be installed)" private const val MINIMUM_TIMEOUT_VALUE_IN_SECONDS = 5 @@ -77,7 +81,7 @@ class PythonDialogWindow(val model: PythonTestsModel) : DialogWrapper(model.proj } row("Generate tests for:") {} row { - cell(JBScrollPane(functionsTable)).align(Align.FILL) + cell(JBScrollPane(pyElementsTable)).align(Align.FILL) } } From ea62001b34322ffd9d05eeedda7188505b26a3d5 Mon Sep 17 00:00:00 2001 From: Vyacheslav Tamarin Date: Wed, 26 Apr 2023 12:30:36 +0300 Subject: [PATCH 3/3] Fix description --- .../intellij/plugin/language/python/PythonDialogWindow.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utbot-intellij-python/src/main/kotlin/org/utbot/intellij/plugin/language/python/PythonDialogWindow.kt b/utbot-intellij-python/src/main/kotlin/org/utbot/intellij/plugin/language/python/PythonDialogWindow.kt index 56fdf4cd40..5f6cb1a165 100644 --- a/utbot-intellij-python/src/main/kotlin/org/utbot/intellij/plugin/language/python/PythonDialogWindow.kt +++ b/utbot-intellij-python/src/main/kotlin/org/utbot/intellij/plugin/language/python/PythonDialogWindow.kt @@ -75,9 +75,9 @@ class PythonDialogWindow(val model: PythonTestsModel) : DialogWrapper(model.proj row("Test generation timeout:") { cell(BorderLayoutPanel().apply { addToLeft(timeoutSpinnerForTotalTimeout) - addToRight(JBLabel("seconds per function")) + addToRight(JBLabel("seconds per module")) }) - contextHelp("Set the timeout for all test generation processes per function to complete.") + contextHelp("Set the timeout for all test generation processes per module to complete.") } row("Generate tests for:") {} row {