2023-01-11 15:50:27 +00:00
|
|
|
# SPDX-License-Identifier: MIT
|
|
|
|
|
2024-08-29 15:35:04 +00:00
|
|
|
|
|
|
|
from importlib import metadata
|
2023-01-11 15:50:27 +00:00
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
import attr
|
|
|
|
import attrs
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(name="mod", params=(attr, attrs))
|
|
|
|
def _mod(request):
|
2023-08-20 10:03:53 +00:00
|
|
|
return request.param
|
2023-01-11 15:50:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TestLegacyMetadataHack:
|
2023-06-13 08:02:59 +00:00
|
|
|
def test_version(self, mod, recwarn):
|
2023-01-11 15:50:27 +00:00
|
|
|
"""
|
2023-06-13 08:02:59 +00:00
|
|
|
__version__ returns the correct version and doesn't warn.
|
2023-01-11 15:50:27 +00:00
|
|
|
"""
|
2023-06-13 08:02:59 +00:00
|
|
|
assert metadata.version("attrs") == mod.__version__
|
2023-01-11 15:50:27 +00:00
|
|
|
|
2023-06-13 08:02:59 +00:00
|
|
|
assert [] == recwarn.list
|
2023-01-11 15:50:27 +00:00
|
|
|
|
|
|
|
def test_does_not_exist(self, mod):
|
|
|
|
"""
|
|
|
|
Asking for unsupported dunders raises an AttributeError.
|
|
|
|
"""
|
|
|
|
with pytest.raises(
|
|
|
|
AttributeError,
|
|
|
|
match=f"module {mod.__name__} has no attribute __yolo__",
|
|
|
|
):
|
|
|
|
mod.__yolo__
|
|
|
|
|
|
|
|
def test_version_info(self, recwarn, mod):
|
|
|
|
"""
|
2024-01-08 06:37:20 +00:00
|
|
|
___version_info__ is not deprecated, therefore doesn't raise a warning
|
2023-01-11 15:50:27 +00:00
|
|
|
and parses correctly.
|
|
|
|
"""
|
|
|
|
assert isinstance(mod.__version_info__, attr.VersionInfo)
|
|
|
|
assert [] == recwarn.list
|