66from scopesim import UserCommands
77from scopesim .optics .image_plane import ImagePlane
88from scopesim .effects .electronic import AutoExposure
9- from scopesim .utils import from_currsys
109
1110from scopesim .tests .mocks .py_objects .imagehdu_objects import _image_hdu_square
1211
@@ -28,7 +27,7 @@ def fixture_imageplane():
2827 return implane
2928
3029
31- @pytest .fixture (name = "autoexposure" , scope = "class " )
30+ @pytest .fixture (name = "autoexposure" , scope = "function " )
3231def fixture_autoexposure ():
3332 """Instantiate an AutoExposure object"""
3433 return AutoExposure (fill_frac = 0.75 ,
@@ -45,8 +44,8 @@ def test_initialises_correctly(self):
4544 assert isinstance (autoexposure , AutoExposure )
4645
4746 def test_returns_imageplane (self , autoexposure , imageplane ):
48- with patch ( "scopesim.rc.__currsys__" , _patched_cmds ()):
49- outimpl = autoexposure .apply_to (imageplane )
47+ autoexposure . cmds = _patched_cmds ()
48+ outimpl = autoexposure .apply_to (imageplane )
5049
5150 assert isinstance (outimpl , ImagePlane )
5251
@@ -59,24 +58,24 @@ def test_produces_correct_values(self, autoexposure, imageplane):
5958 ref_dit = 0.75
6059
6160 # TODO: Change AutoExposure to read exptime like dit and ndit
62- with patch ( "scopesim.rc.__currsys__" , _patched_cmds (exptime = exptime )):
63- autoexposure .apply_to (imageplane )
61+ autoexposure . cmds = _patched_cmds (exptime = exptime )
62+ autoexposure .apply_to (imageplane )
6463
65- out_dit = from_currsys ( "!OBS.dit" )
66- out_ndit = from_currsys ( "!OBS.ndit" )
64+ out_dit = autoexposure . cmds [ "!OBS.dit" ]
65+ out_ndit = autoexposure . cmds [ "!OBS.ndit" ]
6766
6867 assert out_dit == pytest .approx (ref_dit )
6968 assert out_dit * out_ndit == pytest .approx (exptime )
7069
7170 def test_detects_saturation (self , imageplane ):
7271 mindit = 0.011
73- with patch ( "scopesim.rc.__currsys__" , _patched_cmds ( exptime = 100. )):
74- autoexposure = AutoExposure ( fill_frac = 0.75 ,
75- full_well = 10. ,
76- mindit = mindit )
77- autoexposure .apply_to (imageplane )
72+ autoexposure = AutoExposure ( fill_frac = 0.75 ,
73+ full_well = 10. ,
74+ mindit = mindit ,
75+ cmds = _patched_cmds ( exptime = 100. ) )
76+ autoexposure .apply_to (imageplane )
7877
79- out_dit = from_currsys ( "!OBS.dit" )
78+ out_dit = autoexposure . cmds [ "!OBS.dit" ]
8079
8180 assert out_dit == mindit
8281
@@ -85,19 +84,19 @@ def test_fill_frac_acts_correctly(self, imageplane):
8584 fill_2 = 0.5
8685 autoexp_1 = AutoExposure (fill_frac = fill_1 ,
8786 full_well = 1e5 ,
88- mindit = 0.011 )
89- with patch ( "scopesim.rc.__currsys__" , _patched_cmds ()):
90- autoexp_1 .apply_to (imageplane )
91- out_dit_1 = from_currsys ( "!OBS.dit" )
92- out_ndit_1 = from_currsys ( "!OBS.ndit" )
87+ mindit = 0.011 ,
88+ cmds = _patched_cmds ())
89+ autoexp_1 .apply_to (imageplane )
90+ out_dit_1 = autoexp_1 . cmds [ "!OBS.dit" ]
91+ out_ndit_1 = autoexp_1 . cmds [ "!OBS.ndit" ]
9392
9493 autoexp_2 = AutoExposure (fill_frac = fill_2 ,
9594 full_well = 1e5 ,
96- mindit = 0.011 )
97- with patch ( "scopesim.rc.__currsys__" , _patched_cmds ()):
98- autoexp_2 .apply_to (imageplane )
99- out_dit_2 = from_currsys ( "!OBS.dit" )
100- out_ndit_2 = from_currsys ( "!OBS.ndit" )
95+ mindit = 0.011 ,
96+ cmds = _patched_cmds ())
97+ autoexp_2 .apply_to (imageplane )
98+ out_dit_2 = autoexp_2 . cmds [ "!OBS.dit" ]
99+ out_ndit_2 = autoexp_2 . cmds [ "!OBS.ndit" ]
101100
102101 assert out_dit_1 == fill_1 / fill_2 * out_dit_2
103102 assert out_ndit_1 == fill_2 / fill_1 * out_ndit_2
@@ -108,17 +107,18 @@ def test_exptime_specified_by_dit_ndit(self, autoexposure, imageplane):
108107 instead of `!OBS.exptime`.
109108 """
110109 # 1. use exptime
111- with patch ( "scopesim.rc.__currsys__" , _patched_cmds ( exptime = 10. )):
112- autoexposure .apply_to (imageplane )
113- dit_1 = from_currsys ( "!OBS.dit" )
114- ndit_1 = from_currsys ( "!OBS.ndit" )
110+ autoexposure . cmds [ "!OBS.exptime" ] = 10.0
111+ autoexposure .apply_to (imageplane )
112+ dit_1 = autoexposure . cmds [ "!OBS.dit" ]
113+ ndit_1 = autoexposure . cmds [ "!OBS.ndit" ]
115114
116115 # 2. use dit and ndit
117- with patch ("scopesim.rc.__currsys__" ,
118- _patched_cmds (exptime = None , dit = 5 , ndit = 2 )):
119- autoexposure .apply_to (imageplane )
120- dit_2 = from_currsys ("!OBS.dit" )
121- ndit_2 = from_currsys ("!OBS.ndit" )
116+ autoexposure .cmds ["!OBS.exptime" ] = None
117+ autoexposure .cmds ["!OBS.dit" ] = 5
118+ autoexposure .cmds ["!OBS.ndit" ] = 2
119+ autoexposure .apply_to (imageplane )
120+ dit_2 = autoexposure .cmds ["!OBS.dit" ]
121+ ndit_2 = autoexposure .cmds ["!OBS.ndit" ]
122122
123123 assert dit_1 == dit_2
124124 assert ndit_1 == ndit_2
@@ -129,10 +129,10 @@ def test_exptime_at_least_mindit(self, imageplane):
129129 autoexposure = AutoExposure (fill_frac = 0.75 ,
130130 full_well = 1e5 ,
131131 mindit = mindit )
132- with patch ( "scopesim.rc.__currsys__" , _patched_cmds ( exptime = exptime )):
133- autoexposure .apply_to (imageplane )
134- dit = from_currsys ( "!OBS.dit" )
135- ndit = from_currsys ( "!OBS.ndit" )
132+ autoexposure . cmds [ "!OBS.exptime" ] = exptime
133+ autoexposure .apply_to (imageplane )
134+ dit = autoexposure . cmds [ "!OBS.dit" ]
135+ ndit = autoexposure . cmds [ "!OBS.ndit" ]
136136
137137 assert dit == mindit
138138 assert ndit == 1
0 commit comments