From ae2691e1d3a77170c3826c6529d32d706ff63ada Mon Sep 17 00:00:00 2001 From: j178 <10510431+j178@users.noreply.github.com> Date: Wed, 24 Jul 2024 01:24:06 +0800 Subject: [PATCH] Add test --- crates/uv/tests/python_pin.rs | 41 +++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/crates/uv/tests/python_pin.rs b/crates/uv/tests/python_pin.rs index 53ca8fce7c800..e6e3c689da61d 100644 --- a/crates/uv/tests/python_pin.rs +++ b/crates/uv/tests/python_pin.rs @@ -1,11 +1,12 @@ #![cfg(all(feature = "python", feature = "pypi"))] -use assert_fs::fixture::{FileWriteStr as _, PathChild as _}; +use anyhow::Result; +use assert_fs::fixture::{FileWriteStr, PathChild, PathCreateDir}; use common::{uv_snapshot, TestContext}; use insta::assert_snapshot; use uv_python::{ platform::{Arch, Os}, - PYTHON_VERSION_FILENAME, + PYTHON_VERSIONS_FILENAME, PYTHON_VERSION_FILENAME, }; mod common; @@ -629,3 +630,39 @@ fn python_pin_resolve() { "###); }); } + +#[test] +fn test_read_python_version() -> Result<()> { + let context = TestContext::new_with_versions(&[]); + + let child = context.temp_dir.child("foo"); + child.create_dir_all()?; + + let version_file = child.child(PYTHON_VERSION_FILENAME); + version_file.write_str("3.12\n\n# 3.11\n3.10\n\n")?; + uv_snapshot!(context.filters(), context.python_pin().current_dir(&child), @r###" + success: true + exit_code: 0 + ----- stdout ----- + 3.12 + + ----- stderr ----- + "###); + + let child = context.temp_dir.child("bar"); + child.create_dir_all()?; + + let versions_file = child.child(PYTHON_VERSIONS_FILENAME); + versions_file.write_str("3.12\n\n# 3.11\n3.10\n\n")?; + uv_snapshot!(context.filters(), context.python_pin().current_dir(&child), @r###" + success: true + exit_code: 0 + ----- stdout ----- + 3.12 + 3.10 + + ----- stderr ----- + "###); + + Ok(()) +}