From a46488287121d9cfc4c0df8647020a4543ff68e7 Mon Sep 17 00:00:00 2001 From: Alexander Koshevoy Date: Tue, 14 Jun 2022 13:16:20 +0200 Subject: [PATCH] Add test for PydevConsoleRunnerUtil.kt GitOrigin-RevId: bff71722b755967af0cd97014d47f17136a4782e --- .../console/PydevConsoleRunnerUtilTest.kt | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 python/testSrc/com/jetbrains/python/console/PydevConsoleRunnerUtilTest.kt diff --git a/python/testSrc/com/jetbrains/python/console/PydevConsoleRunnerUtilTest.kt b/python/testSrc/com/jetbrains/python/console/PydevConsoleRunnerUtilTest.kt new file mode 100644 index 000000000000..acbd1a20ba9b --- /dev/null +++ b/python/testSrc/com/jetbrains/python/console/PydevConsoleRunnerUtilTest.kt @@ -0,0 +1,74 @@ +// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +package com.jetbrains.python.console + +import com.intellij.execution.Platform +import com.intellij.execution.target.* +import com.intellij.execution.target.value.TargetValue +import com.intellij.execution.target.value.constant +import com.intellij.openapi.progress.ProgressIndicator +import org.assertj.core.api.SoftAssertions +import org.junit.Test + +class PydevConsoleRunnerUtilTest { + @Test + fun `test constructPyPathAndWorkingDirCommand`() { + val dummyRequest = DummyTargetEnvironmentRequest() + val dummyEnvironment = DummyTargetEnvironment(dummyRequest) + + val pythonPath = mutableListOf(constant("/home/foo/bar's baz")) + val workingDir = "/home/foo/bar\\qux" + + val consoleStartCommand = PydevConsoleRunnerImpl.CONSOLE_START_COMMAND + + SoftAssertions.assertSoftly { softly -> + softly + .assertThat(constructPyPathAndWorkingDirCommand(pythonPath, workingDir, consoleStartCommand).apply(dummyEnvironment)) + .isEqualTo( + """|import sys; print('Python %s on %s' % (sys.version, sys.platform)) + |sys.path.extend(['/home/foo/bar\'s baz', '/home/foo/bar\\qux']) + |""".trimMargin() + ) + .describedAs("Constructs the command that adds the python paths and working directory to `sys.path`") + } + } + + private class DummyTargetEnvironmentRequest : TargetEnvironmentRequest { + override val targetPlatform: TargetPlatform = TargetPlatform(Platform.UNIX) + + override val configuration: TargetEnvironmentConfiguration? = null + + override var projectPathOnTarget: String = "" + + @Deprecated("Use uploadVolumes") + override val defaultVolume: TargetEnvironmentRequest.Volume + get() = throw UnsupportedOperationException() + + @Deprecated("Use uploadVolumes") + override fun createUploadRoot(remoteRootPath: String?, temporary: Boolean): TargetEnvironmentRequest.Volume = + throw UnsupportedOperationException() + + @Deprecated("Use downloadVolumes") + override fun createDownloadRoot(remoteRootPath: String?): TargetEnvironmentRequest.DownloadableVolume = + throw UnsupportedOperationException() + + @Deprecated("Use targetPortBindings") + override fun bindTargetPort(targetPort: Int): TargetValue = throw UnsupportedOperationException() + + @Deprecated("Use localPortBindings") + override fun bindLocalPort(localPort: Int): TargetValue = throw UnsupportedOperationException() + + override fun prepareEnvironment(progressIndicator: TargetProgressIndicator): TargetEnvironment = DummyTargetEnvironment(this) + + override fun onEnvironmentPrepared(callback: (environment: TargetEnvironment, progressIndicator: TargetProgressIndicator) -> Unit) = + throw UnsupportedOperationException() + } + + private class DummyTargetEnvironment(request: DummyTargetEnvironmentRequest) : TargetEnvironment(request) { + override fun createProcess(commandLine: TargetedCommandLine, indicator: ProgressIndicator): Process = + throw UnsupportedOperationException() + + override val targetPlatform: TargetPlatform = request.targetPlatform + + override fun shutdown() = Unit + } +} \ No newline at end of file