From 7ba43343507b8ff50e23229ae622b534a5bdb2cf Mon Sep 17 00:00:00 2001 From: teutoburg Date: Wed, 31 Jan 2024 12:14:02 +0100 Subject: [PATCH] Fix utils tests, fallback version --- scopesim/__init__.py | 4 ++-- scopesim/tests/test_utils_functions.py | 26 ++++++++++---------------- 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/scopesim/__init__.py b/scopesim/__init__.py index b30d4ec1..334da299 100644 --- a/scopesim/__init__.py +++ b/scopesim/__init__.py @@ -65,5 +65,5 @@ try: __version__ = metadata.version(__package__) -except: - version = 0.8 +except metadata.PackageNotFoundError: + __version__ = "undetermined" diff --git a/scopesim/tests/test_utils_functions.py b/scopesim/tests/test_utils_functions.py index adb994f2..6f5ff8bb 100644 --- a/scopesim/tests/test_utils_functions.py +++ b/scopesim/tests/test_utils_functions.py @@ -186,14 +186,11 @@ 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], @@ -201,14 +198,11 @@ def test_converts_astropy_table(self): 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__!