Skip to content
Snippets Groups Projects
Select Git revision
  • 36c5888f58a73a5e72861a3f3f9d579eab53f41f
  • master default protected
  • refactor-control-power-properties
  • set_hba_element_power
  • L2SS-2199-apply-dab-to-xy
  • stop-using-mesh-gateway
  • test-pytango-10.0.3
  • revert-cs032-ccd-ip
  • deploy-components-parallel
  • fix-chrony-exporter
  • L2SS-2407-swap-iers-caltable-monitoring-port
  • L2SS-2357-fix-ruff
  • sync-up-with-meta-pypcc
  • stabilise-landing-page
  • all-stations-lofar2
  • v0.39.7-backports
  • Move-sdptr-to-v1.5.0
  • fix-build-ubuntu
  • tokens-in-env-files
  • fix-build
  • L2SS-2214-deploy-cdb
  • v0.52.8 protected
  • v0.52.7 protected
  • v0.55.5-r2 protected
  • v0.52.8-rc1 protected
  • v0.55.5 protected
  • v0.55.4 protected
  • 0.55.2.dev0
  • 0.55.1.dev0
  • 0.55.0.dev0
  • v0.54.0 protected
  • 0.53.2.dev0
  • 0.53.1.dev0
  • v0.52.3-r2 protected
  • remove-snmp-client
  • v0.52.3 protected
  • v0.52.3dev0 protected
  • 0.53.1dev0
  • v0.52.2-rc3 protected
  • v0.52.2-rc2 protected
  • v0.52.2-rc1 protected
41 results

test_threshold.py

Blame
  • Corné Lukken's avatar
    L2SS-1986: Process new requirements and fix bugs
    Corné Lukken authored
    36c5888f
    History
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    test_threshold.py 6.30 KiB
    # Copyright (C) 2024 ASTRON (Netherlands Institute for Radio Astronomy)
    # SPDX-License-Identifier: Apache-2.0
    
    import logging
    
    import numpy
    
    from tangostationcontrol.states.station_state_enum import StationStateEnum
    from tangostationcontrol.protection.threshold import NumberProtectionThreshold
    
    from test import base
    
    logger = logging.getLogger()
    
    
    class TestProtectionThreshold(base.TestCase):
    
        def setUp(self):
            super(TestProtectionThreshold, self).setUp()
    
        def test_number_threshold_scalar(self):
            """Test evaluating a NumberProtectionThreshold for simple scalars"""
    
            test = NumberProtectionThreshold(minimal=0, maximum=90.0)
    
            # self.assertTrue(test.evaluate(-1))
            # self.assertTrue(test.evaluate(-0.1))
            self.assertTrue(test.evaluate(91))
            self.assertTrue(test.evaluate(90.1))
    
            self.assertFalse(test.evaluate(0))
            self.assertFalse(test.evaluate(0.0))
            self.assertFalse(test.evaluate(89.9))
    
        def test_number_threshold_list(self):
            test = NumberProtectionThreshold(minimal=0, maximum=90.0)
    
            # self.assertTrue(
            #     test.evaluate([0, 0, 0, 0, -1]),
            #     "Single dimensionsal list below threshold failed",
            # )
            self.assertTrue(
                test.evaluate(
                    [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 91, 0, 0], [0, 0, 0, 0, 0]]
                ),
                "Multidimensional list above threshold failed",
            )
    
            self.assertFalse(
                test.evaluate([0, 0, 0, 0, 0]),
                "Single dimensional list within threshold failed",
            )
            self.assertFalse(
                test.evaluate(
                    [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]
                ),
                "Multidimensional list within threshold failed",
            )
    
        def test_number_threshold_tuple(self):
            test = NumberProtectionThreshold(minimal=0, maximum=90.0)
    
            # self.assertTrue(
            #     test.evaluate(
            #         (
            #             0,
            #             0,
            #             0,
            #             0,
            #             -1,
            #         )
            #     ),
            #     "Single dimensionsal tuple below threshold failed",
            # )
            self.assertTrue(
                test.evaluate(
                    (
                        (
                            0,
                            0,
                            0,
                            0,
                            0,
                        ),
                        (
                            0,
                            0,
                            0,
                            0,
                            0,
                        ),
                        (
                            0,
                            0,
                            91,
                            0,
                            0,
                        ),
                        (
                            0,
                            0,
                            0,
                            0,
                            0,
                        ),
                    )
                ),
                "Multidimensional tuple above threshold failed",
            )
    
            self.assertFalse(
                test.evaluate(
                    (
                        0,
                        0,
                        0,
                        0,
                        0,
                    )
                ),
                "Single dimensional tuple within threshold failed",
            )
            self.assertFalse(
                test.evaluate(
                    (
                        (
                            0,
                            0,
                            0,
                            0,
                            0,
                        ),
                        (
                            0,
                            0,
                            0,
                            0,
                            0,
                        ),
                        (
                            0,
                            0,
                            0,
                            0,
                            0,
                        ),
                        (
                            0,
                            0,
                            0,
                            0,
                            0,
                        ),
                    )
                ),
                "Multidimensional tuple within threshold failed",
            )
    
        def test_number_threshold_numpy(self):
            test = NumberProtectionThreshold(minimal=0, maximum=90.0)
    
            self.assertTrue(
                test.evaluate(numpy.array([0] * 3 + [91], dtype=numpy.int8)),
                "Single dimensional numpy array int8 above threshold failed",
            )
    
            self.assertTrue(
                test.evaluate(numpy.array([[0] * 3 + [91]] + [[0] * 4], dtype=numpy.int8)),
                "Multi dimensional numpy array int8 above threshold failed",
            )
    
            self.assertTrue(
                test.evaluate(numpy.array([0] * 3 + [91], dtype=numpy.double)),
                "Single dimensional numpy array double above threshold failed",
            )
    
            self.assertTrue(
                test.evaluate(
                    numpy.array([[0] * 3 + [91]] + [[0] * 4], dtype=numpy.double)
                ),
                "Multi dimensional numpy array double above threshold failed",
            )
    
            self.assertFalse(
                test.evaluate(numpy.array([[0] * 3 + [2]] + [[0] * 4], dtype=numpy.double)),
                "Multi dimensional numpy array double within threshold failed",
            )
    
        def test_number_threshold_enum(self):
            test = NumberProtectionThreshold(
                minimal=StationStateEnum.HIBERNATE, maximum=StationStateEnum.STANDBY
            )
    
            # self.assertTrue(
            #     test.evaluate(StationStateEnum.OFF), "Enum scalar below threshold failed"
            # )
    
            self.assertTrue(
                test.evaluate(StationStateEnum.ON), "Enum scalar above threshold failed"
            )
    
            self.assertFalse(
                test.evaluate(StationStateEnum.HIBERNATE),
                "Enum scalar within threshold failed",
            )
    
            # self.assertTrue(
            #     test.evaluate([StationStateEnum.STANDBY] * 3 + [StationStateEnum.OFF]),
            #     "Single dimensionsal list below threshold failed",
            # )
    
            # self.assertTrue(
            #     test.evaluate(
            #         [[StationStateEnum.STANDBY] * 3 + [StationStateEnum.OFF]] * 4
            #     ),
            #     "Multidimension dimensionsal list below threshold failed",
            # )