Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix test_deprecate to work with setuptools_scm versions #461

Merged
merged 2 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 18 additions & 9 deletions tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,25 @@ def test_deprecate(self, deprecation_increment: int | None, details: str | None)

warnings.simplefilter("error")

current_version = xdem.__version__
current_version = Version(Version(xdem.__version__).base_version)

# Set the removal version to be the current version plus the increment (e.g. 0.0.5 + 1 -> 0.0.6)
removal_version = (
current_version.rsplit(".", 2)[0]
+ "."
+ str(int(current_version.rsplit(".", 2)[1]) + deprecation_increment)
if deprecation_increment is not None
else None
)
if deprecation_increment is not None:
# If the micro version is already 0 and it is a decrement, decrement minor version instead
if current_version.micro == 0 and deprecation_increment == -1:
removal_version_tuple = (current_version.major, current_version.minor + deprecation_increment, 0)
# Otherwise, increment micro version
else:
removal_version_tuple = (
current_version.major,
current_version.minor,
current_version.micro + deprecation_increment,
)

# Convert to version
removal_version = Version(".".join([str(v) for v in removal_version_tuple]))
else:
removal_version = None

# Define a function with no use that is marked as deprecated.
@xdem.misc.deprecate(removal_version, details=details) # type: ignore
Expand All @@ -81,7 +90,7 @@ def useless_func() -> int:
assert Version("0.0.10") > Version("0.0.8")

# If True, a warning is expected. If False, a ValueError is expected.
should_warn = removal_version is None or Version(removal_version) > Version(current_version)
should_warn = removal_version is None or removal_version > current_version

# Add the expected text depending on the parametrization.
text = (
Expand Down
8 changes: 6 additions & 2 deletions xdem/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def generate_random_field(shape: tuple[int, int], corr_size: int) -> NDArrayf:
return field


def deprecate(removal_version: str = None, details: str = None) -> Callable[[Any], Any]:
def deprecate(removal_version: Version = None, details: str = None) -> Callable[[Any], Any]:
"""
Trigger a DeprecationWarning for the decorated function.

Expand All @@ -88,8 +88,12 @@ def deprecate(removal_version: str = None, details: str = None) -> Callable[[Any
def deprecator_func(func: Callable[[Any], Any]) -> Callable[[Any], Any]:
@functools.wraps(func) # type: ignore
def new_func(*args: Any, **kwargs: Any) -> Any:

# Get current base version (without dev changes)
current_version = Version(Version(xdem.__version__).base_version)

# True if it should warn, False if it should raise an error
should_warn = removal_version is None or Version(removal_version) > Version(xdem.__version__)
should_warn = removal_version is None or removal_version > current_version

# Add text depending on the given arguments and 'should_warn'.
text = (
Expand Down
Loading