oh-my-posh/segment_python_test.go

89 lines
2.2 KiB
Go
Raw Normal View History

package main
import (
"testing"
2020-11-14 11:04:04 -08:00
"github.com/alecthomas/assert"
)
type pythonArgs struct {
virtualEnvName string
condaEnvName string
condaDefaultName string
pyEnvName string
2020-11-14 11:04:04 -08:00
displayVersion bool
}
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)
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("")
props := &properties{
values: map[Property]interface{}{
2020-11-14 11:04:04 -08:00
DisplayVersion: args.displayVersion,
DisplayVirtualEnv: true,
},
}
2020-11-14 11:04:04 -08:00
python := &python{}
python.init(props, env)
return python
}
2020-11-14 11:04:04 -08:00
func TestPythonVertualEnv(t *testing.T) {
expected := "VENV"
args := &pythonArgs{
virtualEnvName: expected,
}
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,
}
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,
}
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,
}
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,
}
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)
assert.Equal(t, expected, python.string())
}