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