Skip to content

Commit b9e5805

Browse files
committed
Keep variant metadata tests with distribution types
1 parent e21285f commit b9e5805

5 files changed

Lines changed: 28 additions & 15 deletions

File tree

‎Cargo.lock‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎crates/uv-client/src/lib.rs‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,3 @@ mod remote_metadata;
3131
mod retry;
3232
mod rkyvutil;
3333
mod tls;
34-
#[cfg(test)]
35-
mod variants_json_tests;

‎crates/uv-distribution-types/Cargo.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ url = { workspace = true }
5858
version-ranges = { workspace = true }
5959

6060
[dev-dependencies]
61+
insta = { workspace = true }
6162
toml = { workspace = true }
6263

6364
[features]

‎crates/uv-distribution-types/src/variants_json.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ use tracing::debug;
55

66
use uv_distribution_filename::VariantLabel;
77

8-
/// The schema for the PEP 825 draft. TODO(konsti): Update when we have the final path.
8+
// TODO(konsti): Update the schema URL once PEP 825 is finalized.
9+
/// The schema for the PEP 825 draft.
910
const VARIANT_SCHEMA: &str = "https://variants-schema.wheelnext.dev/peps/825/v0.1.1.json";
1011

1112
/// An error parsing a variant metadata file.

crates/uv-client/src/variants_json_tests.rs renamed to crates/uv-distribution-types/tests/variants_json.rs

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ fn reject_empty_namespace_priorities() {
5656
"default-priorities": {"namespace": []},
5757
"variants": {"fast": {"cpu": {"level": ["v2", "v3"]}}, "null": {}}
5858
});
59-
let error = serde_json::from_value::<VariantsJsonContent>(invalid).unwrap_err();
59+
let error = serde_json::from_value::<VariantsJsonContent>(invalid)
60+
.expect_err("namespace priorities must not be empty");
6061
assert_snapshot!(error, @"Variant namespace priorities must be non-empty and unique");
6162
}
6263

@@ -67,7 +68,8 @@ fn reject_duplicate_namespace_priorities() {
6768
"default-priorities": {"namespace": ["cpu", "cpu"]},
6869
"variants": {"fast": {"cpu": {"level": ["v2", "v3"]}}, "null": {}}
6970
});
70-
let error = serde_json::from_value::<VariantsJsonContent>(invalid).unwrap_err();
71+
let error = serde_json::from_value::<VariantsJsonContent>(invalid)
72+
.expect_err("namespace priorities must be unique");
7173
assert_snapshot!(error, @"Variant namespace priorities must be non-empty and unique");
7274
}
7375

@@ -78,7 +80,8 @@ fn reject_invalid_namespace_in_priorities() {
7880
"default-priorities": {"namespace": ["CPU"]},
7981
"variants": {"fast": {"cpu": {"level": ["v2", "v3"]}}, "null": {}}
8082
});
81-
let error = serde_json::from_value::<VariantsJsonContent>(invalid).unwrap_err();
83+
let error = serde_json::from_value::<VariantsJsonContent>(invalid)
84+
.expect_err("namespace priorities must be valid");
8285
assert_snapshot!(error, @"Invalid variant namespace: `CPU`");
8386
}
8487

@@ -89,7 +92,8 @@ fn reject_namespace_missing_from_priorities() {
8992
"default-priorities": {"namespace": ["gpu"]},
9093
"variants": {"fast": {"cpu": {"level": ["v2", "v3"]}}, "null": {}}
9194
});
92-
let error = serde_json::from_value::<VariantsJsonContent>(invalid).unwrap_err();
95+
let error = serde_json::from_value::<VariantsJsonContent>(invalid)
96+
.expect_err("variant namespaces must appear in the priorities");
9397
assert_snapshot!(
9498
error,
9599
@"Variant namespace `cpu` is missing from default-priorities.namespace"
@@ -103,7 +107,8 @@ fn reject_invalid_variant_label() {
103107
"default-priorities": {"namespace": ["cpu"]},
104108
"variants": {"Bad": {}}
105109
});
106-
let error = serde_json::from_value::<VariantsJsonContent>(invalid).unwrap_err();
110+
let error = serde_json::from_value::<VariantsJsonContent>(invalid)
111+
.expect_err("variant labels must be valid");
107112
assert_snapshot!(
108113
error,
109114
@"Variant label must contain only lowercase ASCII letters, digits, underscores, and periods, not `B`"
@@ -117,7 +122,8 @@ fn reject_invalid_variant_namespace() {
117122
"default-priorities": {"namespace": ["cpu"]},
118123
"variants": {"fast": {"CPU": {"level": ["v3"]}}, "null": {}}
119124
});
120-
let error = serde_json::from_value::<VariantsJsonContent>(invalid).unwrap_err();
125+
let error = serde_json::from_value::<VariantsJsonContent>(invalid)
126+
.expect_err("variant namespaces must be valid");
121127
assert_snapshot!(error, @"Invalid variant namespace: `CPU`");
122128
}
123129

@@ -128,7 +134,8 @@ fn reject_invalid_variant_feature() {
128134
"default-priorities": {"namespace": ["cpu"]},
129135
"variants": {"fast": {"cpu": {"bad.feature": ["v3"]}}, "null": {}}
130136
});
131-
let error = serde_json::from_value::<VariantsJsonContent>(invalid).unwrap_err();
137+
let error = serde_json::from_value::<VariantsJsonContent>(invalid)
138+
.expect_err("variant features must be valid");
132139
assert_snapshot!(error, @"Invalid variant feature: `bad.feature`");
133140
}
134141

@@ -139,7 +146,8 @@ fn reject_invalid_variant_value() {
139146
"default-priorities": {"namespace": ["cpu"]},
140147
"variants": {"fast": {"cpu": {"level": ["v 3"]}}, "null": {}}
141148
});
142-
let error = serde_json::from_value::<VariantsJsonContent>(invalid).unwrap_err();
149+
let error = serde_json::from_value::<VariantsJsonContent>(invalid)
150+
.expect_err("variant values must be valid");
143151
assert_snapshot!(error, @"Invalid variant value: `v 3`");
144152
}
145153

@@ -150,7 +158,8 @@ fn reject_empty_feature_values() {
150158
"default-priorities": {"namespace": ["cpu"]},
151159
"variants": {"fast": {"cpu": {"level": []}}, "null": {}}
152160
});
153-
let error = serde_json::from_value::<VariantsJsonContent>(invalid).unwrap_err();
161+
let error = serde_json::from_value::<VariantsJsonContent>(invalid)
162+
.expect_err("variant features must have values");
154163
assert_snapshot!(error, @"Variant feature `cpu :: level` must have at least one value");
155164
}
156165

@@ -161,7 +170,8 @@ fn reject_duplicate_feature_values() {
161170
"default-priorities": {"namespace": ["cpu"]},
162171
"variants": {"fast": {"cpu": {"level": ["v3", "v2", "v3"]}}, "null": {}}
163172
});
164-
let error = serde_json::from_value::<VariantsJsonContent>(invalid).unwrap_err();
173+
let error = serde_json::from_value::<VariantsJsonContent>(invalid)
174+
.expect_err("variant values must be unique");
165175
assert_snapshot!(error, @"Variant feature `cpu :: level` must not contain duplicate values");
166176
}
167177

@@ -172,7 +182,8 @@ fn reject_null_variant_with_properties() {
172182
"default-priorities": {"namespace": ["cpu"]},
173183
"variants": {"fast": {"cpu": {"level": ["v2", "v3"]}}, "null": {"cpu": {"level": ["v3"]}}}
174184
});
175-
let error = serde_json::from_value::<VariantsJsonContent>(invalid).unwrap_err();
185+
let error = serde_json::from_value::<VariantsJsonContent>(invalid)
186+
.expect_err("the null variant must not have properties");
176187
assert_snapshot!(error, @"The null variant must not have properties");
177188
}
178189

@@ -183,6 +194,7 @@ fn reject_unknown_field_in_default_priorities() {
183194
"default-priorities": {"namespace": ["cpu"], "unknown": []},
184195
"variants": {"fast": {"cpu": {"level": ["v2", "v3"]}}, "null": {}}
185196
});
186-
let error = serde_json::from_value::<VariantsJsonContent>(invalid).unwrap_err();
197+
let error = serde_json::from_value::<VariantsJsonContent>(invalid)
198+
.expect_err("default priorities must not contain unknown fields");
187199
assert_snapshot!(error, @"unknown field `unknown`, expected `namespace`");
188200
}

0 commit comments

Comments
 (0)
⌂ 换网址