PY-54269 Remove two confusing tests in PySdkPathsTest replicating the internals of adding user interpreter paths

It seems that the original problem is no longer relevant now that
editable and regular SDKs don't share additional data.

See 126342bee2fdb1ec38c8b03623450dd70f847b7b.

The tests relied on the fact that the previous logic of setting
"transferred paths" might have stored them in additional data
of an "editable" copy of an SDK not actually specified as an SDK
of any module (hence SDK additional data was updated but not actual
project roots). See how PyTransferredSdkRootsKt.setPathsToTransfer
is called in `PythonSdkUpdater.updateSdkPaths`.

The new mechanism that also considers `sys.path` entries for
editable cross-module dependencies doesn't have this side effect,
and breaks the tests.

Namely, depending on whether `ProjectJdkTable.updateJdk(sdk, editableSdk)`
or `ProjectSdksModel.apply()` is called between the introspection
of the editable and the actual SDK, copying the additional data of
the first to the second, existing "tranferred roots" might get out of
sync with actually configured source roots for the given SDK,
affecting setting and removing them on `sys.path` change.

GitOrigin-RevId: 3e3345d056f0a2671942bc121188d650b3e4c99e
This commit is contained in:
Mikhail Golubev
2025-02-04 22:07:19 +00:00
committed by intellij-monorepo-bot
parent 3d1f1cf094
commit 003f4e9702
@@ -138,122 +138,6 @@ class PySdkPathsTest {
checkRoots(simpleSdk, module, listOf(moduleRoot), emptyList())
}
@Test
fun userAddedViaEditableSdkWithSharedData() {
// emulates com.jetbrains.python.configuration.PythonSdkDetailsDialog.ShowPathButton.actionPerformed
val (module, moduleRoot) = createModule()
val userAddedPath = createSubdir(moduleRoot)
mockPythonPluginDisposable()
val pythonVersion = LanguageLevel.getDefault().toPythonVersion()
val sdk = PythonMockSdk.create(pythonVersion)
registerSdk(sdk)
module.pythonSdk = sdk
IndexingTestUtil.waitUntilIndexesAreReady(module.project)
sdk.putUserData(PythonSdkType.MOCK_PY_VERSION_KEY, pythonVersion)
val projectSdksModel = PyConfigurableInterpreterList.getInstance(projectModel.project).model
val editableSdk = projectSdksModel.findSdk(sdk.name)
editableSdk!!.putUserData(PythonSdkType.MOCK_PY_VERSION_KEY, pythonVersion)
// --- ADD path ---
editableSdk.sdkModificator.apply {
(sdkAdditionalData as PythonSdkAdditionalData).setAddedPathsFromVirtualFiles(setOf(userAddedPath))
runWriteActionAndWait {
commitChanges()
projectSdksModel.apply()
}
}
updateSdkPaths(editableSdk)
updateSdkPaths(sdk)
checkRoots(sdk, module, listOf(moduleRoot, userAddedPath), emptyList())
// --- REMOVE path ---
editableSdk.sdkModificator.apply {
(sdkAdditionalData as PythonSdkAdditionalData).setAddedPathsFromVirtualFiles(emptySet())
runWriteActionAndWait {
commitChanges()
projectSdksModel.apply()
}
}
updateSdkPaths(editableSdk)
updateSdkPaths(sdk)
checkRoots(sdk, module, listOf(moduleRoot), emptyList())
runWriteActionAndWait { ProjectJdkTable.getInstance().removeJdk(sdk) }
}
@Test
fun userAddedViaEditableSdkWithoutSharedData() {
// emulates com.jetbrains.python.configuration.PythonSdkDetailsDialog.ShowPathButton.actionPerformed
val (module, moduleRoot) = createModule()
val sdkPath = createVenvStructureInModule(moduleRoot).path
val userAddedPath = createSubdir(moduleRoot)
val pythonVersion = LanguageLevel.getDefault().toPythonVersion()
val sdk = ProjectJdkTable.getInstance().createSdk("Mock ${PyNames.PYTHON_SDK_ID_NAME} $pythonVersion", PythonSdkType.getInstance())
sdk.sdkModificator.apply {
versionString = pythonVersion
homePath = "$sdkPath/bin/python"
runWriteActionAndWait { commitChanges() }
}
registerSdk(sdk)
module.pythonSdk = sdk
IndexingTestUtil.waitUntilIndexesAreReady(module.project)
sdk.putUserData(PythonSdkType.MOCK_PY_VERSION_KEY, pythonVersion)
val projectSdksModel = PyConfigurableInterpreterList.getInstance(projectModel.project).model
val editableSdk = projectSdksModel.findSdk(sdk.name)
editableSdk!!.putUserData(PythonSdkType.MOCK_PY_VERSION_KEY, pythonVersion)
// --- ADD path ---
editableSdk.sdkModificator.apply {
assertThat(sdkAdditionalData).isNull()
mockPythonPluginDisposable()
sdkAdditionalData = PythonSdkAdditionalData().apply {
setAddedPathsFromVirtualFiles(setOf(userAddedPath))
}
runWriteActionAndWait {
commitChanges()
ProjectJdkTable.getInstance().updateJdk(sdk, editableSdk)
}
}
updateSdkPaths(editableSdk)
updateSdkPaths(sdk)
checkRoots(sdk, module, listOf(moduleRoot, userAddedPath), emptyList())
// --- REMOVE path ---
editableSdk.sdkModificator.apply {
(sdkAdditionalData as PythonSdkAdditionalData).setAddedPathsFromVirtualFiles(emptySet())
runWriteActionAndWait {
commitChanges()
projectSdksModel.apply()
}
}
updateSdkPaths(editableSdk)
updateSdkPaths(sdk) // after updateJdk call editableSdk and sdk share the same data
checkRoots(sdk, module, listOf(moduleRoot), emptyList())
runWriteActionAndWait { ProjectJdkTable.getInstance().removeJdk(sdk) }
}
@Test
fun sysPathEntryInModuleAndSdkInModuleButEntryNotInSdk() {
val (module, moduleRoot) = createModule()