forked from JanDeDobbeleer/oh-my-posh
-
Notifications
You must be signed in to change notification settings - Fork 1
/
segment_python_test.go
88 lines (79 loc) · 2.17 KB
/
segment_python_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package main
import (
"testing"
"github.com/alecthomas/assert"
)
type pythonArgs struct {
virtualEnvName string
condaEnvName string
condaDefaultName string
pyEnvName string
displayVersion bool
}
func bootStrapPythonTest(args *pythonArgs) *python {
env := new(MockedEnvironment)
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)
env.On("getPathSeperator", nil).Return("")
props := &properties{
values: map[Property]interface{}{
DisplayVersion: args.displayVersion,
DisplayVirtualEnv: true,
},
}
python := &python{}
python.init(props, env)
return python
}
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())
}
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())
}
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())
}
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())
}
func TestPythonPyEnvWithVersion(t *testing.T) {
expected := "PYENV 3.8.4"
args := &pythonArgs{
pyEnvName: "PYENV",
displayVersion: true,
}
python := bootStrapPythonTest(args)
assert.True(t, python.enabled())
assert.Equal(t, "3.8.4", python.language.version)
assert.Equal(t, expected, python.string())
}