Skip to content

Use literal file names in test_commands #1212

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
76 changes: 52 additions & 24 deletions tests/test_commands.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import dataclasses
import os

import pytest

from tests import helpers
from twine import commands
from twine import exceptions

Expand Down Expand Up @@ -52,41 +52,69 @@ def test_find_dists_handles_real_files():
assert expected == files


class Signed(str):

@property
def signature(self):
return f"{self}.asc"

def attestation(self, what):
return f"{self}.{what}.attestation"


@dataclasses.dataclass
class Distribution:
name: str
version: str

@property
def sdist(self):
return Signed(f"dist/{self.name}-{self.version}.tar.gz")

@property
def wheel(self):
return Signed(f"dist/{self.name}-{self.version}-py2.py3-none-any.whl")


def test_split_inputs():
"""Split inputs into dists, signatures, and attestations."""
a = Distribution("twine", "1.5.0")
b = Distribution("twine", "1.6.5")

inputs = [
helpers.WHEEL_FIXTURE,
helpers.WHEEL_FIXTURE + ".asc",
helpers.WHEEL_FIXTURE + ".build.attestation",
helpers.WHEEL_FIXTURE + ".publish.attestation",
helpers.SDIST_FIXTURE,
helpers.SDIST_FIXTURE + ".asc",
helpers.NEW_WHEEL_FIXTURE,
helpers.NEW_WHEEL_FIXTURE + ".frob.attestation",
helpers.NEW_SDIST_FIXTURE,
a.wheel,
a.wheel.signature,
a.wheel.attestation("build"),
a.wheel.attestation("build.publish"),
a.sdist,
a.sdist.signature,
b.wheel,
b.wheel.attestation("frob"),
b.sdist,
]

inputs = commands._split_inputs(inputs)

assert inputs.dists == [
helpers.WHEEL_FIXTURE,
helpers.SDIST_FIXTURE,
helpers.NEW_WHEEL_FIXTURE,
helpers.NEW_SDIST_FIXTURE,
a.wheel,
a.sdist,
b.wheel,
b.sdist,
]

expected_signatures = {
os.path.basename(dist) + ".asc": dist + ".asc"
for dist in [helpers.WHEEL_FIXTURE, helpers.SDIST_FIXTURE]
assert inputs.signatures == {
"twine-1.5.0-py2.py3-none-any.whl.asc": a.wheel.signature,
"twine-1.5.0.tar.gz.asc": a.sdist.signature,
}
assert inputs.signatures == expected_signatures

assert inputs.attestations_by_dist == {
helpers.WHEEL_FIXTURE: [
helpers.WHEEL_FIXTURE + ".build.attestation",
helpers.WHEEL_FIXTURE + ".publish.attestation",
a.wheel: [
a.wheel.attestation("build"),
a.wheel.attestation("build.publish"),
],
a.sdist: [],
b.wheel: [
b.wheel.attestation("frob"),
],
helpers.SDIST_FIXTURE: [],
helpers.NEW_WHEEL_FIXTURE: [helpers.NEW_WHEEL_FIXTURE + ".frob.attestation"],
helpers.NEW_SDIST_FIXTURE: [],
b.sdist: [],
}
Loading