Example #1
0
def test_functions():
    assert formatDuration(1) == '1 second'
    assert formatDuration(4) == '4 seconds'
    assert formatDuration(154, precise=False) == '3 min'
    assert formatDuration(154, precise=True) == '2 min, 34 sec'
    assert formatDuration(7199) == '2 h, 0 min'
    assert formatDuration(3700) == '1 h, 2 min'
    assert formatDuration(24 * 3600 + 7240, precise=False) == '1 day, 2 h'
    assert formatDuration(48 * 3600 - 1) == '2 days, 0 h'

    assert bitDescription(0x5, (0, 'a'), (1, 'b', 'c'),
                          (2, 'd', 'e')) == 'a, c, d'

    assert parseConnectionString('[email protected]:pass@host:1301', 1302) == \
        {'user': '******', 'password': '******', 'host': 'host',
         'port': 1301}
    assert parseConnectionString('user:@host', 1302) == \
        {'user': '******', 'password': '', 'host': 'host', 'port': 1302}
    assert parseConnectionString('user@host:1301', 1302) == \
        {'user': '******', 'password': None, 'host': 'host', 'port': 1301}
    assert parseConnectionString('user@ho-st:1301', 1302) == \
        {'user': '******', 'password': None, 'host': 'ho-st', 'port': 1301}
    assert parseConnectionString('', 1302) is None
    assert parseConnectionString('host?', 1302) is None

    # pylint: disable=range-builtin-not-iterating
    assert [tuple(x) for x in chunks(range(10), 3)] == \
        [(0, 1, 2), (3, 4, 5), (6, 7, 8), (9,)]
Example #2
0
    def doStatus(self, maxage=0):
        alarms = self._attached_iodev._HW_readAlarms()
        almsg = bitDescription(
            alarms,
            *(self._attached_iodev._HW_Alarms +
              getattr(self._attached_iodev, '_HW_Alarms_%s' % self.chamber)))

        if almsg:
            return status.ERROR, almsg

        work = self.doRead(maxage)
        if work in (1, 0):
            # off or ventings; pumping is good!
            return status.OK, ['off', 'venting', 'priming or pumping'][work]
        return status.OK, ''
Example #3
0
    def _indexHW_status(self, i):
        """Used status bits."""
        # read HW values
        errval = self._areadErrorWord(self.addresses[i])
        statval = (self._areadStatusWord(self.addresses[i])
                   ^ self.HW_Status_Inv) & ~self.HW_Status_Ign

        msg = bitDescription(statval, *self.HW_Statusbits)
        self.log.debug('HW_status: (%x) %s', statval, msg)
        if errval:
            errnum = errval
            return status.ERROR, 'ERROR %d: %s, %s' % (
                errnum,
                self.HW_Errors.get(errnum,
                                   'Unknown Error {0:d}'.format(errnum)), msg)

        for mask, stat in self.HW_Status_map:
            if statval & mask:
                return stat, msg

        return status.OK, msg if msg else 'Ready'