Skip to content

Commit 3080f5a

Browse files
committed
Add tests
1 parent 49cb3b9 commit 3080f5a

File tree

3 files changed

+47
-4
lines changed

3 files changed

+47
-4
lines changed

crates/uv-metadata/src/lib.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub enum Error {
3737
#[error("The .dist-info directory name contains invalid characters")]
3838
InvalidName(#[from] InvalidNameError),
3939
#[error("The metadata at {0} is invalid")]
40-
InvalidMetadata(String, pypi_types::MetadataError),
40+
InvalidMetadata(String, Box<pypi_types::MetadataError>),
4141
#[error("Failed to read from zip file")]
4242
Zip(#[from] zip::result::ZipError),
4343
#[error("Failed to read from zip file")]
@@ -285,7 +285,7 @@ pub async fn read_metadata_async_stream<R: futures::AsyncRead + Unpin>(
285285
reader.read_to_end(&mut contents).await.unwrap();
286286

287287
let metadata = Metadata23::parse_metadata(&contents)
288-
.map_err(|err| Error::InvalidMetadata(debug_path.to_string(), err))?;
288+
.map_err(|err| Error::InvalidMetadata(debug_path.to_string(), Box::new(err)))?;
289289
return Ok(metadata);
290290
}
291291

@@ -305,7 +305,10 @@ pub fn read_flat_wheel_metadata(
305305
let dist_info_prefix = find_flat_dist_info(filename, &wheel)?;
306306
let metadata = read_dist_info_metadata(&dist_info_prefix, &wheel)?;
307307
Metadata23::parse_metadata(&metadata).map_err(|err| {
308-
Error::InvalidMetadata(format!("{dist_info_prefix}.dist-info/METADATA"), err)
308+
Error::InvalidMetadata(
309+
format!("{dist_info_prefix}.dist-info/METADATA"),
310+
Box::new(err),
311+
)
309312
})
310313
}
311314

crates/uv/tests/lock.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12695,7 +12695,7 @@ fn lock_duplicate_sources() -> Result<()> {
1269512695
}
1269612696

1269712697
#[test]
12698-
fn lock_invalid_project_table_dep() -> Result<()> {
12698+
fn lock_invalid_project_table() -> Result<()> {
1269912699
let context = TestContext::new("3.12");
1270012700

1270112701
let pyproject_toml = context.temp_dir.child("a/pyproject.toml");
@@ -12706,6 +12706,7 @@ fn lock_invalid_project_table_dep() -> Result<()> {
1270612706
version = "0.1.0"
1270712707
requires-python = ">=3.12"
1270812708
dependencies = ["b"]
12709+
1270912710
[tool.uv.sources]
1271012711
b = { path = "../b" }
1271112712
"#,

crates/uv/tests/run.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1910,3 +1910,42 @@ fn run_exit_code() -> Result<()> {
19101910

19111911
Ok(())
19121912
}
1913+
1914+
#[test]
1915+
fn run_lock_invalid_project_table() -> Result<()> {
1916+
let context = TestContext::new_with_versions(&["3.12", "3.11", "3.8"]);
1917+
1918+
let pyproject_toml = context.temp_dir.child("pyproject.toml");
1919+
pyproject_toml.write_str(indoc! { r#"
1920+
[project.urls]
1921+
repository = 'https://github.com/octocat/octocat-python'
1922+
1923+
[build-system]
1924+
requires = ["setuptools>=42"]
1925+
build-backend = "setuptools.build_meta"
1926+
"#
1927+
})?;
1928+
1929+
let test_script = context.temp_dir.child("main.py");
1930+
test_script.write_str(indoc! { r#"
1931+
print("Hello, world!")
1932+
"#
1933+
})?;
1934+
1935+
uv_snapshot!(context.filters(), context.run().arg("main.py"), @r###"
1936+
success: false
1937+
exit_code: 2
1938+
----- stdout -----
1939+
1940+
----- stderr -----
1941+
error: Failed to parse: `pyproject.toml`
1942+
Caused by: TOML parse error at line 1, column 2
1943+
|
1944+
1 | [project.urls]
1945+
| ^^^^^^^
1946+
missing field `name`
1947+
1948+
"###);
1949+
1950+
Ok(())
1951+
}

0 commit comments

Comments
 (0)