diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 82df604..47f1db9 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -48,4 +48,6 @@ jobs: # Tell us what version we are using poetry run ruff version # Check the source file, ignore type annotations (ANN) for now. - poetry run ruff check numpy_financial/ --ignore F403,Q000,PLR0913,ERA001,TRY003,EM101,EM102,RET505,D203,D213,ANN --select ALL + poetry run ruff check numpy_financial/ --ignore F403 --select E,F,B,I + # Check the test file + poetry run ruff check tests/ --select E,F,B,I diff --git a/tests/test_financial.py b/tests/test_financial.py index d6986de..ad01952 100644 --- a/tests/test_financial.py +++ b/tests/test_financial.py @@ -1,13 +1,17 @@ -from decimal import Decimal import math +from decimal import Decimal # Don't use 'import numpy as np', to avoid accidentally testing # the versions in numpy instead of numpy_financial. import numpy +import pytest from numpy.testing import ( - assert_, assert_almost_equal, assert_allclose, assert_equal, assert_raises + assert_, + assert_allclose, + assert_almost_equal, + assert_equal, + assert_raises, ) -import pytest import numpy_financial as npf @@ -253,7 +257,9 @@ def test_mirr(self, values, finance_rate, reinvest_rate, expected): @pytest.mark.parametrize( "args, expected", [ - ({'values': ['-4500', '-800', '800', '800', '600', '600', '800', '800', '700', '3000'], + ({'values': [ + '-4500', '-800', '800', '800', '600', '600', '800', '800', '700', '3000' + ], 'finance_rate': '0.08', 'reinvest_rate': '0.055' }, '0.066597175031553548874239618' ), @@ -273,7 +279,11 @@ def test_mirr(self, values, finance_rate, reinvest_rate, expected): ) def test_mirr_decimal(self, number_type, args, expected): values = [number_type(v) for v in args['values']] - result = npf.mirr(values, number_type(args['finance_rate']), number_type(args['reinvest_rate'])) + result = npf.mirr( + values, + number_type(args['finance_rate']), + number_type(args['reinvest_rate']) + ) if expected is not numpy.nan: assert_almost_equal(result, number_type(expected), 15) @@ -285,7 +295,9 @@ def test_mirr_no_real_solution_exception(self): # have the same sign, then npf.mirr returns NoRealSolutionException # when raise_exceptions is set to True. val = [39000, 30000, 21000, 37000, 46000] - assert_raises(npf.NoRealSolutionError, npf.mirr, val, 0.10, 0.12, raise_exceptions=True) + + with pytest.raises(npf.NoRealSolutionError): + npf.mirr(val, 0.10, 0.12, raise_exceptions=True) class TestNper: @@ -717,12 +729,15 @@ def test_irr_no_real_solution_exception(self): # have the same sign, then npf.irr returns NoRealSolutionException # when raise_exceptions is set to True. cashflows = numpy.array([40000, 5000, 8000, 12000, 30000]) - assert_raises(npf.NoRealSolutionError, npf.irr, cashflows, raise_exceptions=True) + + with pytest.raises(npf.NoRealSolutionError): + npf.irr(cashflows, raise_exceptions=True) def test_irr_maximum_iterations_exception(self): # Test that if the maximum number of iterations is reached, # then npf.irr returns IterationsExceededException # when raise_exceptions is set to True. cashflows = numpy.array([-40000, 5000, 8000, 12000, 30000]) - assert_raises(npf.IterationsExceededError, npf.irr, cashflows, - maxiter=1, raise_exceptions=True) + + with pytest.raises(npf.IterationsExceededError): + npf.irr(cashflows, maxiter=1, raise_exceptions=True)