Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,42 @@ pgregory.net/rapid is licensed under the Mozilla Public License, Version 2.0.
It is a test-only dependency: internal/proptest contains only _test.go files,
so rapid does not appear in this module's non-test import graph and is not
built into any consumer that imports this library.

The marker/ package's conformance tests port the marker evaluation and parse
cases of pypa/packaging (https://github.com/pypa/packaging), Copyright (c)
Donald Stufft and individual contributors, specifically tests/test_markers.py's
classes TestOperatorEvaluation and TestMarker and its module-level and/or
evaluation tests, pinned at commit 4eb0753dba8fcaaac8eb75463374e448f0931558
(identical at release 26.3), licensed under the Apache License, Version 2.0.
Translated from Python/pytest to Go table-driven tests, in
marker/conformance_test.go. Upstream tests resting on implementation details
with no counterpart here are not ported, and the reason is recorded in the
file's header: TestNode, TestDefaultEnvironment (the live interpreter),
__str__/__repr__/__hash__/__eq__, the operator-overload tests, every
test_pickle_*, evaluate(context=...), and the set-valued "extras"/
"dependency_groups" marker variables (PEP 685/735), which this package's
grammar does not recognize at all. Where a Go expectation differs from
upstream's literal assertion the divergence is annotated inline at its table.

The extras/ package's conformance tests port the name-canonicalization cases
of pypa/packaging (https://github.com/pypa/packaging), Copyright (c) Donald
Stufft and individual contributors, specifically tests/test_utils.py's
test_canonicalize_name and the non-validating half of
test_canonicalize_name_invalid, pinned at commit
4eb0753dba8fcaaac8eb75463374e448f0931558, licensed under the Apache License,
Version 2.0. Translated from Python/pytest to Go table-driven tests, in
extras/conformance_test.go.

The internal/pep508 package's error-position conformance tests port input
strings and caret span offsets - not message text - from Astral uv's
uv-pep508 crate (https://github.com/astral-sh/uv), specifically
crates/uv-pep508/src/lib.rs's `mod tests` error_* cases, pinned at commit
01cb90c1a4f88af09906cb60de9766d2add4a062 (release 0.12.18). uv-pep508
overrides uv's workspace license to Apache-2.0 OR BSD-2-Clause (Copyright (c)
2023 konstin) and ships its own license files; this material is taken under
the Apache-2.0 arm. Translated from Rust/insta snapshots to Go table-driven
tests, in internal/pep508/error_position_test.go, asserting this package's own
byte offsets and message text throughout - never uv's prose, and never any
case behind uv's "non-pep508-extensions" cargo feature (unnamed
direct-reference requirements, which this module's grammar has no
counterpart for).
84 changes: 84 additions & 0 deletions extras/conformance_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// SPDX-License-Identifier: Apache-2.0 OR MIT
//
// Portions of this file port test cases from pypa/packaging
// (https://github.com/pypa/packaging), specifically tests/test_utils.py's
// test_canonicalize_name, used under the Apache License, Version 2.0
// (dual-licensed Apache-2.0 OR BSD-2-Clause; see NOTICE for full license and
// copyright detail).
// Changed: translated from Python/pytest to Go table-driven tests; see the
// divergence notes below for cases where the Go expectation intentionally
// differs from upstream's literal assertion.
//
// Of test_utils.py's 11 test functions, only this one maps cleanly onto this
// module: 6 are parse_wheel_filename/parse_sdist_filename (wheelname/'s
// concern, and parse_sdist_filename has no Go counterpart at all), and
// test_canonicalize_version, test_is_normalized_name, and the validating half
// of canonicalize_name(validate=True) have no Go implementation anywhere in
// this module. Only extras.Normalize (canonicalize_name) is ported here.
//
// Upstream pinned at 4eb0753dba8fcaaac8eb75463374e448f0931558 (identical at
// release 26.3: the only test_markers.py/test_utils.py change since is a type
// annotation, not a case).

package extras

import (
"testing"

"github.com/stretchr/testify/assert"
)

// Ported from pypa/packaging tests/test_utils.py, test_canonicalize_name.
// Pinned: 4eb0753dba8fcaaac8eb75463374e448f0931558 (L23-L39 at that commit).
// https://github.com/pypa/packaging/blob/4eb0753dba8fcaaac8eb75463374e448f0931558/tests/test_utils.py#L23-L39
func TestConformance_CanonicalizeName(t *testing.T) {
tests := []struct {
name string
want string
}{
{"foo", "foo"},
{"Foo", "foo"},
{"fOo", "foo"},
{"foo.bar", "foo-bar"},
{"Foo.Bar", "foo-bar"},
{"Foo.....Bar", "foo-bar"},
{"foo_bar", "foo-bar"},
{"foo___bar", "foo-bar"},
{"foo-bar", "foo-bar"},
{"foo----bar", "foo-bar"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equal(t, tt.want, Normalize(tt.name))
})
}
}

// Ported from pypa/packaging tests/test_utils.py,
// test_canonicalize_name_invalid - the NON-VALIDATING half only
// (`assert canonicalize_name(name) == expected`). The validating half
// (`canonicalize_name(name, validate=True)` raising InvalidName) has no
// counterpart: Normalize has no validate mode, and PEP 503/685 name-validity
// checking is not implemented anywhere in this module. A half-port, not a
// skip: the assertion this function still makes is real and ported as-is.
// Pinned: 4eb0753dba8fcaaac8eb75463374e448f0931558 (L42-L57 at that commit).
// https://github.com/pypa/packaging/blob/4eb0753dba8fcaaac8eb75463374e448f0931558/tests/test_utils.py#L42-L57
func TestConformance_CanonicalizeNameInvalid_NonValidatingHalf(t *testing.T) {
tests := []struct {
name string
want string
}{
{"_not_legal", "-not-legal"},
{"hi\n", "hi\n"},
{"\nhi", "\nhi"},
{"h\ni", "h\ni"},
{"hi\r", "hi\r"},
{"\rhi", "\rhi"},
{"h\ri", "h\ri"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equal(t, tt.want, Normalize(tt.name))
})
}
}
Loading
Loading