summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_importlib
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2021-05-02 21:03:40 (GMT)
committerGitHub <noreply@github.com>2021-05-02 21:03:40 (GMT)
commit37e0c7850de902179b28f1378fbbc38a5ed3628c (patch)
treeecc352d5d7eaf99485bc4c2735d2a5f14f532084 /Lib/test/test_importlib
parent0ad1e0384c8afc5259a6d03363491d89500a5d03 (diff)
downloadcpython-37e0c7850de902179b28f1378fbbc38a5ed3628c.zip
cpython-37e0c7850de902179b28f1378fbbc38a5ed3628c.tar.gz
cpython-37e0c7850de902179b28f1378fbbc38a5ed3628c.tar.bz2
bpo-43926: Cleaner metadata with PEP 566 JSON support. (GH-25565)
* bpo-43926: Cleaner metadata with PEP 566 JSON support. * Add blurb * Add versionchanged and versionadded declarations for changes to metadata. * Use descriptor for PEP 566
Diffstat (limited to 'Lib/test/test_importlib')
-rw-r--r--Lib/test/test_importlib/fixtures.py11
-rw-r--r--Lib/test/test_importlib/test_main.py6
-rw-r--r--Lib/test/test_importlib/test_metadata_api.py23
3 files changed, 37 insertions, 3 deletions
diff --git a/Lib/test/test_importlib/fixtures.py b/Lib/test/test_importlib/fixtures.py
index 1ae70c7..12ed07d 100644
--- a/Lib/test/test_importlib/fixtures.py
+++ b/Lib/test/test_importlib/fixtures.py
@@ -1,5 +1,6 @@
import os
import sys
+import copy
import shutil
import pathlib
import tempfile
@@ -108,6 +109,16 @@ class DistInfoPkg(OnSysPath, SiteDir):
super(DistInfoPkg, self).setUp()
build_files(DistInfoPkg.files, self.site_dir)
+ def make_uppercase(self):
+ """
+ Rewrite metadata with everything uppercase.
+ """
+ shutil.rmtree(self.site_dir / "distinfo_pkg-1.0.0.dist-info")
+ files = copy.deepcopy(DistInfoPkg.files)
+ info = files["distinfo_pkg-1.0.0.dist-info"]
+ info["METADATA"] = info["METADATA"].upper()
+ build_files(files, self.site_dir)
+
class DistInfoPkgWithDot(OnSysPath, SiteDir):
files: FilesDef = {
diff --git a/Lib/test/test_importlib/test_main.py b/Lib/test/test_importlib/test_main.py
index 08069c9..52cb637 100644
--- a/Lib/test/test_importlib/test_main.py
+++ b/Lib/test/test_importlib/test_main.py
@@ -125,7 +125,7 @@ class NonASCIITests(fixtures.OnSysPath, fixtures.SiteDir, unittest.TestCase):
metadata_dir.mkdir()
metadata = metadata_dir / 'METADATA'
with metadata.open('w', encoding='utf-8') as fp:
- fp.write('Description: pôrˈtend\n')
+ fp.write('Description: pôrˈtend')
return 'portend'
@staticmethod
@@ -145,7 +145,7 @@ class NonASCIITests(fixtures.OnSysPath, fixtures.SiteDir, unittest.TestCase):
pôrˈtend
"""
- ).lstrip()
+ ).strip()
)
return 'portend'
@@ -157,7 +157,7 @@ class NonASCIITests(fixtures.OnSysPath, fixtures.SiteDir, unittest.TestCase):
def test_metadata_loads_egg_info(self):
pkg_name = self.pkg_with_non_ascii_description_egg_info(self.site_dir)
meta = metadata(pkg_name)
- assert meta.get_payload() == 'pôrˈtend\n'
+ assert meta['Description'] == 'pôrˈtend'
class DiscoveryTests(fixtures.EggInfoPkg, fixtures.DistInfoPkg, unittest.TestCase):
diff --git a/Lib/test/test_importlib/test_metadata_api.py b/Lib/test/test_importlib/test_metadata_api.py
index 657c166..825edc1 100644
--- a/Lib/test/test_importlib/test_metadata_api.py
+++ b/Lib/test/test_importlib/test_metadata_api.py
@@ -231,6 +231,29 @@ class APITests(
assert deps == expected
+ def test_as_json(self):
+ md = metadata('distinfo-pkg').json
+ assert 'name' in md
+ assert md['keywords'] == ['sample', 'package']
+ desc = md['description']
+ assert desc.startswith('Once upon a time\nThere was')
+ assert len(md['requires_dist']) == 2
+
+ def test_as_json_egg_info(self):
+ md = metadata('egginfo-pkg').json
+ assert 'name' in md
+ assert md['keywords'] == ['sample', 'package']
+ desc = md['description']
+ assert desc.startswith('Once upon a time\nThere was')
+ assert len(md['classifier']) == 2
+
+ def test_as_json_odd_case(self):
+ self.make_uppercase()
+ md = metadata('distinfo-pkg').json
+ assert 'name' in md
+ assert len(md['requires_dist']) == 2
+ assert md['keywords'] == ['SAMPLE', 'PACKAGE']
+
class LegacyDots(fixtures.DistInfoPkgWithDotLegacy, unittest.TestCase):
def test_name_normalization(self):