Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c03c24b

Browse files
Remember selections in python dialog (#2184)
1 parent 169ad42 commit c03c24b

File tree

3 files changed

+65
-42
lines changed

3 files changed

+65
-42
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package org.utbot.intellij.plugin.language.python
33
import com.intellij.codeInsight.CodeInsightUtil
44
import com.intellij.openapi.application.invokeLater
55
import com.intellij.openapi.application.readAction
6+
import com.intellij.openapi.components.service
67
import com.intellij.openapi.editor.Editor
78
import com.intellij.openapi.fileEditor.FileDocumentManager
89
import com.intellij.openapi.module.Module
@@ -31,8 +32,8 @@ import org.jetbrains.kotlin.idea.util.projectStructure.sdk
3132
import org.jetbrains.kotlin.j2k.getContainingClass
3233
import org.utbot.common.PathUtil.toPath
3334
import org.utbot.common.appendHtmlLine
34-
import org.utbot.framework.UtSettings
3535
import org.utbot.framework.plugin.api.util.LockFile
36+
import org.utbot.intellij.plugin.settings.Settings
3637
import org.utbot.intellij.plugin.ui.WarningTestsReportNotifier
3738
import org.utbot.intellij.plugin.ui.utils.showErrorDialogLater
3839
import org.utbot.intellij.plugin.ui.utils.testModules
@@ -108,7 +109,7 @@ object PythonDialogProcessor {
108109
testModules,
109110
elementsToShow,
110111
focusedElements,
111-
UtSettings.utBotGenerationTimeoutInMillis,
112+
project.service<Settings>().generationTimeoutInMillis,
112113
DEFAULT_TIMEOUT_FOR_RUN_IN_MILLIS,
113114
cgLanguageAssistant = PythonCgLanguageAssistant,
114115
pythonPath = pythonPath,

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

Lines changed: 45 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,38 @@
11
package org.utbot.intellij.plugin.language.python
22

33
import com.intellij.openapi.components.service
4-
import com.intellij.openapi.project.Project
5-
import com.intellij.openapi.ui.*
6-
import com.intellij.ui.ContextHelpLabel
4+
import com.intellij.openapi.ui.ComboBox
5+
import com.intellij.openapi.ui.DialogPanel
6+
import com.intellij.openapi.ui.DialogWrapper
7+
import com.intellij.openapi.ui.ValidationInfo
78
import com.intellij.ui.JBIntSpinner
8-
import com.intellij.ui.components.Panel
9-
import com.intellij.ui.layout.CellBuilder
10-
import com.intellij.ui.layout.Row
11-
import com.intellij.ui.layout.panel
9+
import com.intellij.ui.components.JBLabel
10+
import com.intellij.ui.components.JBScrollPane
11+
import com.intellij.ui.dsl.builder.Align
12+
import com.intellij.ui.dsl.builder.panel
1213
import com.intellij.util.ui.JBUI
13-
import com.jetbrains.python.psi.*
14-
import org.utbot.framework.UtSettings
14+
import com.intellij.util.ui.components.BorderLayoutPanel
15+
import com.jetbrains.python.psi.PyClass
16+
import com.jetbrains.python.psi.PyFunction
1517
import org.utbot.framework.codegen.domain.ProjectType
18+
import org.utbot.framework.codegen.domain.TestFramework
19+
import org.utbot.intellij.plugin.language.python.settings.loadStateFromModel
1620
import org.utbot.intellij.plugin.language.python.table.UtPyClassItem
1721
import org.utbot.intellij.plugin.language.python.table.UtPyFunctionItem
1822
import org.utbot.intellij.plugin.language.python.table.UtPyMemberSelectionTable
1923
import org.utbot.intellij.plugin.language.python.table.UtPyTableItem
2024
import org.utbot.intellij.plugin.settings.Settings
21-
import java.awt.BorderLayout
22-
import java.util.concurrent.TimeUnit
2325
import org.utbot.intellij.plugin.ui.components.TestSourceDirectoryChooser
2426
import org.utbot.intellij.plugin.ui.utils.createTestFrameworksRenderer
2527
import java.awt.event.ActionEvent
26-
import javax.swing.*
27-
28+
import java.util.concurrent.TimeUnit
29+
import javax.swing.AbstractAction
30+
import javax.swing.Action
31+
import javax.swing.DefaultComboBoxModel
32+
import javax.swing.JComponent
2833

2934
private const val WILL_BE_INSTALLED_LABEL = " (will be installed)"
30-
private const val MINIMUM_TIMEOUT_VALUE_IN_SECONDS = 1
35+
private const val MINIMUM_TIMEOUT_VALUE_IN_SECONDS = 5
3136
private const val STEP_TIMEOUT_VALUE_IN_SECONDS = 5
3237
private const val ACTION_GENERATE = "Generate Tests"
3338

@@ -37,7 +42,7 @@ class PythonDialogWindow(val model: PythonTestsModel) : DialogWrapper(model.proj
3742
private val testSourceFolderField = TestSourceDirectoryChooser(model)
3843
private val timeoutSpinnerForTotalTimeout =
3944
JBIntSpinner(
40-
TimeUnit.MILLISECONDS.toSeconds(UtSettings.utBotGenerationTimeoutInMillis).toInt(),
45+
TimeUnit.MILLISECONDS.toSeconds(model.timeout).toInt(),
4146
MINIMUM_TIMEOUT_VALUE_IN_SECONDS,
4247
Int.MAX_VALUE,
4348
STEP_TIMEOUT_VALUE_IN_SECONDS
@@ -46,6 +51,7 @@ class PythonDialogWindow(val model: PythonTestsModel) : DialogWrapper(model.proj
4651
ComboBox(DefaultComboBoxModel(model.cgLanguageAssistant.getLanguageTestFrameworkManager().testFrameworks.toTypedArray()))
4752

4853
private lateinit var panel: DialogPanel
54+
private lateinit var currentFrameworkItem: TestFramework
4955

5056
init {
5157
title = "Generate Tests with UnitTestBot"
@@ -59,36 +65,42 @@ class PythonDialogWindow(val model: PythonTestsModel) : DialogWrapper(model.proj
5965
}
6066

6167
override fun createCenterPanel(): JComponent {
62-
6368
panel = panel {
6469
row("Test sources root:") {
65-
component(testSourceFolderField)
70+
cell(testSourceFolderField).align(Align.FILL)
6671
}
67-
row("Test framework:") {
68-
makePanelWithHelpTooltip(
69-
testFrameworks,
70-
null
71-
)
72+
row("Testing framework:") {
73+
cell(testFrameworks)
7274
}
73-
row("Timeout for all selected functions:") {
74-
cell {
75-
component(timeoutSpinnerForTotalTimeout)
76-
label("seconds")
77-
component(ContextHelpLabel.create("Set the timeout for all test generation processes."))
78-
}
75+
row("Test generation timeout:") {
76+
cell(BorderLayoutPanel().apply {
77+
addToLeft(timeoutSpinnerForTotalTimeout)
78+
addToRight(JBLabel("seconds per module"))
79+
})
80+
contextHelp("Set the timeout for all test generation processes per module to complete.")
7981
}
80-
row("Generate test methods for:") {}
82+
row("Generate tests for:") {}
8183
row {
82-
scrollPane(pyElementsTable)
84+
cell(JBScrollPane(pyElementsTable)).align(Align.FILL)
8385
}
8486
}
8587

88+
initDefaultValues()
8689
updatePyElementsTable()
87-
updateTestFrameworksList()
8890
return panel
8991
}
9092

93+
private fun initDefaultValues() {
94+
val settings = model.project.service<Settings>()
95+
96+
val installedTestFramework = TestFramework.allItems.singleOrNull { it.isInstalled }
97+
currentFrameworkItem = installedTestFramework ?: settings.testFramework
98+
99+
updateTestFrameworksList()
100+
}
101+
91102
private fun updateTestFrameworksList() {
103+
testFrameworks.item = currentFrameworkItem
92104
testFrameworks.renderer = createTestFrameworksRenderer(WILL_BE_INSTALLED_LABEL)
93105
}
94106

@@ -126,15 +138,6 @@ class PythonDialogWindow(val model: PythonTestsModel) : DialogWrapper(model.proj
126138

127139
private fun checkMembers(members: Collection<UtPyTableItem>) = members.forEach { it.isChecked = true }
128140

129-
private fun Row.makePanelWithHelpTooltip(
130-
mainComponent: JComponent,
131-
contextHelpLabel: ContextHelpLabel?
132-
): CellBuilder<JPanel> =
133-
component(Panel().apply {
134-
add(mainComponent, BorderLayout.LINE_START)
135-
contextHelpLabel?.let { add(it, BorderLayout.LINE_END) }
136-
})
137-
138141
class OKOptionAction(private val okAction: Action) : AbstractAction(ACTION_GENERATE) {
139142
init {
140143
putValue(DEFAULT_ACTION, java.lang.Boolean.TRUE)
@@ -162,6 +165,8 @@ class PythonDialogWindow(val model: PythonTestsModel) : DialogWrapper(model.proj
162165
model.runtimeExceptionTestsBehaviour = runtimeExceptionTestsBehaviour
163166
}
164167

168+
loadStateFromModel(settings, model)
169+
165170
super.doOKAction()
166171
}
167172

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package org.utbot.intellij.plugin.language.python.settings
2+
3+
import org.utbot.intellij.plugin.language.python.PythonTestsModel
4+
import org.utbot.intellij.plugin.settings.Settings
5+
6+
fun loadStateFromModel(settings: Settings, model: PythonTestsModel) {
7+
settings.loadState(fromGenerateTestsModel(model))
8+
}
9+
10+
private fun fromGenerateTestsModel(model: PythonTestsModel): Settings.State {
11+
return Settings.State(
12+
sourceRootHistory = model.sourceRootHistory,
13+
testFramework = model.testFramework,
14+
generationTimeoutInMillis = model.timeout,
15+
enableExperimentalLanguagesSupport = true,
16+
)
17+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /