|
1 | 1 | import tomllib |
| 2 | +from importlib import metadata |
| 3 | + |
2 | 4 | import open_data_pvnet |
3 | 5 |
|
4 | 6 |
|
5 | 7 | def test_version_consistency(): |
6 | 8 | """ |
7 | | - Verify that the version in pyproject.toml matches the version in __init__.py |
| 9 | + Verify that the dynamic version works correctly and matches the version in __init__.py |
8 | 10 | """ |
9 | | - # Read version from pyproject.toml |
| 11 | + # Read the dynamic version configuration from pyproject.toml |
10 | 12 | with open("pyproject.toml", "rb") as f: |
11 | 13 | pyproject_data = tomllib.load(f) |
12 | | - pyproject_version = pyproject_data["project"]["version"] |
| 14 | + |
| 15 | + # Verify that dynamic versioning is configured |
| 16 | + assert "version" in pyproject_data["project"]["dynamic"], ( |
| 17 | + "Dynamic versioning should be configured in pyproject.toml" |
| 18 | + ) |
| 19 | + |
| 20 | + # Get the version from the installed package metadata |
| 21 | + try: |
| 22 | + package_version = metadata.version("open-data-pvnet") |
| 23 | + except metadata.PackageNotFoundError: |
| 24 | + # If package is not installed, skip this check |
| 25 | + package_version = None |
13 | 26 |
|
14 | 27 | # Read version from the __init__.py file |
15 | 28 | init_version = open_data_pvnet.__version__ |
16 | 29 |
|
17 | | - # Assert both versions are the same |
18 | | - assert pyproject_version == init_version, ( |
19 | | - f"Version mismatch: pyproject.toml has {pyproject_version}, " |
20 | | - f"but __init__.py has {init_version}" |
| 30 | + # If package is installed, verify versions match |
| 31 | + if package_version: |
| 32 | + assert package_version == init_version, ( |
| 33 | + f"Version mismatch: installed package has {package_version}, " |
| 34 | + f"but __init__.py has {init_version}" |
| 35 | + ) |
| 36 | + |
| 37 | + # Verify that setuptools dynamic configuration is correct |
| 38 | + dynamic_config = pyproject_data["tool"]["setuptools"]["dynamic"] |
| 39 | + assert "version" in dynamic_config, ( |
| 40 | + "Version should be configured in [tool.setuptools.dynamic]" |
| 41 | + ) |
| 42 | + assert dynamic_config["version"]["attr"] == "open_data_pvnet.__version__", ( |
| 43 | + "Dynamic version should point to open_data_pvnet.__version__" |
21 | 44 | ) |
0 commit comments