def _create_block_from_channel(self, channel): """ Create a single block from a channel object. Args: channel: the channel. Returns: """ name = shorten_title(channel["Channel"]) connected = channel["Connected"] current_value = channel["Current Value"] if connected: units = current_value.get("Units", "") precision = unicode(current_value.get("Precision", "")) value = unicode(current_value["Value"]) replaced = True while replaced: value, replaced = self._replace_fake_unicode(value) alarm = current_value["Alarm"] else: value = "null" alarm = "" units = "" precision = 0 status = Block.CONNECTED if connected else Block.DISCONNECTED return Block(name, status, value, alarm, True, precision, units)
def test_shorten_title_larmor_block_low_rc(self): # Arrange test_pv = "IN:LARMOR:CS:SB:Chi:RC:LOW.VAL" # Act shortened_title = shorten_title(test_pv) # Assert self.assertEquals(shortened_title, "Chi:RC:LOW.VAL")
def test_shorten_title_larmor_block_high_rc(self): # Arrange test_pv = "IN:LARMOR:CS:SB:CJHCent:RC:HIGH.VAL" # Act shortened_title = shorten_title(test_pv) # Assert self.assertEquals(shortened_title, "CJHCent:RC:HIGH.VAL")
def test_shorten_title_rc_in_pv_doesnt_count(self): # Arrange test_pv = "TE:NDLT910:RC.VAL" # Act shortened_title = shorten_title(test_pv) # Assert self.assertEquals(shortened_title, "RC.VAL")
def test_shorten_title_with_malformed_input_rc_value(self): # Arrange test_pv = "RC:INRANGE.VAL" # Act shortened_title = shorten_title(test_pv) # Assert self.assertEquals(shortened_title, "RC:INRANGE.VAL")
def test_shorten_title_with_bad_rc_value(self): # Arrange test_pv = "OLD_BLOCK:RC:OUTRANGE.VAL" # Act shortened_title = shorten_title(test_pv) # Assert self.assertEquals(shortened_title, "OUTRANGE.VAL")
def test_shorten_title_with_empty_string(self): # Arrange test_pv = "" # Act shortened_title = shorten_title(test_pv) # Assert self.assertEquals(shortened_title, "")
def test_shorten_title_with_rc_in_range(self): # Arrange test_pv = "TE:NDLT910:CS:SB:OLD_BLOCK:RC:INRANGE.VAL" # Act shortened_title = shorten_title(test_pv) # Assert self.assertEquals(shortened_title, "OLD_BLOCK:RC:INRANGE.VAL")
def test_shorten_title_with_rc_enabled(self): # Arrange test_pv = "TE:NDLT910:CS:SB:NEW_BLOCK:RC:ENABLE.VAL" # Act shortened_title = shorten_title(test_pv) # Assert self.assertEquals(shortened_title, "NEW_BLOCK:RC:ENABLE.VAL")
def test_shorten_title_for_default_case(self): #Arrange test_pv = "TE:NDLT910:DAE:COUNTRATE.VAL" #Act shortened_title = shorten_title(test_pv) #Assert self.assertEquals(shortened_title, "COUNTRATE.VAL")