From 1fe0f9514b9be6842ee12fc51ed5dc6938e31ef9 Mon Sep 17 00:00:00 2001 From: nre Date: Thu, 14 Sep 2023 16:17:40 +0000 Subject: [PATCH] Run pyenv to assert the pyenv root path exists To support Windows (which will be done in a subsequent commit), we'll need to translate Windows-style paths to Cygwin-style paths (for example, C:\foo\bar -> /c/foo/bar). The fileExists step only supports Windows-style paths when run on Windows, which means that we need to actually run pyenv to assert that it exists. --- src/com/ableton/Pyenv.groovy | 4 ++-- test/com/ableton/PyenvTest.groovy | 7 +++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/com/ableton/Pyenv.groovy b/src/com/ableton/Pyenv.groovy index 1e387a1..fb17bf1 100644 --- a/src/com/ableton/Pyenv.groovy +++ b/src/com/ableton/Pyenv.groovy @@ -120,8 +120,8 @@ class Pyenv implements Serializable { protected void assertPyenvRoot() { assert pyenvRoot - if (!script.fileExists(pyenvRoot)) { - script.error "pyenv root path '${pyenvRoot}' does not exist" + if (script.sh(returnStatus: true, script: "${pyenvRoot}/bin/pyenv --version")) { + script.error "pyenv executable not found in '${pyenvRoot}'" } } } diff --git a/test/com/ableton/PyenvTest.groovy b/test/com/ableton/PyenvTest.groovy index df3b212..d984774 100644 --- a/test/com/ableton/PyenvTest.groovy +++ b/test/com/ableton/PyenvTest.groovy @@ -35,8 +35,8 @@ class PyenvTest extends BasePipelineTest { @Test void assertPyenvRootInvalidRoot() { String pyenvRoot = '/mock/pyenv/root' - helper.registerAllowedMethod('fileExists', [String]) { return false } helper.registerAllowedMethod('isUnix', []) { return true } + helper.addShMock("${pyenvRoot}/bin/pyenv --version", '1.2.3', 0) assertThrows(Exception) { new Pyenv(script, '1.2.3', pyenvRoot).createVirtualEnv() } } @@ -52,8 +52,8 @@ class PyenvTest extends BasePipelineTest { void createVirtualEnv() { String pythonVersion = '1.2.3' String pyenvRoot = '/mock/pyenv/root' - helper.registerAllowedMethod('fileExists', [String]) { return true } helper.registerAllowedMethod('isUnix', []) { return true } + helper.addShMock("${pyenvRoot}/bin/pyenv --version", '1.2.3', 0) helper.addShMock(installCommands(pyenvRoot, pythonVersion), '', 0) Object venv = new Pyenv(script, pyenvRoot).createVirtualEnv(pythonVersion, 1) @@ -74,7 +74,6 @@ class PyenvTest extends BasePipelineTest { String pyenvRoot = '/mock/pyenv/root' boolean errorCalled = false helper.registerAllowedMethod('error', [String]) { errorCalled = true } - helper.registerAllowedMethod('fileExists', [String]) { return true } helper.registerAllowedMethod('isUnix', []) { return true } helper.addShMock("${pyenvRoot}/bin/pyenv --version", '1.2.3', 0) helper.addShMock(installCommands(pyenvRoot, pythonVersion), '', 1) @@ -93,8 +92,8 @@ class PyenvTest extends BasePipelineTest { 2.3.7 ''' String pyenvRoot = '/pyenv' + helper.addShMock("${pyenvRoot}/bin/pyenv --version", '1.2.3', 0) helper.addShMock("${pyenvRoot}/bin/pyenv install --list", mockPyenvVersions, 0) - helper.registerAllowedMethod('fileExists', [String]) { return true } helper.registerAllowedMethod('isUnix', []) { return true } assertTrue(new Pyenv(script, pyenvRoot).versionSupported('2.1.3'))