From 8a9a4a5eb8443ad48b4ed7273b6870fa78ee9a75 Mon Sep 17 00:00:00 2001 From: "Vladimir.Koshelev" Date: Mon, 29 Sep 2025 16:08:23 +0200 Subject: [PATCH] [python] fix running intellij.python.community.services.systemPython GitOrigin-RevId: 166a0991c7b5032a63efebad1eb078cc15540b46 --- ...python.community.services.systemPython.iml | 2 - .../testResources/META-INF/plugin.xml | 1 - ....community.services.systemPython._test.xml | 7 ++++ .../SystemPythonServiceShowCaseTest.kt | 39 ++++++++++++------- .../env/systemPython/impl/EnvProviderTest.kt | 16 +++++--- 5 files changed, 41 insertions(+), 24 deletions(-) diff --git a/python/services/system-python/intellij.python.community.services.systemPython.iml b/python/services/system-python/intellij.python.community.services.systemPython.iml index a665ee86be8d..c401fd5a7327 100644 --- a/python/services/system-python/intellij.python.community.services.systemPython.iml +++ b/python/services/system-python/intellij.python.community.services.systemPython.iml @@ -31,8 +31,6 @@ - - diff --git a/python/services/system-python/testResources/META-INF/plugin.xml b/python/services/system-python/testResources/META-INF/plugin.xml index 02f5860da78e..e96a300b6bff 100644 --- a/python/services/system-python/testResources/META-INF/plugin.xml +++ b/python/services/system-python/testResources/META-INF/plugin.xml @@ -1,5 +1,4 @@ - pycharm.systemPython.tests diff --git a/python/services/system-python/testResources/intellij.python.community.services.systemPython._test.xml b/python/services/system-python/testResources/intellij.python.community.services.systemPython._test.xml index e49a89f5a534..db259d0ef34a 100644 --- a/python/services/system-python/testResources/intellij.python.community.services.systemPython._test.xml +++ b/python/services/system-python/testResources/intellij.python.community.services.systemPython._test.xml @@ -4,4 +4,11 @@ + + + + + + + \ No newline at end of file diff --git a/python/services/system-python/tests/com/intellij/python/junit5Tests/env/systemPython/SystemPythonServiceShowCaseTest.kt b/python/services/system-python/tests/com/intellij/python/junit5Tests/env/systemPython/SystemPythonServiceShowCaseTest.kt index fa6b77838be8..a7a9f080bd59 100644 --- a/python/services/system-python/tests/com/intellij/python/junit5Tests/env/systemPython/SystemPythonServiceShowCaseTest.kt +++ b/python/services/system-python/tests/com/intellij/python/junit5Tests/env/systemPython/SystemPythonServiceShowCaseTest.kt @@ -28,9 +28,6 @@ import com.jetbrains.python.errorProcessing.MessageError import com.jetbrains.python.getOrThrow import com.jetbrains.python.sdk.flavors.PythonSdkFlavor import com.jetbrains.python.venvReader.VirtualEnvReader -import io.mockk.coEvery -import io.mockk.coVerify -import io.mockk.mockk import kotlinx.coroutines.async import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.Matchers.hasItem @@ -38,6 +35,10 @@ import org.hamcrest.Matchers.not import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.Test import org.junit.jupiter.api.io.TempDir +import com.intellij.platform.eel.EelApi +import com.intellij.python.community.services.shared.UICustomization +import com.jetbrains.python.PythonBinary +import com.jetbrains.python.errorProcessing.PyResult import java.nio.file.Path import kotlin.io.path.deleteExisting import kotlin.io.path.pathString @@ -56,7 +57,7 @@ class SystemPythonServiceShowCaseTest { val output = async { (if (systemPython.languageLevel.isPy3K) process.stdout else process.stderr).readWholeText() } - Assertions.assertEquals(0, process.exitCode.await(), "Wrong exit code") + Assertions.assertTrue(process.exitCode.await() == 0) val versionString = PythonSdkFlavor.getLanguageLevelFromVersionStringStaticSafe(output.await())!! Assertions.assertEquals(systemPython.languageLevel, versionString, "Wrong version") } @@ -91,32 +92,40 @@ class SystemPythonServiceShowCaseTest { @Test fun testRefresh(@TestDisposable disposable: Disposable): Unit = timeoutRunBlocking(10.minutes) { - val mockProvider = mockk() - coEvery { mockProvider.findSystemPythons(any()) } returns Result.failure(MessageError("...")) - coEvery { mockProvider.uiCustomization } returns null + val provider = CountingTestProvider(Result.failure(MessageError("..."))) val sut = SystemPythonService() + // Warm up cache before registering test provider sut.findSystemPythons() - ApplicationManager.getApplication().registerExtension(SystemPythonProvider.EP, mockProvider, disposable) + ApplicationManager.getApplication().registerExtension(SystemPythonProvider.EP, provider, disposable) repeat(10) { sut.findSystemPythons() } - coVerify(exactly = 0) { mockProvider.findSystemPythons(any()) } + Assertions.assertTrue(provider.calls == 0, "Provider should not be called while cache is valid") sut.findSystemPythons(forceRefresh = true) - coVerify(atLeast = 1) { mockProvider.findSystemPythons(any()) } + Assertions.assertTrue(provider.calls >= 1, "Provider should be called after force refresh") } @RegistryKey("python.system.refresh.minutes", "0") @Test fun testDisableCache(@TestDisposable disposable: Disposable): Unit = timeoutRunBlocking(10.minutes) { val timesToRepeat = 5 - val mockProvider = mockk() - coEvery { mockProvider.findSystemPythons(any()) } returns Result.success(emptySet()) - coEvery { mockProvider.uiCustomization } returns null + val provider = CountingTestProvider(Result.success(emptySet())) val sut = SystemPythonServiceImpl(this) - ApplicationManager.getApplication().registerExtension(SystemPythonProvider.EP, mockProvider, disposable) + ApplicationManager.getApplication().registerExtension(SystemPythonProvider.EP, provider, disposable) repeat(timesToRepeat) { sut.findSystemPythons() } - coVerify(exactly = timesToRepeat) { mockProvider.findSystemPythons(any()) } + Assertions.assertTrue(provider.calls == timesToRepeat) + } + + private class CountingTestProvider( + private val result: PyResult>, + override val uiCustomization: UICustomization? = null, + ) : SystemPythonProvider { + var calls: Int = 0 + override suspend fun findSystemPythons(eelApi: EelApi): PyResult> { + calls++ + return result + } } } \ No newline at end of file diff --git a/python/services/system-python/tests/com/intellij/python/junit5Tests/env/systemPython/impl/EnvProviderTest.kt b/python/services/system-python/tests/com/intellij/python/junit5Tests/env/systemPython/impl/EnvProviderTest.kt index 2693b4833ddf..7eee6f4b7331 100644 --- a/python/services/system-python/tests/com/intellij/python/junit5Tests/env/systemPython/impl/EnvProviderTest.kt +++ b/python/services/system-python/tests/com/intellij/python/junit5Tests/env/systemPython/impl/EnvProviderTest.kt @@ -15,14 +15,13 @@ import com.intellij.testFramework.registerExtension import com.jetbrains.python.PythonBinary import com.jetbrains.python.Result import com.jetbrains.python.getOrThrow -import io.mockk.coEvery -import io.mockk.mockk import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.Matchers import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertTrue import org.junit.jupiter.api.Test import org.junit.jupiter.api.io.TempDir +import com.intellij.platform.eel.EelApi import java.nio.file.Path @PyEnvTestCase @@ -50,11 +49,16 @@ class EnvProviderTest { ): Unit = timeoutRunBlocking { val venvPython = createVenv(python, venvDir).getOrThrow() val ui = UICustomization("myui") - val provider = mockk() - coEvery { provider.findSystemPythons(any()) } returns Result.success(setOf(venvPython)) - coEvery { provider.uiCustomization } returns ui + val provider = InlineTestProvider(setOf(venvPython), ui) ApplicationManager.getApplication().registerExtension(SystemPythonProvider.EP, provider, disposable) val python = SystemPythonService().findSystemPythons(forceRefresh = true).first { it.pythonBinary == venvPython } - assertEquals(ui, python.ui, "Wrong UI") + assertTrue(ui == python.ui, "Wrong UI") + } + + private class InlineTestProvider( + private val pythons: Set, + override val uiCustomization: UICustomization? + ) : SystemPythonProvider { + override suspend fun findSystemPythons(eelApi: EelApi) = Result.success(pythons) } } \ No newline at end of file