File: version-name.bats

package info (click to toggle)
pyenv 2.5.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 8,176 kB
  • sloc: sh: 4,727; python: 402; makefile: 70; ansic: 60
file content (141 lines) | stat: -rw-r--r-- 3,288 bytes parent folder | download | duplicates (2)
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/usr/bin/env bats

load test_helper

create_version() {
  mkdir -p "${PYENV_ROOT}/versions/$1"
}

setup() {
  mkdir -p "$PYENV_TEST_DIR"
  cd "$PYENV_TEST_DIR"
}

@test "no version selected" {
  assert [ ! -d "${PYENV_ROOT}/versions" ]
  run pyenv-version-name
  assert_success "system"
}

@test "system version is not checked for existence" {
  PYENV_VERSION=system run pyenv-version-name
  assert_success "system"
}

@test "PYENV_VERSION can be overridden by hook" {
  create_version "2.7.11"
  create_version "3.5.1"
  create_hook version-name test.bash <<<"PYENV_VERSION=3.5.1"

  PYENV_VERSION=2.7.11 run pyenv-version-name
  assert_success "3.5.1"
}

@test "carries original IFS within hooks" {
  create_hook version-name hello.bash <<SH
hellos=(\$(printf "hello\\tugly world\\nagain"))
echo HELLO="\$(printf ":%s" "\${hellos[@]}")"
SH

  export PYENV_VERSION=system
  IFS=$' \t\n' run pyenv-version-name env
  assert_success
  assert_line "HELLO=:hello:ugly:world:again"
}

@test "PYENV_VERSION has precedence over local" {
  create_version "2.7.11"
  create_version "3.5.1"

  cat > ".python-version" <<<"2.7.11"
  run pyenv-version-name
  assert_success "2.7.11"

  PYENV_VERSION=3.5.1 run pyenv-version-name
  assert_success "3.5.1"
}

@test "local file has precedence over global" {
  create_version "2.7.11"
  create_version "3.5.1"

  cat > "${PYENV_ROOT}/version" <<<"2.7.11"
  run pyenv-version-name
  assert_success "2.7.11"

  cat > ".python-version" <<<"3.5.1"
  run pyenv-version-name
  assert_success "3.5.1"
}

@test "missing version" {
  PYENV_VERSION=1.2 run pyenv-version-name
  assert_failure "pyenv: version \`1.2' is not installed (set by PYENV_VERSION environment variable)"
}

@test "missing version with --force" {
  PYENV_VERSION=1.2 run pyenv-version-name -f
  assert_success "1.2"
}

@test "one missing version (second missing)" {
  create_version "3.5.1"
  PYENV_VERSION="3.5.1:1.2" run pyenv-version-name
  assert_failure
  assert_output <<OUT
pyenv: version \`1.2' is not installed (set by PYENV_VERSION environment variable)
3.5.1
OUT
}

@test "one missing version (first missing)" {
  create_version "3.5.1"
  PYENV_VERSION="1.2:3.5.1" run pyenv-version-name
  assert_failure
  assert_output <<OUT
pyenv: version \`1.2' is not installed (set by PYENV_VERSION environment variable)
3.5.1
OUT
}

pyenv-version-name-without-stderr() {
  pyenv-version-name 2>/dev/null
}

@test "one missing version (without stderr)" {
  create_version "3.5.1"
  PYENV_VERSION="1.2:3.5.1" run pyenv-version-name-without-stderr
  assert_failure
  assert_output <<OUT
3.5.1
OUT
}

@test "version with prefix in name" {
  create_version "2.7.11"
  cat > ".python-version" <<<"python-2.7.11"
  run pyenv-version-name
  assert_success
  assert_output "2.7.11"
}

@test "falls back to pyenv-latest" {
  create_version "2.7.11"
  PYENV_VERSION="2.7" run pyenv-version-name
  assert_success
  assert_output "2.7.11"
}

@test "pyenv-latest fallback with prefix in name" {
  create_version "3.12.6"
  PYENV_VERSION="python-3.12" run pyenv-version-name
  assert_success
  assert_output "3.12.6"
}

@test "pyenv version started by python-" {
  create_version "python-3.12.6"
  PYENV_VERSION="python-3.12.6" run pyenv-version-name
  assert_success
  assert_output "python-3.12.6"
}