@@ -101,9 +101,26 @@ class PyenvTest extends BasePipelineTest {
101101
102102 @Test
103103 void createVirtualEnvWindows () {
104+ String pythonVersion = ' 1.2.3'
105+ String pyenvRoot = ' C:\\ mock\\ pyenv\\ root'
106+ String posixPyenvRoot = ' /c/mock/pyenv/root'
107+ String shPyenvRoot = ' C:/mock/pyenv/root'
108+ List shMocks = [
109+ new Tuple (installCommands(
110+ shPyenvRoot, pythonVersion, false , posixPyenvRoot), ' ' , 0
111+ ),
112+ new Tuple (" ${ shPyenvRoot} /bin/pyenv install --list" , ''' Available versions:
113+ 1.2.3
114+ ''' , 0 ),
115+ ]
116+ shMocks. each { mock -> helper. addShMock(mock[0 ], mock[1 ], mock[2 ]) }
117+ helper. registerAllowedMethod(' fileExists' , [String ]) { return true }
104118 script. env[' OS' ] = ' Windows_NT'
105119
106- assertThrows(Exception ) { new Pyenv (script, ' C:\\ pyenv' ). createVirtualEnv(' 1.2.3' ) }
120+ Object venv = new Pyenv (script, pyenvRoot). createVirtualEnv(pythonVersion, 1 )
121+
122+ assertEquals (" /workspace/.venv/${ TEST_RANDOM_NAME} " as String , venv. venvRootDir)
123+ shMocks. each { mock -> assertCallStackContains(mock[0 ]) }
107124 }
108125
109126 @Test
@@ -140,17 +157,43 @@ class PyenvTest extends BasePipelineTest {
140157
141158 @Test
142159 void versionSupportedWindows () {
160+ // Resembles pyenv's output, at least as of version 2.3.x
161+ String mockPyenvVersions = ''' Available versions:
162+ 2.1.3
163+ 2.2.3
164+ 2.3.7
165+ '''
166+ String shPyenvRoot = ' C:/pyenv'
167+ helper. addShMock(" ${ shPyenvRoot} /bin/pyenv install --list" , mockPyenvVersions, 0 )
168+ helper. registerAllowedMethod(' fileExists' , [String ]) { return true }
143169 script. env[' OS' ] = ' Windows_NT'
144170
145- assertThrows(Exception ) { new Pyenv (script, ' C:\\ pyenv' ). versionSupported(' 1.2.3' ) }
171+ assertTrue (new Pyenv (script, shPyenvRoot). versionSupported(' 2.1.3' ))
172+ assertFalse (new Pyenv (script, shPyenvRoot). versionSupported(' 2.1.3333' ))
173+ assertCallStackContains(" ${ shPyenvRoot} /bin/pyenv install --list" )
146174 }
147175
148- private String installCommands (String pyenvRoot , String pythonVersion ) {
176+ private String installCommands (
177+ String pyenvRoot ,
178+ String pythonVersion ,
179+ boolean isUnix = true ,
180+ String posixPyenvRoot = null
181+ ) {
149182 List installCommands = [
150183 " export PYENV_ROOT=${ pyenvRoot} " ,
151- " export PATH=\$ PYENV_ROOT/bin:\$ PATH" ,
152- ' eval "\$ (pyenv init --path)"' ,
153- ' eval "\$ (pyenv init -)"' ,
184+ ]
185+ if (isUnix) {
186+ installCommands + = [
187+ " export PATH=\$ PYENV_ROOT/bin:\$ PATH" ,
188+ ' eval "\$ (pyenv init --path)"' ,
189+ ' eval "\$ (pyenv init -)"' ,
190+ ]
191+ } else {
192+ installCommands + = [
193+ " export PATH=${ posixPyenvRoot} /shims:${ posixPyenvRoot} /bin:\$ PATH" ,
194+ ]
195+ }
196+ installCommands + = [
154197 " pyenv install --skip-existing ${ pythonVersion} " ,
155198 ' pyenv exec pip install virtualenv' ,
156199 " pyenv exec virtualenv /workspace/.venv/${ TEST_RANDOM_NAME} " ,
0 commit comments