Skip to content

Commit

Permalink
Add tests and fix forgotten log arg
Browse files Browse the repository at this point in the history
Turns out, codecov is useful after all...
  • Loading branch information
teutoburg committed Nov 20, 2024
1 parent c689b9e commit 4192891
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 3 deletions.
3 changes: 2 additions & 1 deletion scopesim/commands/user_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,8 @@ def set_modes(self, *modes) -> None:
# or rather warning?
logger.info(
"Mode '%s' is still in experimental stage, results "
"may not be representative of physical instrument."
"may not be representative of physical instrument.",
mode
)

if self.modes_dict[mode].get("status") == "concept":
Expand Down
23 changes: 22 additions & 1 deletion scopesim/tests/mocks/basic_instrument/default.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Default config file for setting up the instrument
object : observation
object: configuration
alias : OBS
name : test_instrument
description : default parameters needed for a basic simulation
status: development

packages :
- basic_instrument # name of package dependencies
Expand All @@ -24,6 +25,7 @@ properties :
mode_yamls :
- name : imaging
description: Basic NIR imager
status: development
alias : OBS
properties :
include_slit : False
Expand All @@ -32,6 +34,7 @@ mode_yamls :

- name : spectroscopy
description: Basic three-trace long-slit spectrograph
status: development
alias: OBS
properties :
include_slit : True
Expand All @@ -42,10 +45,28 @@ mode_yamls :

- name : ifu
description: Basic three-trace integral-field-unit spectrograph
status: development
alias: OBS
properties:
include_slit: False
include_slicer: True
filter_name: "open"
yamls:
- YAML_mode_ifu.yaml # mode specific effects and properties

- name: mock_concept_mode
description: Dummy mode to test concept status.
status: concept

- name: mock_experimental_mode
description: Dummy mode to test experimental status.
status: experimental

- name: mock_deprecated_mode
description: Dummy mode to test deprecated status without message.
status: deprecated

- name: mock_deprecated_mode_msg
description: Dummy mode to test deprecated status with message.
status: deprecated
deprecate: This mode is deprecated.
54 changes: 53 additions & 1 deletion scopesim/tests/test_basic_instrument/test_basic_instrument.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

# -*- coding: utf-8 -*-
import pytest

import numpy as np
Expand Down Expand Up @@ -116,6 +116,7 @@ def test_runs(self):
trace_flux = det_im[:, sl].sum() # sum along a trace
assert round(trace_flux / spot_flux) == n


@pytest.mark.usefixtures("protect_currsys", "patch_all_mock_paths")
class TestSourceImageNotAffected:
"""
Expand Down Expand Up @@ -228,6 +229,57 @@ def test_source_keywords_in_header(self):
assert hdr["ESO ATM SEEING"] == opt.cmds["!OBS.psf_fwhm"]


@pytest.mark.usefixtures("protect_currsys", "patch_all_mock_paths")
class TestModeStatus:
def test_concept_mode_init(self):
with pytest.raises(NotImplementedError):
_ = sim.UserCommands(use_instrument="basic_instrument",
set_modes=["mock_concept_mode"])

def test_concept_mode_change(self):
cmd = sim.UserCommands(use_instrument="basic_instrument")
with pytest.raises(NotImplementedError):
cmd.set_modes("mock_concept_mode")

def test_experimental_mode_init(self, caplog):
_ = sim.UserCommands(use_instrument="basic_instrument",
set_modes=["mock_experimental_mode"])
assert ("Mode 'mock_experimental_mode' is still in experimental stage"
in caplog.text)

def test_experimental_mode_change(self, caplog):
cmd = sim.UserCommands(use_instrument="basic_instrument")
cmd.set_modes("mock_experimental_mode")
assert ("Mode 'mock_experimental_mode' is still in experimental stage"
in caplog.text)

def test_deprecated_mode_init(self):
with pytest.raises(
DeprecationWarning,
match="Instrument mode 'mock_deprecated_mode' is deprecated."):
_ = sim.UserCommands(use_instrument="basic_instrument",
set_modes=["mock_deprecated_mode"])

def test_deprecated_mode_change(self):
cmd = sim.UserCommands(use_instrument="basic_instrument")
with pytest.raises(
DeprecationWarning,
match="Instrument mode 'mock_deprecated_mode' is deprecated."):
cmd.set_modes("mock_deprecated_mode")

def test_deprecated_msg_mode_init(self):
with pytest.raises(
DeprecationWarning, match="This mode is deprecated."):
_ = sim.UserCommands(use_instrument="basic_instrument",
set_modes=["mock_deprecated_mode_msg"])

def test_deprecated_msg_mode_change(self, caplog):
cmd = sim.UserCommands(use_instrument="basic_instrument")
with pytest.raises(
DeprecationWarning, match="This mode is deprecated."):
cmd.set_modes("mock_deprecated_mode_msg")


@pytest.fixture(scope="function", name="obs")
def basic_opt_observed():
src = st.star(flux=15)
Expand Down

0 comments on commit 4192891

Please sign in to comment.