diff --git a/utbot-intellij-python/src/main/kotlin/org/utbot/intellij/plugin/python/PythonDialogProcessor.kt b/utbot-intellij-python/src/main/kotlin/org/utbot/intellij/plugin/python/PythonDialogProcessor.kt index 86eb6b4d56..a90e62650e 100644 --- a/utbot-intellij-python/src/main/kotlin/org/utbot/intellij/plugin/python/PythonDialogProcessor.kt +++ b/utbot-intellij-python/src/main/kotlin/org/utbot/intellij/plugin/python/PythonDialogProcessor.kt @@ -36,6 +36,7 @@ import org.utbot.python.TestFileInformation import org.utbot.python.framework.api.python.PythonClassId import org.utbot.python.framework.codegen.PythonCgLanguageAssistant import org.utbot.python.newtyping.mypy.dropInitFile +import org.utbot.python.utils.PythonVersionChecker import java.util.concurrent.ScheduledFuture import java.util.concurrent.TimeUnit import kotlin.io.path.Path @@ -124,16 +125,24 @@ object PythonDialogProcessor { title = "Python test generation error" ) } else { - val dialog = createDialog( - project, - elementsToShow, - focusedElement, - pythonPath, - ) - if (!dialog.showAndGet()) { - return + if (!PythonVersionChecker.checkPythonVersion(pythonPath)) { + showErrorDialogLater( + project, + message = "Please use Python 3.10 or newer", + title = "Python test generation error" + ) + } else { + val dialog = createDialog( + project, + elementsToShow, + focusedElement, + pythonPath, + ) + if (!dialog.showAndGet()) { + return + } + createTests(project, dialog.model) } - createTests(project, dialog.model) } } diff --git a/utbot-python/src/main/kotlin/org/utbot/python/utils/PythonVersionChecker.kt b/utbot-python/src/main/kotlin/org/utbot/python/utils/PythonVersionChecker.kt new file mode 100644 index 0000000000..a0e81e7a07 --- /dev/null +++ b/utbot-python/src/main/kotlin/org/utbot/python/utils/PythonVersionChecker.kt @@ -0,0 +1,22 @@ +package org.utbot.python.utils + +object PythonVersionChecker { + private val minimalPythonVersion = Triple(3, 10, 0) + + fun checkPythonVersion(pythonPath: String): Boolean { + try { + val version = runCommand(listOf( + pythonPath, + "-c", + "\"import sys; print('.'.join(map(str, sys.version_info[:3])))\"" + )) + if (version.exitValue == 0) { + val (major, minor, patch) = version.stdout.split(".") + return (major.toInt() >= minimalPythonVersion.first && minor.toInt() >= minimalPythonVersion.second && patch.toInt() >= minimalPythonVersion.third) + } + return false + } catch (_: Exception) { + return false + } + } +} \ No newline at end of file