diff --git a/tests/test_bdist.py b/tests/test_bdist.py deleted file mode 100644 index a7dfcab9..00000000 --- a/tests/test_bdist.py +++ /dev/null @@ -1,94 +0,0 @@ -# Copyright 2024 Daniele Nicolodi -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import os -import pathlib -import re -import zipfile - -import pytest - -from twine import bdist -from twine import exceptions - -from . import helpers - - -@pytest.fixture( - params=[ - "fixtures/twine-3.3.0-py3.9.egg", - ] -) -def example_bdist(request): - file_name = os.path.join(helpers.TESTS_DIR, request.param) - return bdist.BDist(file_name) - - -def test_read_valid(example_bdist): - """Parse metadata from a valid sdist file.""" - metadata = example_bdist.read() - assert b"Metadata-Version: 1.2" in metadata - assert b"Name: twine" in metadata - assert b"Version: 3.3.0" in metadata - - -def test_read_non_existent(): - """Raise an exception when sdist file doesn't exist.""" - file_name = str(pathlib.Path("/foo/bar/baz.egg").resolve()) - with pytest.raises( - exceptions.InvalidDistribution, match=re.escape(f"No such file: {file_name}") - ): - bdist.BDist(file_name).read() - - -def test_no_metadata(monkeypatch): - """Raise an exception when sdist does not contain PKG-INFO.""" - file_name = os.path.join(helpers.TESTS_DIR, "fixtures/twine-3.3.0-py3.9.egg") - monkeypatch.setattr(zipfile.ZipFile, "namelist", lambda x: []) - with pytest.raises( - exceptions.InvalidDistribution, match=re.escape("No PKG-INFO in archive") - ): - bdist.BDist(file_name).read() - - -def test_invalid_metadata(monkeypatch): - """Raise an exception when PKG-INFO does not contain ``Metadata-Version``.""" - monkeypatch.setattr(zipfile.ZipFile, "read", lambda x, n: b"") - file_name = os.path.join(helpers.TESTS_DIR, "fixtures/twine-3.3.0-py3.9.egg") - with pytest.raises( - exceptions.InvalidDistribution, match=re.escape("No PKG-INFO in archive") - ): - bdist.BDist(file_name).read() - - -def test_multiple_pkginfo(monkeypatch): - """Find the right PKG-INFO.""" - file_name = os.path.join(helpers.TESTS_DIR, "fixtures/twine-3.3.0-py3.9.egg") - namelist = zipfile.ZipFile.namelist - - def patch(self): - return [ - "twine-3.3.0/twine/PKG-INFO", - *namelist(self), - "twine-3.3.0/examples/PKG-INFO", - ] - - monkeypatch.setattr(zipfile.ZipFile, "namelist", patch) - metadata = bdist.BDist(file_name).read() - assert b"Metadata-Version: 1.2" in metadata - assert b"Name: twine" in metadata - assert b"Version: 3.3.0" in metadata - - -def test_py_version(example_bdist): - assert example_bdist.py_version == "3.9" diff --git a/twine/package.py b/twine/package.py index e7cb5533..80c17fe5 100644 --- a/twine/package.py +++ b/twine/package.py @@ -47,7 +47,7 @@ DIST_TYPES = { "wheel": wheel.Wheel, - "sdist": pkginfo.SDist, + "sdist": sdist.SDist, } DIST_EXTENSIONS = {