1
- from decimal import Decimal
2
1
import math
2
+ from decimal import Decimal
3
3
4
4
# Don't use 'import numpy as np', to avoid accidentally testing
5
5
# the versions in numpy instead of numpy_financial.
6
6
import numpy
7
+ import pytest
7
8
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 ,
9
14
)
10
- import pytest
11
15
12
16
import numpy_financial as npf
13
17
@@ -253,7 +257,9 @@ def test_mirr(self, values, finance_rate, reinvest_rate, expected):
253
257
@pytest .mark .parametrize (
254
258
"args, expected" ,
255
259
[
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
+ ],
257
263
'finance_rate' : '0.08' , 'reinvest_rate' : '0.055'
258
264
}, '0.066597175031553548874239618'
259
265
),
@@ -273,7 +279,11 @@ def test_mirr(self, values, finance_rate, reinvest_rate, expected):
273
279
)
274
280
def test_mirr_decimal (self , number_type , args , expected ):
275
281
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
+ )
277
287
278
288
if expected is not numpy .nan :
279
289
assert_almost_equal (result , number_type (expected ), 15 )
@@ -285,7 +295,9 @@ def test_mirr_no_real_solution_exception(self):
285
295
# have the same sign, then npf.mirr returns NoRealSolutionException
286
296
# when raise_exceptions is set to True.
287
297
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 )
289
301
290
302
291
303
class TestNper :
@@ -717,12 +729,15 @@ def test_irr_no_real_solution_exception(self):
717
729
# have the same sign, then npf.irr returns NoRealSolutionException
718
730
# when raise_exceptions is set to True.
719
731
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 )
721
735
722
736
def test_irr_maximum_iterations_exception (self ):
723
737
# Test that if the maximum number of iterations is reached,
724
738
# then npf.irr returns IterationsExceededException
725
739
# when raise_exceptions is set to True.
726
740
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