def test_Field__encode_mask__normal_one_byte(): """ mask: 0b11110000 encoded: 0b00000011 <- input shifted: 0b00110000 <- output """ f = Field("", bit_mask=0b11110000) input_bytes = bytes([0b00000011]) expected = bytes([0b00110000]) actual = f._encode_mask(input_bytes) assert actual == expected
def test_Field__encode_mask__normal_multi_byte(): """ mask: 0x0FFFF0 encoded: 0x00FF00 <- input shifted: 0x0FF000 <- output """ f = Field("", byte_index=(0, 1, 2), bit_mask=0x0FFFF0) input_bytes = (0x00FF00).to_bytes(3, "big") expected = (0x0FF000).to_bytes(3, "big") actual = f._encode_mask(input_bytes) assert actual == expected
def test_Field__encode_mask__condition_bit_mask_is_None(): f = Field("", bit_mask=None) input_bytes = bytes(list(range(3))) expected = input_bytes actual = f._encode_mask(input_bytes) assert actual == expected