Skip to content

Commit 67712e7

Browse files
authored
bpo-46126: Restore docstrings in importlib.metadata tests. (#32288)
1 parent 3289209 commit 67712e7

File tree

2 files changed

+44
-24
lines changed

2 files changed

+44
-24
lines changed

Lib/test/test_importlib/test_main.py

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,12 @@ def test_for_name_does_not_exist(self):
3737
Distribution.from_name('does-not-exist')
3838

3939
def test_package_not_found_mentions_metadata(self):
40-
# When a package is not found, that could indicate that the
41-
# packgae is not installed or that it is installed without
42-
# metadata. Ensure the exception mentions metadata to help
43-
# guide users toward the cause. See #124.
40+
"""
41+
When a package is not found, that could indicate that the
42+
packgae is not installed or that it is installed without
43+
metadata. Ensure the exception mentions metadata to help
44+
guide users toward the cause. See #124.
45+
"""
4446
with self.assertRaises(PackageNotFoundError) as ctx:
4547
Distribution.from_name('does-not-exist')
4648

@@ -89,8 +91,10 @@ def pkg_with_dashes(site_dir):
8991
return 'my-pkg'
9092

9193
def test_dashes_in_dist_name_found_as_underscores(self):
92-
# For a package with a dash in the name, the dist-info metadata
93-
# uses underscores in the name. Ensure the metadata loads.
94+
"""
95+
For a package with a dash in the name, the dist-info metadata
96+
uses underscores in the name. Ensure the metadata loads.
97+
"""
9498
pkg_name = self.pkg_with_dashes(self.site_dir)
9599
assert version(pkg_name) == '1.0'
96100

@@ -108,7 +112,9 @@ def pkg_with_mixed_case(site_dir):
108112
return 'CherryPy'
109113

110114
def test_dist_name_found_as_any_case(self):
111-
# Ensure the metadata loads when queried with any case.
115+
"""
116+
Ensure the metadata loads when queried with any case.
117+
"""
112118
pkg_name = self.pkg_with_mixed_case(self.site_dir)
113119
assert version(pkg_name) == '1.0'
114120
assert version(pkg_name.lower()) == '1.0'
@@ -244,11 +250,13 @@ def test_repr(self):
244250
assert "'name'" in repr(self.ep)
245251

246252
def test_hashable(self):
247-
# EntryPoints should be hashable.
253+
"""EntryPoints should be hashable"""
248254
hash(self.ep)
249255

250256
def test_json_dump(self):
251-
# json should not expect to be able to dump an EntryPoint.
257+
"""
258+
json should not expect to be able to dump an EntryPoint
259+
"""
252260
with self.assertRaises(Exception):
253261
with warnings.catch_warnings(record=True):
254262
json.dumps(self.ep)
@@ -260,7 +268,9 @@ def test_attr(self):
260268
assert self.ep.attr is None
261269

262270
def test_sortable(self):
263-
# EntryPoint objects are sortable, but result is undefined.
271+
"""
272+
EntryPoint objects are sortable, but result is undefined.
273+
"""
264274
sorted(
265275
[
266276
EntryPoint(name='b', value='val', group='group'),
@@ -273,8 +283,10 @@ class FileSystem(
273283
fixtures.OnSysPath, fixtures.SiteDir, fixtures.FileBuilder, unittest.TestCase
274284
):
275285
def test_unicode_dir_on_sys_path(self):
276-
# Ensure a Unicode subdirectory of a directory on sys.path
277-
# does not crash.
286+
"""
287+
Ensure a Unicode subdirectory of a directory on sys.path
288+
does not crash.
289+
"""
278290
fixtures.build_files(
279291
{self.unicode_filename(): {}},
280292
prefix=self.site_dir,

Lib/test/test_importlib/test_metadata_api.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,10 @@ def test_entry_points_distribution(self):
9090
self.assertEqual(ep.dist.version, "1.0.0")
9191

9292
def test_entry_points_unique_packages(self):
93-
# Entry points should only be exposed for the first package
94-
# on sys.path with a given name.
93+
"""
94+
Entry points should only be exposed for the first package
95+
on sys.path with a given name.
96+
"""
9597
alt_site_dir = self.fixtures.enter_context(fixtures.tempdir())
9698
self.fixtures.enter_context(self.add_sys_path(alt_site_dir))
9799
alt_pkg = {
@@ -123,9 +125,11 @@ def test_entry_points_missing_group(self):
123125
assert entry_points(group='missing') == ()
124126

125127
def test_entry_points_dict_construction(self):
126-
# Prior versions of entry_points() returned simple lists and
127-
# allowed casting those lists into maps by name using ``dict()``.
128-
# Capture this now deprecated use-case.
128+
"""
129+
Prior versions of entry_points() returned simple lists and
130+
allowed casting those lists into maps by name using ``dict()``.
131+
Capture this now deprecated use-case.
132+
"""
129133
with suppress_known_deprecation() as caught:
130134
eps = dict(entry_points(group='entries'))
131135

@@ -154,19 +158,23 @@ def test_entry_points_by_index(self):
154158
assert "Accessing entry points by index is deprecated" in str(expected)
155159

156160
def test_entry_points_groups_getitem(self):
157-
# Prior versions of entry_points() returned a dict. Ensure
158-
# that callers using '.__getitem__()' are supported but warned to
159-
# migrate.
161+
"""
162+
Prior versions of entry_points() returned a dict. Ensure
163+
that callers using '.__getitem__()' are supported but warned to
164+
migrate.
165+
"""
160166
with suppress_known_deprecation():
161167
entry_points()['entries'] == entry_points(group='entries')
162168

163169
with self.assertRaises(KeyError):
164170
entry_points()['missing']
165171

166172
def test_entry_points_groups_get(self):
167-
# Prior versions of entry_points() returned a dict. Ensure
168-
# that callers using '.get()' are supported but warned to
169-
# migrate.
173+
"""
174+
Prior versions of entry_points() returned a dict. Ensure
175+
that callers using '.get()' are supported but warned to
176+
migrate.
177+
"""
170178
with suppress_known_deprecation():
171179
entry_points().get('missing', 'default') == 'default'
172180
entry_points().get('entries', 'default') == entry_points()['entries']
@@ -313,7 +321,7 @@ def test_find_distributions_specified_path(self):
313321
assert any(dist.metadata['Name'] == 'distinfo-pkg' for dist in dists)
314322

315323
def test_distribution_at_pathlib(self):
316-
# Demonstrate how to load metadata direct from a directory.
324+
"""Demonstrate how to load metadata direct from a directory."""
317325
dist_info_path = self.site_dir / 'distinfo_pkg-1.0.0.dist-info'
318326
dist = Distribution.at(dist_info_path)
319327
assert dist.version == '1.0.0'

0 commit comments

Comments
 (0)