Skip to content

Commit

Permalink
Increase test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
maroba committed Dec 14, 2024
1 parent 898e1cd commit 848d26d
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 56 deletions.
34 changes: 8 additions & 26 deletions findiff/legacy/operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,34 +119,16 @@ def _eval_args(self, args, kwargs):
if "acc" in kwargs:
self.acc = kwargs["acc"]

if isinstance(args[0], tuple): # mixed partial derivative
pds = None

for arg in args:
if len(arg) == 3:
axis, h, order = arg
elif len(arg) == 2:
axis, h = arg
order = 1
else:
raise ValueError("Format: (axis, spacing, order=1)")
spac[axis] = h
if pds is None:
pds = _Diff(axis, order)
else:
pd = _Diff(axis, order)
pds = pds * pd
if len(args) == 3:
axis, h, order = args
elif len(args) == 2:
axis, h = args
order = 1
else:
if len(args) == 3:
axis, h, order = args
elif len(args) == 2:
axis, h = args
order = 1
else:
raise ValueError("Format: (axis, spacing, order=1)")
pds = _Diff(axis, order)
raise ValueError("Format: (axis, spacing, order=1)")
pds = _Diff(axis, order)

spac[axis] = h
spac[axis] = h

# Check if spac is really the spacing and not the coordinates (nonuniform case)
for a, s in spac.items():
Expand Down
63 changes: 33 additions & 30 deletions findiff/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,33 +41,36 @@ def to_index_tuple(long_idx, shape):
return tuple(idx)


def deprecated(reason="This feature is deprecated."):
def decorator(func_or_class):
if isinstance(func_or_class, type): # Handle classes
original_init = func_or_class.__init__

@wraps(original_init)
def new_init(self, *args, **kwargs):
warnings.warn(
f"{func_or_class.__name__} is deprecated and will be removed in future versions: {reason}",
category=DeprecationWarning,
stacklevel=2,
)
original_init(self, *args, **kwargs)

func_or_class.__init__ = new_init
return func_or_class

# Handle functions
@wraps(func_or_class)
def wrapped(*args, **kwargs):
warnings.warn(
f"{func_or_class.__name__} is deprecated: {reason}",
category=DeprecationWarning,
stacklevel=2,
)
return func_or_class(*args, **kwargs)

return wrapped

return decorator
#
# The following is working, but unused yet. Commented because there are no tests yet.
#
# def deprecated(reason="This feature is deprecated."):
# def decorator(func_or_class):
# if isinstance(func_or_class, type): # Handle classes
# original_init = func_or_class.__init__
#
# @wraps(original_init)
# def new_init(self, *args, **kwargs):
# warnings.warn(
# f"{func_or_class.__name__} is deprecated and will be removed in future versions: {reason}",
# category=DeprecationWarning,
# stacklevel=2,
# )
# original_init(self, *args, **kwargs)
#
# func_or_class.__init__ = new_init
# return func_or_class
#
# # Handle functions
# @wraps(func_or_class)
# def wrapped(*args, **kwargs):
# warnings.warn(
# f"{func_or_class.__name__} is deprecated: {reason}",
# category=DeprecationWarning,
# stacklevel=2,
# )
# return func_or_class(*args, **kwargs)
#
# return wrapped
#
# return decorator
5 changes: 5 additions & 0 deletions tests/test_coefs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import unittest

import numpy as np
import pytest
from sympy import Rational

from findiff import coefficients
Expand Down Expand Up @@ -169,6 +170,10 @@ def test_calc_coefs_from_offsets_no_central_point(self):
coefs["coefficients"], [-1.0 / 4, 0, 1.0 / 4]
)

def test_calc_coefs_from_offsets_not_enough_points(self):
with pytest.raises(ValueError):
coefficients(2, offsets=[-2, 2], analytic_inv=False)

def test_calc_coefs_symbolic(self):
for analytic_inv in [True, False]:
coefs = calc_coefs(1, [-2, 0, 1], symbolic=True, analytic_inv=analytic_inv)
Expand Down

0 comments on commit 848d26d

Please sign in to comment.