test_metadata.py 1010 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import importlib.metadata as im
  2. import pytest
  3. @pytest.mark.parametrize("name", ("foo-bar", "foo_bar", "Foo-Bar"))
  4. def test_distribution(name):
  5. assert im.distribution(name) is not None
  6. def test_unknown_package():
  7. with pytest.raises(im.PackageNotFoundError):
  8. im.distribution("bar")
  9. def test_version():
  10. assert im.version("foo-bar") == "1.2.3"
  11. def test_metadata():
  12. assert im.metadata("foo-bar") is not None
  13. def test_files():
  14. files = im.files("foo-bar")
  15. assert len(files) == 1
  16. assert files[0].name == "foo_bar.py"
  17. assert files[0].size == 20
  18. def test_requires():
  19. assert im.requires("foo-bar") == ["Werkzeug (>=0.15)", "Jinja2 (>=2.10.1)"]
  20. def test_entry_points():
  21. entry_points = im.entry_points()
  22. assert "console_scripts" in entry_points
  23. flg_found = False
  24. for entry_point in entry_points["console_scripts"]:
  25. if entry_point.name == "foo_cli" and entry_point.value == "foo_bar:cli":
  26. flg_found = True
  27. assert flg_found