def test_lookup_adapter(): adapter = LookupAdapter({'Zero': 0, 'One': 1}) assert adapter._decode(0) == 'Zero' assert adapter._decode(1) == 'One' with pytest.raises(ValueError): adapter._decode(2) with pytest.raises(KeyError): adapter._encode('Two')
def _decode(self, value): # Mask out the "don't care" bit for anything # that doesn't have the high bit set if value & 0b1000 == 0: value &= 0b0011 # Special case for 0b1000 = 12bit if value == 0b1000: value = 0b0011 return LookupAdapter._decode(self, value)