Skip to content

Commit

Permalink
Fix utils tests, fallback version
Browse files Browse the repository at this point in the history
  • Loading branch information
teutoburg committed Jan 31, 2024
1 parent d266d00 commit 7ba4334
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
4 changes: 2 additions & 2 deletions scopesim/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,5 @@

try:
__version__ = metadata.version(__package__)
except:
version = 0.8
except metadata.PackageNotFoundError:
__version__ = "undetermined"

Check warning on line 69 in scopesim/__init__.py

View check run for this annotation

Codecov / codecov/patch

scopesim/__init__.py#L68-L69

Added lines #L68 - L69 were not covered by tests
26 changes: 10 additions & 16 deletions scopesim/tests/test_utils_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,29 +186,23 @@ def test_converts_dict(self):
assert utils.from_currsys({"seed": "!SIM.random.seed"})["seed"] is None

def test_converts_layered_bang_strings(self):
old = rc.__currsys__["!SIM.sub_pixel.flag"]
rc.__currsys__["!SIM.sub_pixel.flag"] = "!SIM.sub_pixel.fraction"

result = utils.from_currsys("!SIM.sub_pixel.flag")
assert not isinstance(result, str)
assert result == 1

rc.__currsys__["!SIM.sub_pixel.flag"] = old
patched = {"!SIM.sub_pixel.flag": "!SIM.sub_pixel.fraction"}
with patch.dict("scopesim.rc.__currsys__", patched):
result = utils.from_currsys("!SIM.sub_pixel.flag")
assert not isinstance(result, str)
assert result == 1

def test_converts_astropy_table(self):
tbl = Table(data=[["!SIM.random.seed"]*2, ["!SIM.random.seed"]*2],
names=["seeds", "seeds2"])
assert utils.from_currsys(tbl["seeds2"][1]) is None

def test_converts_string_numericals_to_floats(self):
old = rc.__currsys__["!SIM.sub_pixel.fraction"]
rc.__currsys__["!SIM.sub_pixel.fraction"] = "1e0"

result = utils.from_currsys("!SIM.sub_pixel.fraction")
assert isinstance(result, float)
assert result == 1

rc.__currsys__["!SIM.sub_pixel.flag"] = old
patched = {"!SIM.sub_pixel.fraction": "1e0"}
with patch.dict("scopesim.rc.__currsys__", patched):
result = utils.from_currsys("!SIM.sub_pixel.fraction")
assert isinstance(result, float)
assert result == 1


# load_example_optical_train modifies __currsys__!
Expand Down

0 comments on commit 7ba4334

Please sign in to comment.