diff options
author | Jason R. Coombs <jaraco@jaraco.com> | 2019-07-28 18:59:24 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-07-28 18:59:24 (GMT) |
commit | 049460da9c7b5f51732e2966195c44713af9dc4c (patch) | |
tree | 5fb30710967235710cb665d70218a8633ccdffc3 /Lib/test/test_importlib | |
parent | b222955355c8077a3ceca79195731663d7c3dd5f (diff) | |
download | cpython-049460da9c7b5f51732e2966195c44713af9dc4c.zip cpython-049460da9c7b5f51732e2966195c44713af9dc4c.tar.gz cpython-049460da9c7b5f51732e2966195c44713af9dc4c.tar.bz2 |
bpo-37697: Sync with importlib_metadata 0.19 (#14993)
* bpo-37697: Sync with importlib_metadata 0.19
* Run make regen-importlib
* 📜🤖 Added by blurb_it.
Diffstat (limited to 'Lib/test/test_importlib')
-rw-r--r-- | Lib/test/test_importlib/fixtures.py | 1 | ||||
-rw-r--r-- | Lib/test/test_importlib/test_main.py | 19 | ||||
-rw-r--r-- | Lib/test/test_importlib/test_zip.py | 8 |
3 files changed, 24 insertions, 4 deletions
diff --git a/Lib/test/test_importlib/fixtures.py b/Lib/test/test_importlib/fixtures.py index 3b926ba..0b4ce18 100644 --- a/Lib/test/test_importlib/fixtures.py +++ b/Lib/test/test_importlib/fixtures.py @@ -83,6 +83,7 @@ class DistInfoPkg(OnSysPath, SiteDir): "entry_points.txt": """ [entries] main = mod:main + ns:sub = mod:main """ }, "mod.py": """ diff --git a/Lib/test/test_importlib/test_main.py b/Lib/test/test_importlib/test_main.py index 5e2cb26..bc42b83 100644 --- a/Lib/test/test_importlib/test_main.py +++ b/Lib/test/test_importlib/test_main.py @@ -32,7 +32,7 @@ class BasicTests(fixtures.DistInfoPkg, unittest.TestCase): class ImportTests(fixtures.DistInfoPkg, unittest.TestCase): def test_import_nonexistent_module(self): # Ensure that the MetadataPathFinder does not crash an import of a - # nonexistent module. + # non-existant module. with self.assertRaises(ImportError): importlib.import_module('does_not_exist') @@ -41,6 +41,11 @@ class ImportTests(fixtures.DistInfoPkg, unittest.TestCase): ep = entries['main'] self.assertEqual(ep.load().__name__, "main") + def test_entrypoint_with_colon_in_name(self): + entries = dict(entry_points()['entries']) + ep = entries['ns:sub'] + self.assertEqual(ep.value, 'mod:main') + def test_resolve_without_attr(self): ep = EntryPoint( name='ep', @@ -159,8 +164,16 @@ class DiscoveryTests(fixtures.EggInfoPkg, class DirectoryTest(fixtures.OnSysPath, fixtures.SiteDir, unittest.TestCase): - def test(self): + def test_egg_info(self): # make an `EGG-INFO` directory that's unrelated self.site_dir.joinpath('EGG-INFO').mkdir() # used to crash with `IsADirectoryError` - self.assertIsNone(version('unknown-package')) + with self.assertRaises(PackageNotFoundError): + version('unknown-package') + + def test_egg(self): + egg = self.site_dir.joinpath('foo-3.6.egg') + egg.mkdir() + with self.add_sys_path(egg): + with self.assertRaises(PackageNotFoundError): + version('foo') diff --git a/Lib/test/test_importlib/test_zip.py b/Lib/test/test_importlib/test_zip.py index bcf7cf3..9568c22 100644 --- a/Lib/test/test_importlib/test_zip.py +++ b/Lib/test/test_importlib/test_zip.py @@ -2,7 +2,9 @@ import sys import unittest from contextlib import ExitStack -from importlib.metadata import distribution, entry_points, files, version +from importlib.metadata import ( + distribution, entry_points, files, PackageNotFoundError, version, +) from importlib.resources import path @@ -22,6 +24,10 @@ class TestZip(unittest.TestCase): def test_zip_version(self): self.assertEqual(version('example'), '21.12') + def test_zip_version_does_not_match(self): + with self.assertRaises(PackageNotFoundError): + version('definitely-not-installed') + def test_zip_entry_points(self): scripts = dict(entry_points()['console_scripts']) entry_point = scripts['example'] |