mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
gh-120492: Sync importlib_metadata 8.2.0 (#124033)
* Sync with importlib_metadata 8.2.0 Removes deprecated behaviors, including support for `PackageMetadata.__getitem__` returning None for missing keys and Distribution subclasses not implementing abstract methods. Prioritizes valid dists to invalid dists when retrieving by name (python/cpython/#120492). Adds SimplePath to `importlib.metadata.__all__`. * Add blurb
This commit is contained in:
parent
d86c2257a6
commit
ec4021c6d7
8 changed files with 154 additions and 64 deletions
|
|
@ -1,10 +1,8 @@
|
|||
import re
|
||||
import pickle
|
||||
import unittest
|
||||
import warnings
|
||||
import importlib
|
||||
import importlib.metadata
|
||||
import contextlib
|
||||
from test.support import os_helper
|
||||
|
||||
try:
|
||||
|
|
@ -13,7 +11,6 @@
|
|||
from .stubs import fake_filesystem_unittest as ffs
|
||||
|
||||
from . import fixtures
|
||||
from ._context import suppress
|
||||
from ._path import Symlink
|
||||
from importlib.metadata import (
|
||||
Distribution,
|
||||
|
|
@ -28,13 +25,6 @@
|
|||
)
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def suppress_known_deprecation():
|
||||
with warnings.catch_warnings(record=True) as ctx:
|
||||
warnings.simplefilter('default', category=DeprecationWarning)
|
||||
yield ctx
|
||||
|
||||
|
||||
class BasicTests(fixtures.DistInfoPkg, unittest.TestCase):
|
||||
version_pattern = r'\d+\.\d+(\.\d)?'
|
||||
|
||||
|
|
@ -59,9 +49,6 @@ def test_package_not_found_mentions_metadata(self):
|
|||
|
||||
assert "metadata" in str(ctx.exception)
|
||||
|
||||
# expected to fail until ABC is enforced
|
||||
@suppress(AssertionError)
|
||||
@suppress_known_deprecation()
|
||||
def test_abc_enforced(self):
|
||||
with self.assertRaises(TypeError):
|
||||
type('DistributionSubclass', (Distribution,), {})()
|
||||
|
|
@ -146,6 +133,31 @@ def test_unique_distributions(self):
|
|||
assert len(after) == len(before)
|
||||
|
||||
|
||||
class InvalidMetadataTests(fixtures.OnSysPath, fixtures.SiteDir, unittest.TestCase):
|
||||
@staticmethod
|
||||
def make_pkg(name, files=dict(METADATA="VERSION: 1.0")):
|
||||
"""
|
||||
Create metadata for a dist-info package with name and files.
|
||||
"""
|
||||
return {
|
||||
f'{name}.dist-info': files,
|
||||
}
|
||||
|
||||
def test_valid_dists_preferred(self):
|
||||
"""
|
||||
Dists with metadata should be preferred when discovered by name.
|
||||
|
||||
Ref python/importlib_metadata#489.
|
||||
"""
|
||||
# create three dists with the valid one in the middle (lexicographically)
|
||||
# such that on most file systems, the valid one is never naturally first.
|
||||
fixtures.build_files(self.make_pkg('foo-4.0', files={}), self.site_dir)
|
||||
fixtures.build_files(self.make_pkg('foo-4.1'), self.site_dir)
|
||||
fixtures.build_files(self.make_pkg('foo-4.2', files={}), self.site_dir)
|
||||
dist = Distribution.from_name('foo')
|
||||
assert dist.version == "1.0"
|
||||
|
||||
|
||||
class NonASCIITests(fixtures.OnSysPath, fixtures.SiteDir, unittest.TestCase):
|
||||
@staticmethod
|
||||
def pkg_with_non_ascii_description(site_dir):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue