2020-10-02 02:55:27 -07:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2020-11-14 11:04:04 -08:00
|
|
|
"github.com/alecthomas/assert"
|
2020-10-02 02:55:27 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
type pythonArgs struct {
|
|
|
|
virtualEnvName string
|
|
|
|
condaEnvName string
|
|
|
|
condaDefaultName string
|
|
|
|
pyEnvName string
|
2020-11-14 11:04:04 -08:00
|
|
|
displayVersion bool
|
2020-10-02 02:55:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func bootStrapPythonTest(args *pythonArgs) *python {
|
|
|
|
env := new(MockedEnvironment)
|
2020-11-14 11:04:04 -08:00
|
|
|
env.On("hasCommand", "python").Return(true)
|
|
|
|
env.On("runCommand", "python", []string{"--version"}).Return("Python 3.8.4", nil)
|
|
|
|
env.On("hasFiles", "*.py").Return(true)
|
2020-10-02 02:55:27 -07:00
|
|
|
env.On("getenv", "VIRTUAL_ENV").Return(args.virtualEnvName)
|
|
|
|
env.On("getenv", "CONDA_ENV_PATH").Return(args.condaEnvName)
|
|
|
|
env.On("getenv", "CONDA_DEFAULT_ENV").Return(args.condaDefaultName)
|
|
|
|
env.On("getenv", "PYENV_VERSION").Return(args.pyEnvName)
|
2020-11-14 11:04:04 -08:00
|
|
|
env.On("getPathSeperator", nil).Return("")
|
2020-10-02 02:55:27 -07:00
|
|
|
props := &properties{
|
|
|
|
values: map[Property]interface{}{
|
2020-11-14 11:04:04 -08:00
|
|
|
DisplayVersion: args.displayVersion,
|
2020-10-02 02:55:27 -07:00
|
|
|
DisplayVirtualEnv: true,
|
|
|
|
},
|
|
|
|
}
|
2020-11-14 11:04:04 -08:00
|
|
|
python := &python{}
|
|
|
|
python.init(props, env)
|
|
|
|
return python
|
2020-10-02 02:55:27 -07:00
|
|
|
}
|
|
|
|
|
2020-11-14 11:04:04 -08:00
|
|
|
func TestPythonVertualEnv(t *testing.T) {
|
|
|
|
expected := "VENV"
|
|
|
|
args := &pythonArgs{
|
|
|
|
virtualEnvName: expected,
|
|
|
|
}
|
2020-10-02 02:55:27 -07:00
|
|
|
python := bootStrapPythonTest(args)
|
|
|
|
assert.True(t, python.enabled())
|
|
|
|
assert.Equal(t, expected, python.string())
|
|
|
|
}
|
|
|
|
|
2020-11-14 11:04:04 -08:00
|
|
|
func TestPythonCondaEnv(t *testing.T) {
|
|
|
|
expected := "CONDA"
|
|
|
|
args := &pythonArgs{
|
|
|
|
condaEnvName: expected,
|
|
|
|
}
|
2020-10-02 02:55:27 -07:00
|
|
|
python := bootStrapPythonTest(args)
|
|
|
|
assert.True(t, python.enabled())
|
|
|
|
assert.Equal(t, expected, python.string())
|
|
|
|
}
|
|
|
|
|
2020-11-14 11:04:04 -08:00
|
|
|
func TestPythonCondaDefaultName(t *testing.T) {
|
|
|
|
expected := "CONDADEF"
|
|
|
|
args := &pythonArgs{
|
|
|
|
condaDefaultName: expected,
|
|
|
|
}
|
2020-11-09 06:47:34 -08:00
|
|
|
python := bootStrapPythonTest(args)
|
|
|
|
assert.True(t, python.enabled())
|
|
|
|
assert.Equal(t, expected, python.string())
|
|
|
|
}
|
|
|
|
|
2020-11-14 11:04:04 -08:00
|
|
|
func TestPythonPyEnv(t *testing.T) {
|
|
|
|
expected := "PYENV"
|
|
|
|
args := &pythonArgs{
|
|
|
|
pyEnvName: expected,
|
|
|
|
}
|
2020-10-02 02:55:27 -07:00
|
|
|
python := bootStrapPythonTest(args)
|
|
|
|
assert.True(t, python.enabled())
|
|
|
|
assert.Equal(t, expected, python.string())
|
|
|
|
}
|
|
|
|
|
2020-11-14 11:04:04 -08:00
|
|
|
func TestPythonPyEnvWithVersion(t *testing.T) {
|
|
|
|
expected := "PYENV 3.8.4"
|
|
|
|
args := &pythonArgs{
|
|
|
|
pyEnvName: "PYENV",
|
|
|
|
displayVersion: true,
|
|
|
|
}
|
2020-10-02 02:55:27 -07:00
|
|
|
python := bootStrapPythonTest(args)
|
|
|
|
assert.True(t, python.enabled())
|
2020-11-14 11:04:04 -08:00
|
|
|
assert.Equal(t, "3.8.4", python.language.version)
|
2020-10-02 02:55:27 -07:00
|
|
|
assert.Equal(t, expected, python.string())
|
|
|
|
}
|