Skip to content

Add LockFile to PythonDialogProcessor #1568 #1572

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 22, 2022
Merged
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 @@ -23,6 +23,7 @@ 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.ui.WarningTestsReportNotifier
import org.utbot.intellij.plugin.ui.utils.showErrorDialogLater
import org.utbot.intellij.plugin.ui.utils.testModules
Expand Down Expand Up @@ -114,61 +115,68 @@ object PythonDialogProcessor {
private fun createTests(project: Project, model: PythonTestsModel) {
ProgressManager.getInstance().run(object : Backgroundable(project, "Generate python tests") {
override fun run(indicator: ProgressIndicator) {
val pythonPath = model.srcModule.sdk?.homePath
if (pythonPath == null) {
showErrorDialogLater(
project,
message = "Couldn't find Python interpreter",
title = "Python test generation error"
)
return
}
val methods = findSelectedPythonMethods(model)
if (methods == null) {
showErrorDialogLater(
project,
message = "Couldn't parse file. Maybe it contains syntax error?",
title = "Python test generation error"
)
if (!LockFile.lock()) {
return
}
processTestGeneration(
pythonPath = pythonPath,
pythonFilePath = model.file.virtualFile.path,
pythonFileContent = getContentFromPyFile(model.file),
directoriesForSysPath = model.directoriesForSysPath,
currentPythonModule = model.currentPythonModule,
pythonMethods = methods,
containingClassName = model.containingClass?.name,
timeout = model.timeout,
testFramework = model.testFramework,
timeoutForRun = model.timeoutForRun,
visitOnlySpecifiedSource = model.visitOnlySpecifiedSource,
isCanceled = { indicator.isCanceled },
checkingRequirementsAction = { indicator.text = "Checking requirements" },
requirementsAreNotInstalledAction = {
askAndInstallRequirementsLater(model.project, pythonPath)
PythonTestGenerationProcessor.MissingRequirementsActionResult.NOT_INSTALLED
},
startedLoadingPythonTypesAction = { indicator.text = "Loading information about Python types" },
startedTestGenerationAction = { indicator.text = "Generating tests" },
notGeneratedTestsAction = {
try {
val pythonPath = model.srcModule.sdk?.homePath
if (pythonPath == null) {
showErrorDialogLater(
project,
message = "Couldn't find Python interpreter",
title = "Python test generation error"
)
return
}
val methods = findSelectedPythonMethods(model)
if (methods == null) {
showErrorDialogLater(
project,
message = "Cannot create tests for the following functions: " + it.joinToString(),
message = "Couldn't parse file. Maybe it contains syntax error?",
title = "Python test generation error"
)
},
writeTestTextToFile = { generatedCode ->
writeGeneratedCodeToPsiDocument(generatedCode, model)
},
processMypyWarnings = {
val message = it.fold(StringBuilder()) { acc, line -> acc.appendHtmlLine(line) }
WarningTestsReportNotifier.notify(message.toString())
},
startedCleaningAction = { indicator.text = "Cleaning up..." },
pythonRunRoot = Path(model.testSourceRootPath)
)
return
}
processTestGeneration(
pythonPath = pythonPath,
pythonFilePath = model.file.virtualFile.path,
pythonFileContent = getContentFromPyFile(model.file),
directoriesForSysPath = model.directoriesForSysPath,
currentPythonModule = model.currentPythonModule,
pythonMethods = methods,
containingClassName = model.containingClass?.name,
timeout = model.timeout,
testFramework = model.testFramework,
timeoutForRun = model.timeoutForRun,
visitOnlySpecifiedSource = model.visitOnlySpecifiedSource,
isCanceled = { indicator.isCanceled },
checkingRequirementsAction = { indicator.text = "Checking requirements" },
requirementsAreNotInstalledAction = {
askAndInstallRequirementsLater(model.project, pythonPath)
PythonTestGenerationProcessor.MissingRequirementsActionResult.NOT_INSTALLED
},
startedLoadingPythonTypesAction = { indicator.text = "Loading information about Python types" },
startedTestGenerationAction = { indicator.text = "Generating tests" },
notGeneratedTestsAction = {
showErrorDialogLater(
project,
message = "Cannot create tests for the following functions: " + it.joinToString(),
title = "Python test generation error"
)
},
writeTestTextToFile = { generatedCode ->
writeGeneratedCodeToPsiDocument(generatedCode, model)
},
processMypyWarnings = {
val message = it.fold(StringBuilder()) { acc, line -> acc.appendHtmlLine(line) }
WarningTestsReportNotifier.notify(message.toString())
},
startedCleaningAction = { indicator.text = "Cleaning up..." },
pythonRunRoot = Path(model.testSourceRootPath)
)
} finally {
LockFile.unlock()
}
}
})
}
Expand Down