Skip to content

Commit

Permalink
Updated test_descriptions.py to better test updateOptions and replace…
Browse files Browse the repository at this point in the history
…Options methods in ModelDescription.
  • Loading branch information
perwin committed Jun 6, 2020
1 parent 8c98133 commit 80f5b1f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
3 changes: 2 additions & 1 deletion new_notes_and_todo_for_python-wrapper_code.txt
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ bootstrap resampling) in process

[ ] Add test of replaceOptions method (ModelDescription)
[ ] Add test of replaceOptions method (SimpleModelDescription)
[ ] Add test of nParameters value (SimpleModelDescription)
[ ] Write test
[X] Add test of nParameters value (SimpleModelDescription)

[X] Add ability to get list of image-function names
-- instantiate a list of string when module is imported?
Expand Down
4 changes: 3 additions & 1 deletion pyimfit/descriptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,9 @@ def updateOptions( self, optionsDict: Dict[str,float] ):

def replaceOptions( self, optionsDict: Dict[str,float] ):
"""
Replaces the current image-descriptions dict.
Replaces the current image-descriptions dict. This differs from updateOptions()
in that it will completely replace the current image-descriptions dict,
discarding any key-value pairs with keys not in the replacement dict.
Parameters
Expand Down
24 changes: 19 additions & 5 deletions pyimfit/tests/test_descriptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,15 +360,29 @@ def test_ModelDescription_getParamLimits( self ):
pLimits = modeldesc1.getParameterLimits()
assert pLimits == [None,(180.0,220.0), None, (0.1,0.8), (10.0,1e3), (5.0,20.0)]

def testModelDescription_get_and_set_options( self ):
def testModelDescription_updateOptions( self ):
modeldesc1 = ModelDescription(self.fsetList)

assert {} == modeldesc1.optionsDict
optionsDict = {"GAIN": 4.5, "READNOISE": 0.9}
modeldesc1.updateOptions(optionsDict)
assert optionsDict == modeldesc1.optionsDict
optionsDict2 = {"GAIN": 10.5, "READNOISE": 0.9, "ORIGINAL_SKY": 45.01}
optionsDict1 = {"GAIN": 10.5, "READNOISE": 0.9, "ORIGINAL_SKY": 45.01}
modeldesc1.updateOptions(optionsDict1)
assert optionsDict1 == modeldesc1.optionsDict
# the following should *replace* the old GAIN and READNOISE values,
# but leave the ORIGINAL_SKY value unchanged
optionsDict2 = {"GAIN": 4.5, "READNOISE": 0.95}
modeldesc1.updateOptions(optionsDict2)
refDict = {"GAIN": 4.5, "READNOISE": 0.95, "ORIGINAL_SKY": 45.01}
assert refDict == modeldesc1.optionsDict

def testModelDescription_replaceOtions( self ):
modeldesc1 = ModelDescription(self.fsetList)

assert {} == modeldesc1.optionsDict
optionsDict1 = {"GAIN": 10.5, "READNOISE": 0.9, "ORIGINAL_SKY": 45.01}
modeldesc1.replaceOptions(optionsDict1)
assert optionsDict1 == modeldesc1.optionsDict
optionsDict2 = {"GAIN": 4.5, "READNOISE": 0.9}
modeldesc1.replaceOptions(optionsDict2)
assert optionsDict2 == modeldesc1.optionsDict

def test_ModelDescription_load_from_file( self ):
Expand Down

0 comments on commit 80f5b1f

Please sign in to comment.