2019-05-24 20:59:01 -03:00
|
|
|
import sys
|
|
|
|
import unittest
|
|
|
|
|
2022-01-22 22:38:26 -04:00
|
|
|
from . import fixtures
|
2019-07-28 15:59:24 -03:00
|
|
|
from importlib.metadata import (
|
2020-12-31 13:56:43 -04:00
|
|
|
PackageNotFoundError,
|
|
|
|
distribution,
|
|
|
|
distributions,
|
|
|
|
entry_points,
|
|
|
|
files,
|
|
|
|
version,
|
2019-07-28 15:59:24 -03:00
|
|
|
)
|
2019-05-24 20:59:01 -03:00
|
|
|
|
2020-06-05 17:34:16 -03:00
|
|
|
|
2021-12-16 16:49:42 -04:00
|
|
|
class TestZip(fixtures.ZipFixtures, unittest.TestCase):
|
2019-05-24 20:59:01 -03:00
|
|
|
def setUp(self):
|
2021-12-16 16:49:42 -04:00
|
|
|
super().setUp()
|
2020-06-05 17:34:16 -03:00
|
|
|
self._fixture_on_path('example-21.12-py3-none-any.whl')
|
2019-05-24 20:59:01 -03:00
|
|
|
|
|
|
|
def test_zip_version(self):
|
|
|
|
self.assertEqual(version('example'), '21.12')
|
|
|
|
|
2019-07-28 15:59:24 -03:00
|
|
|
def test_zip_version_does_not_match(self):
|
|
|
|
with self.assertRaises(PackageNotFoundError):
|
|
|
|
version('definitely-not-installed')
|
|
|
|
|
2019-05-24 20:59:01 -03:00
|
|
|
def test_zip_entry_points(self):
|
2021-03-13 12:31:45 -04:00
|
|
|
scripts = entry_points(group='console_scripts')
|
2019-05-24 20:59:01 -03:00
|
|
|
entry_point = scripts['example']
|
|
|
|
self.assertEqual(entry_point.value, 'example:main')
|
2019-06-07 18:23:39 -03:00
|
|
|
entry_point = scripts['Example']
|
|
|
|
self.assertEqual(entry_point.value, 'example:main')
|
2019-05-24 20:59:01 -03:00
|
|
|
|
|
|
|
def test_missing_metadata(self):
|
|
|
|
self.assertIsNone(distribution('example').read_text('does not exist'))
|
|
|
|
|
|
|
|
def test_case_insensitive(self):
|
|
|
|
self.assertEqual(version('Example'), '21.12')
|
|
|
|
|
|
|
|
def test_files(self):
|
|
|
|
for file in files('example'):
|
|
|
|
path = str(file.dist.locate_file(file))
|
|
|
|
assert '.whl/' in path, path
|
|
|
|
|
2020-06-05 17:34:16 -03:00
|
|
|
def test_one_distribution(self):
|
|
|
|
dists = list(distributions(path=sys.path[:1]))
|
|
|
|
assert len(dists) == 1
|
|
|
|
|
2019-05-24 20:59:01 -03:00
|
|
|
|
|
|
|
class TestEgg(TestZip):
|
|
|
|
def setUp(self):
|
2021-12-16 16:49:42 -04:00
|
|
|
super().setUp()
|
2020-06-05 17:34:16 -03:00
|
|
|
self._fixture_on_path('example-21.12-py3.6.egg')
|
2019-05-24 20:59:01 -03:00
|
|
|
|
|
|
|
def test_files(self):
|
|
|
|
for file in files('example'):
|
|
|
|
path = str(file.dist.locate_file(file))
|
|
|
|
assert '.egg/' in path, path
|
2021-05-31 12:52:29 -03:00
|
|
|
|
|
|
|
def test_normalized_name(self):
|
|
|
|
dist = distribution('example')
|
|
|
|
assert dist._normalized_name == 'example'
|