Skip to content

Commit 0ea8227

Browse files
authored
Merge pull request #80 from numpy/maint/run-ruff-on-all-dirs
MAINT: Run ruff on test file
2 parents 06f5d48 + 0e9fb51 commit 0ea8227

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

.github/workflows/lint.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,6 @@ jobs:
4848
# Tell us what version we are using
4949
poetry run ruff version
5050
# Check the source file, ignore type annotations (ANN) for now.
51-
poetry run ruff check numpy_financial/ --ignore F403,Q000,PLR0913,ERA001,TRY003,EM101,EM102,RET505,D203,D213,ANN --select ALL
51+
poetry run ruff check numpy_financial/ --ignore F403 --select E,F,B,I
52+
# Check the test file
53+
poetry run ruff check tests/ --select E,F,B,I

tests/test_financial.py

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
from decimal import Decimal
21
import math
2+
from decimal import Decimal
33

44
# Don't use 'import numpy as np', to avoid accidentally testing
55
# the versions in numpy instead of numpy_financial.
66
import numpy
7+
import pytest
78
from numpy.testing import (
8-
assert_, assert_almost_equal, assert_allclose, assert_equal, assert_raises
9+
assert_,
10+
assert_allclose,
11+
assert_almost_equal,
12+
assert_equal,
13+
assert_raises,
914
)
10-
import pytest
1115

1216
import numpy_financial as npf
1317

@@ -253,7 +257,9 @@ def test_mirr(self, values, finance_rate, reinvest_rate, expected):
253257
@pytest.mark.parametrize(
254258
"args, expected",
255259
[
256-
({'values': ['-4500', '-800', '800', '800', '600', '600', '800', '800', '700', '3000'],
260+
({'values': [
261+
'-4500', '-800', '800', '800', '600', '600', '800', '800', '700', '3000'
262+
],
257263
'finance_rate': '0.08', 'reinvest_rate': '0.055'
258264
}, '0.066597175031553548874239618'
259265
),
@@ -273,7 +279,11 @@ def test_mirr(self, values, finance_rate, reinvest_rate, expected):
273279
)
274280
def test_mirr_decimal(self, number_type, args, expected):
275281
values = [number_type(v) for v in args['values']]
276-
result = npf.mirr(values, number_type(args['finance_rate']), number_type(args['reinvest_rate']))
282+
result = npf.mirr(
283+
values,
284+
number_type(args['finance_rate']),
285+
number_type(args['reinvest_rate'])
286+
)
277287

278288
if expected is not numpy.nan:
279289
assert_almost_equal(result, number_type(expected), 15)
@@ -285,7 +295,9 @@ def test_mirr_no_real_solution_exception(self):
285295
# have the same sign, then npf.mirr returns NoRealSolutionException
286296
# when raise_exceptions is set to True.
287297
val = [39000, 30000, 21000, 37000, 46000]
288-
assert_raises(npf.NoRealSolutionError, npf.mirr, val, 0.10, 0.12, raise_exceptions=True)
298+
299+
with pytest.raises(npf.NoRealSolutionError):
300+
npf.mirr(val, 0.10, 0.12, raise_exceptions=True)
289301

290302

291303
class TestNper:
@@ -717,12 +729,15 @@ def test_irr_no_real_solution_exception(self):
717729
# have the same sign, then npf.irr returns NoRealSolutionException
718730
# when raise_exceptions is set to True.
719731
cashflows = numpy.array([40000, 5000, 8000, 12000, 30000])
720-
assert_raises(npf.NoRealSolutionError, npf.irr, cashflows, raise_exceptions=True)
732+
733+
with pytest.raises(npf.NoRealSolutionError):
734+
npf.irr(cashflows, raise_exceptions=True)
721735

722736
def test_irr_maximum_iterations_exception(self):
723737
# Test that if the maximum number of iterations is reached,
724738
# then npf.irr returns IterationsExceededException
725739
# when raise_exceptions is set to True.
726740
cashflows = numpy.array([-40000, 5000, 8000, 12000, 30000])
727-
assert_raises(npf.IterationsExceededError, npf.irr, cashflows,
728-
maxiter=1, raise_exceptions=True)
741+
742+
with pytest.raises(npf.IterationsExceededError):
743+
npf.irr(cashflows, maxiter=1, raise_exceptions=True)

0 commit comments

Comments
 (0)