Commit c8009aa
Add pypa/packaging conformance tests for PEP 440 specifier parsing (#1776)
## What
Adds a data-driven conformance suite that validates
`PythonVersionSpecifier` /
`PythonVersion` against **pypa/packaging**, the reference PEP 440
implementation.
`requires-python` in a PEP 723 inline-script block is a PEP 440 version
specifier, and
we evaluate it ourselves (in `matchesPythonVersion`) to choose a base
interpreter and to
decide which Python version to ask uv to install. This pins that
behaviour to the
reference implementation so edge cases can't drift.
118 cases ported from `tests/test_specifiers.py`:
| Suite | Cases | Asserts |
| --- | --- | --- |
| `rejects specifiers packaging rejects` | 31 | `tryParse` returns
`undefined` |
| `matches packaging semantics` | 85 | `matches()` equals packaging's
result |
| `diverges from packaging by design` | 2 | our intentional behaviour |
## How expected values were produced
They were **generated by calling packaging 24.1 directly**, not
hand-transcribed.
Two things to know when re-generating:
1. **Prerelease semantics.** Upstream's harness constructs
`Specifier(spec, prereleases=True)`,
which is *not* packaging's default. Expected values here use the
**default**, which is the
correct model for `requires-python`. Against the default we match
packaging on all 85 cases.
2. **Scope.** Cases using epochs (`2!1.0`), local labels
(`2.0+deadbeef`), post/dev releases,
or more than three release segments are omitted. A Python interpreter
version never has
them, and `PythonVersion` deliberately does not model them (see its
class doc).
## The two intentional divergences
packaging's `Specifier.prereleases` auto-enables prereleases only for
`==`, `>=`, `<=`, `~=`
and `===` — **`<` and `>` are excluded**. So under packaging's default:
- `>3.0.0a7` matches only *final* releases (`3.0.0`, `3.0.1`); it
rejects `3.0.0a8`, `3.0.0b1`, `3.0.0rc1`
- `<3.0.0a8` rejects every 3.x prerelease
Our rule is uniform: any clause naming a prerelease enables prereleases.
That is what the
class docs describe and what `pythonVersionSpecifier.unit.test.ts`
already asserts for
`<3.14.0rc2`. These two cases are isolated in their own suite with the
reason recorded, so
they're an explicit decision rather than an accidental mismatch.
## Testing
- 118/118 new tests pass
- `npm run lint` clean on the new file
- Full unit suite: **2220 passing, 0 failing**
## Licensing
pypa/packaging is dual-licensed Apache-2.0 / BSD-2-Clause. The ported
test data is used
under **BSD-2-Clause**, with source, copyright and licence recorded in
the file header.
No production code is affected — this PR adds a test file only.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent db0a3b2 commit c8009aa
1 file changed
Lines changed: 181 additions & 0 deletions
Lines changed: 181 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
0 commit comments