@@ -90,6 +90,114 @@ fn create_venv_ignores_virtual_env_variable() {
90
90
) ;
91
91
}
92
92
93
+ #[ test]
94
+ fn create_venv_reads_request_from_python_version_file ( ) {
95
+ let context = TestContext :: new_with_versions ( & [ "3.11" , "3.12" ] ) ;
96
+
97
+ // Without the file, we should use the first on the PATH
98
+ uv_snapshot ! ( context. filters( ) , context. venv( )
99
+ . arg( "--preview" ) , @r###"
100
+ success: true
101
+ exit_code: 0
102
+ ----- stdout -----
103
+
104
+ ----- stderr -----
105
+ Using Python 3.11.[X] interpreter at: [PYTHON-3.11]
106
+ Creating virtualenv at: [VENV]/
107
+ Activate with: source [VENV]/bin/activate
108
+ "###
109
+ ) ;
110
+
111
+ // With a version file, we should prefer that version
112
+ context
113
+ . temp_dir
114
+ . child ( ".python-version" )
115
+ . write_str ( "3.12" )
116
+ . unwrap ( ) ;
117
+
118
+ uv_snapshot ! ( context. filters( ) , context. venv( )
119
+ . arg( "--preview" ) , @r###"
120
+ success: true
121
+ exit_code: 0
122
+ ----- stdout -----
123
+
124
+ ----- stderr -----
125
+ Using Python 3.12.[X] interpreter at: [PYTHON-3.12]
126
+ Creating virtualenv at: [VENV]/
127
+ Activate with: source [VENV]/bin/activate
128
+ "###
129
+ ) ;
130
+
131
+ context. venv . assert ( predicates:: path:: is_dir ( ) ) ;
132
+ }
133
+
134
+ #[ test]
135
+ fn create_venv_reads_request_from_python_versions_file ( ) {
136
+ let context = TestContext :: new_with_versions ( & [ "3.11" , "3.12" ] ) ;
137
+
138
+ // Without the file, we should use the first on the PATH
139
+ uv_snapshot ! ( context. filters( ) , context. venv( )
140
+ . arg( "--preview" ) , @r###"
141
+ success: true
142
+ exit_code: 0
143
+ ----- stdout -----
144
+
145
+ ----- stderr -----
146
+ Using Python 3.11.[X] interpreter at: [PYTHON-3.11]
147
+ Creating virtualenv at: [VENV]/
148
+ Activate with: source [VENV]/bin/activate
149
+ "###
150
+ ) ;
151
+
152
+ // With a versions file, we should prefer the first listed version
153
+ context
154
+ . temp_dir
155
+ . child ( ".python-versions" )
156
+ . write_str ( "3.12\n 3.11" )
157
+ . unwrap ( ) ;
158
+
159
+ uv_snapshot ! ( context. filters( ) , context. venv( )
160
+ . arg( "--preview" ) , @r###"
161
+ success: true
162
+ exit_code: 0
163
+ ----- stdout -----
164
+
165
+ ----- stderr -----
166
+ Using Python 3.12.[X] interpreter at: [PYTHON-3.12]
167
+ Creating virtualenv at: [VENV]/
168
+ Activate with: source [VENV]/bin/activate
169
+ "###
170
+ ) ;
171
+
172
+ context. venv . assert ( predicates:: path:: is_dir ( ) ) ;
173
+ }
174
+
175
+ #[ test]
176
+ fn create_venv_explicit_request_takes_priority_over_python_version_file ( ) {
177
+ let context = TestContext :: new_with_versions ( & [ "3.11" , "3.12" ] ) ;
178
+
179
+ context
180
+ . temp_dir
181
+ . child ( ".python-version" )
182
+ . write_str ( "3.12" )
183
+ . unwrap ( ) ;
184
+
185
+ uv_snapshot ! ( context. filters( ) , context. venv( )
186
+ . arg( "--preview" ) . arg( "--python" ) . arg( "3.11" ) , @r###"
187
+ success: true
188
+ exit_code: 0
189
+ ----- stdout -----
190
+
191
+ ----- stderr -----
192
+ Using Python 3.11.[X] interpreter at: [PYTHON-3.11]
193
+ Creating virtualenv at: [VENV]/
194
+ Activate with: source [VENV]/bin/activate
195
+ "###
196
+ ) ;
197
+
198
+ context. venv . assert ( predicates:: path:: is_dir ( ) ) ;
199
+ }
200
+
93
201
#[ test]
94
202
fn seed ( ) {
95
203
let context = TestContext :: new_with_versions ( & [ "3.12" ] ) ;
0 commit comments