44import numpy as np
55import pandas as pd
66
7- from nose .tools import raises
8- from nose .tools import assert_almost_equals
7+ import pytest
98from numpy .testing import assert_allclose
109
1110from pvlib .location import Location
3029def test_pres2alt ():
3130 atmosphere .pres2alt (100000 )
3231
32+
3333def test_alt2press ():
3434 atmosphere .pres2alt (1000 )
3535
3636
37- # two functions combined will generate unique unit tests for each model
38- def test_airmasses ():
39- models = ['simple' , 'kasten1966' , 'youngirvine1967' , 'kastenyoung1989' ,
40- 'gueymard1993' , 'young1994' , 'pickering2002' ]
41- for model in models :
42- yield run_airmass , model , ephem_data ['zenith' ]
43-
44-
45- def run_airmass (model , zenith ):
46- atmosphere .relativeairmass (zenith , model )
37+ @pytest .mark .parametrize ("model" ,
38+ ['simple' , 'kasten1966' , 'youngirvine1967' , 'kastenyoung1989' ,
39+ 'gueymard1993' , 'young1994' , 'pickering2002' ])
40+ def test_airmass (model ):
41+ atmosphere .relativeairmass (ephem_data ['zenith' ], model )
4742
4843
49- @raises (ValueError )
5044def test_airmass_invalid ():
51- atmosphere .relativeairmass (ephem_data ['zenith' ], 'invalid' )
45+ with pytest .raises (ValueError ):
46+ atmosphere .relativeairmass (ephem_data ['zenith' ], 'invalid' )
5247
5348
5449def test_absoluteairmass ():
@@ -79,31 +74,26 @@ def test_gueymard94_pw():
7974 assert_allclose (pws , expected , atol = 0.01 )
8075
8176
82- def test_first_solar_spectral_correction ():
83- ams = np .array ([1 , 3 , 5 ])
84- pws = np .array ([1 , 3 , 5 ])
85- ams , pws = np .meshgrid (ams , pws )
86-
87- expect = {}
88- expect ['cdte' ] = np .array (
77+ @pytest .mark .parametrize ("module_type,expect" , [
78+ ('cdte' , np .array (
8979 [[ 0.99134828 , 0.97701063 , 0.93975103 ],
9080 [ 1.02852847 , 1.01874908 , 0.98604776 ],
91- [ 1.04722476 , 1.03835703 , 1.00656735 ]])
92- expect [ 'monosi' ] = np .array (
81+ [ 1.04722476 , 1.03835703 , 1.00656735 ]])),
82+ ( 'monosi' , np .array (
9383 [[ 0.9782842 , 1.02092726 , 1.03602157 ],
9484 [ 0.9859024 , 1.0302268 , 1.04700244 ],
95- [ 0.98885429 , 1.03351495 , 1.05062687 ]])
96- expect [ 'polysi' ] = np .array (
85+ [ 0.98885429 , 1.03351495 , 1.05062687 ]])),
86+ ( 'polysi' , np .array (
9787 [[ 0.9774921 , 1.01757872 , 1.02649543 ],
9888 [ 0.98947361 , 1.0314545 , 1.04226547 ],
99- [ 0.99403107 , 1.03639082 , 1.04758064 ]])
100-
101- def run_fs_test (module_type ):
102- out = atmosphere . first_solar_spectral_correction ( pws , ams , module_type )
103- assert_allclose ( out , expect [ module_type ], atol = 0.001 )
104-
105- for module_type in expect . keys ():
106- yield run_fs_test , module_type
89+ [ 0.99403107 , 1.03639082 , 1.04758064 ]]))
90+ ])
91+ def test_first_solar_spectral_correction (module_type , expect ):
92+ ams = np . array ([ 1 , 3 , 5 ] )
93+ pws = np . array ([ 1 , 3 , 5 ] )
94+ ams , pws = np . meshgrid ( ams , pws )
95+ out = atmosphere . first_solar_spectral_correction ( pws , ams , module_type )
96+ assert_allclose ( out , expect , atol = 0.001 )
10797
10898
10999def test_first_solar_spectral_correction_supplied ():
@@ -114,6 +104,6 @@ def test_first_solar_spectral_correction_supplied():
114104 assert_allclose (out , expected , atol = 1e-3 )
115105
116106
117- @raises (TypeError )
118107def test_first_solar_spectral_correction_ambiguous ():
119- atmosphere .first_solar_spectral_correction (1 , 1 )
108+ with pytest .raises (TypeError ):
109+ atmosphere .first_solar_spectral_correction (1 , 1 )
0 commit comments