Skip to content

Commit 24296b8

Browse files
tamarinvs19denis-fokin
authored andcommitted
Add LockFile to PythonDialogProcessor #1568 (#1572)
(cherry picked from commit 435787b)
1 parent 4cb44d2 commit 24296b8

File tree

1 file changed

+57
-49
lines changed

1 file changed

+57
-49
lines changed

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

Lines changed: 57 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import org.jetbrains.kotlin.idea.util.projectStructure.sdk
2323
import org.utbot.common.PathUtil.toPath
2424
import org.utbot.common.appendHtmlLine
2525
import org.utbot.framework.UtSettings
26+
import org.utbot.framework.plugin.api.util.LockFile
2627
import org.utbot.intellij.plugin.ui.WarningTestsReportNotifier
2728
import org.utbot.intellij.plugin.ui.utils.showErrorDialogLater
2829
import org.utbot.intellij.plugin.ui.utils.testModules
@@ -114,61 +115,68 @@ object PythonDialogProcessor {
114115
private fun createTests(project: Project, model: PythonTestsModel) {
115116
ProgressManager.getInstance().run(object : Backgroundable(project, "Generate python tests") {
116117
override fun run(indicator: ProgressIndicator) {
117-
val pythonPath = model.srcModule.sdk?.homePath
118-
if (pythonPath == null) {
119-
showErrorDialogLater(
120-
project,
121-
message = "Couldn't find Python interpreter",
122-
title = "Python test generation error"
123-
)
124-
return
125-
}
126-
val methods = findSelectedPythonMethods(model)
127-
if (methods == null) {
128-
showErrorDialogLater(
129-
project,
130-
message = "Couldn't parse file. Maybe it contains syntax error?",
131-
title = "Python test generation error"
132-
)
118+
if (!LockFile.lock()) {
133119
return
134120
}
135-
processTestGeneration(
136-
pythonPath = pythonPath,
137-
pythonFilePath = model.file.virtualFile.path,
138-
pythonFileContent = getContentFromPyFile(model.file),
139-
directoriesForSysPath = model.directoriesForSysPath,
140-
currentPythonModule = model.currentPythonModule,
141-
pythonMethods = methods,
142-
containingClassName = model.containingClass?.name,
143-
timeout = model.timeout,
144-
testFramework = model.testFramework,
145-
timeoutForRun = model.timeoutForRun,
146-
visitOnlySpecifiedSource = model.visitOnlySpecifiedSource,
147-
isCanceled = { indicator.isCanceled },
148-
checkingRequirementsAction = { indicator.text = "Checking requirements" },
149-
requirementsAreNotInstalledAction = {
150-
askAndInstallRequirementsLater(model.project, pythonPath)
151-
PythonTestGenerationProcessor.MissingRequirementsActionResult.NOT_INSTALLED
152-
},
153-
startedLoadingPythonTypesAction = { indicator.text = "Loading information about Python types" },
154-
startedTestGenerationAction = { indicator.text = "Generating tests" },
155-
notGeneratedTestsAction = {
121+
try {
122+
val pythonPath = model.srcModule.sdk?.homePath
123+
if (pythonPath == null) {
124+
showErrorDialogLater(
125+
project,
126+
message = "Couldn't find Python interpreter",
127+
title = "Python test generation error"
128+
)
129+
return
130+
}
131+
val methods = findSelectedPythonMethods(model)
132+
if (methods == null) {
156133
showErrorDialogLater(
157134
project,
158-
message = "Cannot create tests for the following functions: " + it.joinToString(),
135+
message = "Couldn't parse file. Maybe it contains syntax error?",
159136
title = "Python test generation error"
160137
)
161-
},
162-
writeTestTextToFile = { generatedCode ->
163-
writeGeneratedCodeToPsiDocument(generatedCode, model)
164-
},
165-
processMypyWarnings = {
166-
val message = it.fold(StringBuilder()) { acc, line -> acc.appendHtmlLine(line) }
167-
WarningTestsReportNotifier.notify(message.toString())
168-
},
169-
startedCleaningAction = { indicator.text = "Cleaning up..." },
170-
pythonRunRoot = Path(model.testSourceRootPath)
171-
)
138+
return
139+
}
140+
processTestGeneration(
141+
pythonPath = pythonPath,
142+
pythonFilePath = model.file.virtualFile.path,
143+
pythonFileContent = getContentFromPyFile(model.file),
144+
directoriesForSysPath = model.directoriesForSysPath,
145+
currentPythonModule = model.currentPythonModule,
146+
pythonMethods = methods,
147+
containingClassName = model.containingClass?.name,
148+
timeout = model.timeout,
149+
testFramework = model.testFramework,
150+
timeoutForRun = model.timeoutForRun,
151+
visitOnlySpecifiedSource = model.visitOnlySpecifiedSource,
152+
isCanceled = { indicator.isCanceled },
153+
checkingRequirementsAction = { indicator.text = "Checking requirements" },
154+
requirementsAreNotInstalledAction = {
155+
askAndInstallRequirementsLater(model.project, pythonPath)
156+
PythonTestGenerationProcessor.MissingRequirementsActionResult.NOT_INSTALLED
157+
},
158+
startedLoadingPythonTypesAction = { indicator.text = "Loading information about Python types" },
159+
startedTestGenerationAction = { indicator.text = "Generating tests" },
160+
notGeneratedTestsAction = {
161+
showErrorDialogLater(
162+
project,
163+
message = "Cannot create tests for the following functions: " + it.joinToString(),
164+
title = "Python test generation error"
165+
)
166+
},
167+
writeTestTextToFile = { generatedCode ->
168+
writeGeneratedCodeToPsiDocument(generatedCode, model)
169+
},
170+
processMypyWarnings = {
171+
val message = it.fold(StringBuilder()) { acc, line -> acc.appendHtmlLine(line) }
172+
WarningTestsReportNotifier.notify(message.toString())
173+
},
174+
startedCleaningAction = { indicator.text = "Cleaning up..." },
175+
pythonRunRoot = Path(model.testSourceRootPath)
176+
)
177+
} finally {
178+
LockFile.unlock()
179+
}
172180
}
173181
})
174182
}

0 commit comments

Comments
 (0)