alarmserver.test_alarmserver

Package alarmserver :: Module test_alarmserver |
[hide private]
[frames] | no frames]

# Source Code for Module alarmserver.test_alarmserver

     1  #-*- coding: utf-8 -*-

     2  """

     3  Created on 24.09.2013

     4  @author: lehmann

     5  """
     6

     7  import unittest
     8  from alarmserver import *
     9

    10 -class TestAlarmServer (unittest.TestCase):
    11 -    def setUp(self):
    12          self.server = AlarmServer()
    13          self.server.define_alarm(0, "alarm 1")
    14          self.server.define_alarm(1, "alarm 2")
    15          self.server.define_alarm(2, "alarm 3")
    16

    17 -    def test_define_alarm(self):
    18          self.assertEqual(len(self.server.defined_alarms), 3)
    19          self.assertEqual(self.server.defined_alarms[0].text, "alarm 1")
    20          self.assertEqual(self.server.defined_alarms[1].text, "alarm 2")
    21          self.assertEqual(self.server.defined_alarms[2].text, "alarm 3")
    22

    23 -    def test_raise_alarm(self):
    24          self.server.alarm_coming(0)
    25          self.assertEqual(len(self.server.current_alarms), 1)
    26          self.assertTrue(len(self.server.current_alarms)>0)
    27          self.assertTrue(self.server.unacknowledged_alarms)
    28

    29 -    def test_acknowledge(self):
    30          self.server.alarm_coming(0)
    31          self.server.alarm_coming(1)
    32          self.server.acknowledge(0)
    33

    34          self.assertTrue(self.server.current_alarms[0].is_acknowledged)
    35          self.assertFalse(self.server.current_alarms[1].is_acknowledged)
    36          self.assertTrue(self.server.unacknowledged_alarms)
    37

    38          self.server.acknowledge(1)
    39          self.assertTrue(self.server.current_alarms[1].is_acknowledged)
    40          self.assertFalse(self.server.unacknowledged_alarms)
    41

    42 -    def test_clear(self):
    43          self.server.alarm_coming(0)
    44          self.server.alarm_coming(1)
    45

    46          self.assertEqual(len(self.server.current_alarms), 2)
    47          self.server.clear(0)
    48          self.assertEqual(len(self.server.current_alarms), 1)
    49

    50 -    def test_clear_all(self):
    51          self.server.alarm_coming(0)
    52          self.server.alarm_coming(1)
    53

    54          self.assertEqual(len(self.server.current_alarms), 2)
    55

    56          self.server.clear_all()
    57

    58          self.assertEqual(len(self.server.current_alarms), 0)
    59

    60 -    def test_raise_alarm_error(self):
    61          self.assertRaises(Exception, self.server.alarm_coming, 4)
    62

    63 -    def test_bit_of_word(self):
    64          for i in range(BIT_COUNT):
    65              testword = 1<<i
    66              for j in range(BIT_COUNT):
    67                  if j==i:
    68                      self.assertTrue(bit_of_word(testword, j))
    69                  else:
    70                      self.assertFalse(bit_of_word(testword, j))
    71

    72  if __name__=="__main__":
    73      unittest.main(verbosity=2)
    74