test_zip.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import sys
  2. import unittest
  3. import importlib_metadata
  4. from importlib_resources import path
  5. try:
  6. from contextlib import ExitStack
  7. except ImportError:
  8. from contextlib2 import ExitStack
  9. class BespokeLoader:
  10. archive = 'bespoke'
  11. class TestZip(unittest.TestCase):
  12. def setUp(self):
  13. # Find the path to the example.*.whl so we can add it to the front of
  14. # sys.path, where we'll then try to find the metadata thereof.
  15. self.resources = ExitStack()
  16. self.addCleanup(self.resources.close)
  17. wheel = self.resources.enter_context(
  18. path('importlib_metadata.tests.data',
  19. 'example-21.12-py3-none-any.whl'))
  20. sys.path.insert(0, str(wheel))
  21. self.resources.callback(sys.path.pop, 0)
  22. def test_zip_version(self):
  23. self.assertEqual(importlib_metadata.version('example'), '21.12')
  24. def test_zip_entry_points(self):
  25. scripts = dict(importlib_metadata.entry_points()['console_scripts'])
  26. entry_point = scripts['example']
  27. self.assertEqual(entry_point.value, 'example:main')
  28. def test_missing_metadata(self):
  29. distribution = importlib_metadata.distribution('example')
  30. self.assertIsNone(distribution.read_text('does not exist'))
  31. def test_case_insensitive(self):
  32. self.assertEqual(importlib_metadata.version('Example'), '21.12')
  33. def test_files(self):
  34. files = importlib_metadata.files('example')
  35. for file in files:
  36. path = str(file.dist.locate_file(file))
  37. assert '.whl/' in path, path