Skip to content

Commit

Permalink
Simplify unit test, fix docstrings of TelescopeComponent
Browse files Browse the repository at this point in the history
  • Loading branch information
maxnoe committed Jan 10, 2023
1 parent a9481dd commit ffb09d7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 31 deletions.
3 changes: 2 additions & 1 deletion ctapipe/core/telescope_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,11 @@ def from_name(cls, name, subarray, config=None, parent=None, **kwargs):
This argument is typically only specified when using this method
from within a Tool (config need not be passed if parent is used).
kwargs
Are passed to the subclass
Returns
-------
instace
Instance
Instance of subclass to this class
"""
requested_subclass = cls.non_abstract_subclasses()[name]
Expand Down
39 changes: 9 additions & 30 deletions ctapipe/core/tests/test_telescope_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ class SomeComponentFloat(Component):
assert comp_float.tel_param.tel[1] == 1.5


def test_telescope_parameter_resolver():
def test_telescope_parameter_resolver(mock_subarray):
"""check that you can resolve the rules specified in a
TelescopeParameter trait"""

Expand All @@ -211,40 +211,19 @@ class SomeComponent(Component):
)

comp = SomeComponent()

# need to mock a SubarrayDescription
subarray = mock.MagicMock()
subarray.tel_ids = [1, 2, 3, 4]
subarray.get_tel_ids_for_type = (
lambda x: [3, 4] if x == "LST_LST_LSTCam" else [1, 2]
)
subarray.telescope_types = [
"LST_LST_LSTCam",
"MST_MST_NectarCam",
"MST_MST_FlashCam",
]

comp.tel_param1.attach_subarray(subarray)
comp.tel_param2.attach_subarray(subarray)
comp.tel_param3.attach_subarray(subarray)
comp.tel_param1.attach_subarray(mock_subarray)
comp.tel_param2.attach_subarray(mock_subarray)
comp.tel_param3.attach_subarray(mock_subarray)

assert comp.tel_param1.tel[1] == 10
assert comp.tel_param1.tel[3] == 100

assert list(map(comp.tel_param2.tel.__getitem__, [1, 2, 3, 4])) == [
10.0,
10.0,
200.0,
100.0,
]
for tel_id, expected in enumerate([10.0, 10.0, 200.0, 100.0], start=1):
assert comp.tel_param2.tel[tel_id] == expected, f"mismatch for tel_id={tel_id}"

assert list(map(comp.tel_param3.tel.__getitem__, [1, 2, 3, 4, 100])) == [
200.0,
200.0,
200.0,
200.0,
300.0,
]
expected = {1: 200.0, 2: 200.0, 3: 200.0, 4: 200.0, 100: 300.0}
for tel_id, value in expected.items():
assert comp.tel_param3.tel[tel_id] == value, f"mismatch for tel_id={tel_id}"


def test_telescope_parameter_component_arg(mock_subarray):
Expand Down

0 comments on commit ffb09d7

Please sign in to comment.