def test_generate_items_raises(self): """Test failure modes of ._generate_items method.""" pdu = P_DATA_TF() # Short data data = b'\x00\x00\x00\x04\x01\x01\x02' gen = pdu._generate_items(data) with pytest.raises(AssertionError): next(gen)
def test_generate_items(self): """Test ._generate_items""" pdu = P_DATA_TF() gen = pdu._generate_items(b'') with pytest.raises(StopIteration): next(gen) data = b'\x00\x00\x00\x04\x01\x01\x02\x03' gen = pdu._generate_items(data) assert next(gen) == (1, b'\x01\x02\x03') with pytest.raises(StopIteration): next(gen) data += b'\x00\x00\x00\x05\x02\x03\x01\x02\x03' gen = pdu._generate_items(data) assert next(gen) == (1, b'\x01\x02\x03') assert next(gen) == (2, b'\x03\x01\x02\x03') with pytest.raises(StopIteration): next(gen)