1- from decimal import Decimal
21import 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.
66import numpy
7+ import pytest
78from 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
1216import 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
291303class 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