Skip to content

MAINT: Run ruff on test file #80

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

Merged
merged 4 commits into from
Nov 22, 2023
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
4 changes: 3 additions & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
33 changes: 24 additions & 9 deletions tests/test_financial.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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'
),
Expand All @@ -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)
Expand All @@ -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:
Expand Down Expand Up @@ -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)