Coverage for middle_layer/common/domain_layer/__init__.py: 100.00%
18 statements
« prev ^ index » next coverage.py v7.10.5, created at 2026-03-09 06:13 +0000
« prev ^ index » next coverage.py v7.10.5, created at 2026-03-09 06:13 +0000
1# Copyright 2024 Associated Universities, Inc.
2#
3# This file is part of Telescope Time Allocation Tools (TTAT).
4#
5# TTAT is free software: you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation, either version 3 of the License, or
8# any later version.
9#
10# TTAT is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with TTAT. If not, see <https://www.gnu.org/licenses/>.
17#
19from __future__ import annotations
21from enum import Enum
22from functools import reduce
24from astropy.units import Quantity, Unit
27class ValidUnits(Enum):
28 Frequency = Unit("GHz")
29 DumpTime = Unit("s")
30 DataRate = Unit("MB/s")
31 Time = Unit("second")
32 Angle = Unit("degree")
35def validate_units(quantity_list: list[Quantity], expected_unit: Unit) -> bool:
36 """Check all quantities in a given list have the expected units
38 :param quantity_list: List of quantities to check
39 :param expected_unit: Unit to expect
40 :return: True if all units in quantity_list match expected_unit, False otherwise
41 """
43 def check_unit_equality(accumulation: bool, quantity: Quantity):
44 return accumulation and quantity.unit == expected_unit
46 return reduce(check_unit_equality, quantity_list, True)
49type JSON = (str | int | float | bool | list[JSON] | list[JSON_OBJECT] | dict[str, JSON] | None)
50type JSON_ARRAY = list[JSON]
51type JSON_OBJECT = dict[str, JSON]
53x: JSON = {"this": ["that", True], "other": 23, "this thing": False}