Skip to content

Commit a27c93e

Browse files
committed
Add test case for uv python list downloads
1 parent 207ee0d commit a27c93e

File tree

2 files changed

+132
-2
lines changed

2 files changed

+132
-2
lines changed

crates/uv/tests/it/common/mod.rs

+21-2
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,10 @@ impl TestContext {
205205
self.filters
206206
.push(("python.exe".to_string(), "python".to_string()));
207207
} else {
208-
self.filters
209-
.push((r"python\d".to_string(), "python".to_string()));
210208
self.filters
211209
.push((r"python\d.\d\d".to_string(), "python".to_string()));
210+
self.filters
211+
.push((r"python\d".to_string(), "python".to_string()));
212212
}
213213
self
214214
}
@@ -224,6 +224,25 @@ impl TestContext {
224224
self
225225
}
226226

227+
/// Add extra standard filtering for Python installation `bin/` directories, which are not
228+
/// present on Windows but are on Unix. See [`TestContext::with_filtered_virtualenv_bin`] for
229+
/// the virtual environment equivalent.
230+
#[must_use]
231+
pub fn with_filtered_python_install_bin(mut self) -> Self {
232+
if cfg!(unix) {
233+
self.filters.push((
234+
r"[\\/]bin/python".to_string(),
235+
"/[INSTALL-BIN]/python".to_string(),
236+
));
237+
} else {
238+
self.filters.push((
239+
r"[\\/]/python".to_string(),
240+
"/[INSTALL-BIN]/python".to_string(),
241+
));
242+
}
243+
self
244+
}
245+
227246
/// Add extra filtering for ` -> <PATH>` symlink display for Python versions in the test
228247
/// context, e.g., for use in `uv python list`.
229248
#[must_use]

crates/uv/tests/it/python_list.rs

+111
Original file line numberDiff line numberDiff line change
@@ -280,3 +280,114 @@ fn python_list_unsupported_version() {
280280
error: Invalid version request: Python <3.13 does not support free-threading but 3.12t was requested.
281281
");
282282
}
283+
284+
#[test]
285+
fn python_list_downloads() {
286+
let context: TestContext = TestContext::new_with_versions(&[]).with_filtered_python_keys();
287+
288+
// We do not test showing all interpreters — as it differs per platform
289+
// Instead, we choose a Python version where our available distributions are stable
290+
291+
// Test the default display, which requires reverting the test context disabling Python downloads
292+
uv_snapshot!(context.filters(), context.python_list().arg("3.10").env_remove("UV_PYTHON_DOWNLOADS"), @r"
293+
success: true
294+
exit_code: 0
295+
----- stdout -----
296+
cpython-3.10.16-[PLATFORM] <download available>
297+
298+
----- stderr -----
299+
");
300+
301+
// Show patch versions
302+
uv_snapshot!(context.filters(), context.python_list().arg("3.10").arg("--all-versions").env_remove("UV_PYTHON_DOWNLOADS"), @r"
303+
success: true
304+
exit_code: 0
305+
----- stdout -----
306+
cpython-3.10.16-[PLATFORM] <download available>
307+
cpython-3.10.15-[PLATFORM] <download available>
308+
cpython-3.10.14-[PLATFORM] <download available>
309+
cpython-3.10.13-[PLATFORM] <download available>
310+
cpython-3.10.12-[PLATFORM] <download available>
311+
cpython-3.10.11-[PLATFORM] <download available>
312+
cpython-3.10.9-[PLATFORM] <download available>
313+
cpython-3.10.8-[PLATFORM] <download available>
314+
cpython-3.10.7-[PLATFORM] <download available>
315+
cpython-3.10.6-[PLATFORM] <download available>
316+
cpython-3.10.5-[PLATFORM] <download available>
317+
cpython-3.10.4-[PLATFORM] <download available>
318+
cpython-3.10.3-[PLATFORM] <download available>
319+
cpython-3.10.2-[PLATFORM] <download available>
320+
cpython-3.10.0-[PLATFORM] <download available>
321+
322+
----- stderr -----
323+
");
324+
}
325+
326+
#[test]
327+
#[cfg(feature = "python-managed")]
328+
fn python_list_downloads_installed() {
329+
use assert_cmd::assert::OutputAssertExt;
330+
331+
let context: TestContext = TestContext::new_with_versions(&[])
332+
.with_filtered_python_keys()
333+
.with_filtered_python_names()
334+
.with_filtered_python_install_bin()
335+
.with_managed_python_dirs();
336+
337+
// We do not test showing all interpreters — as it differs per platform
338+
// Instead, we choose a Python version where our available distributions are stable
339+
340+
// First, the download is shown as available
341+
uv_snapshot!(context.filters(), context.python_list().arg("3.10").env_remove("UV_PYTHON_DOWNLOADS"), @r"
342+
success: true
343+
exit_code: 0
344+
----- stdout -----
345+
cpython-3.10.16-[PLATFORM] <download available>
346+
347+
----- stderr -----
348+
");
349+
350+
// TODO(zanieb): It'd be nice to test `--show-urls` here too but we need special filtering for
351+
// the URL
352+
353+
// But not if `--only-installed` is used
354+
uv_snapshot!(context.filters(), context.python_list().arg("3.10").arg("--only-installed").env_remove("UV_PYTHON_DOWNLOADS"), @r"
355+
success: true
356+
exit_code: 0
357+
----- stdout -----
358+
359+
----- stderr -----
360+
");
361+
362+
// Install a Python version
363+
context.python_install().arg("3.10").assert().success();
364+
365+
// Then, it should be listed as installed instead of available
366+
uv_snapshot!(context.filters(), context.python_list().arg("3.10").env_remove("UV_PYTHON_DOWNLOADS"), @r"
367+
success: true
368+
exit_code: 0
369+
----- stdout -----
370+
cpython-3.10.16-[PLATFORM] managed/cpython-3.10.16-[PLATFORM]/[INSTALL-BIN]/python
371+
372+
----- stderr -----
373+
");
374+
375+
// But, the display should be reverted if `--only-downloads` is used
376+
uv_snapshot!(context.filters(), context.python_list().arg("3.10").arg("--only-downloads").env_remove("UV_PYTHON_DOWNLOADS"), @r"
377+
success: true
378+
exit_code: 0
379+
----- stdout -----
380+
cpython-3.10.16-[PLATFORM] <download available>
381+
382+
----- stderr -----
383+
");
384+
385+
// And should not be shown if `--no-managed-python` is used
386+
uv_snapshot!(context.filters(), context.python_list().arg("3.10").arg("--no-managed-python").env_remove("UV_PYTHON_DOWNLOADS"), @r"
387+
success: true
388+
exit_code: 0
389+
----- stdout -----
390+
391+
----- stderr -----
392+
");
393+
}

0 commit comments

Comments
 (0)