| 46 | class TestPacket(object): |
| 47 | @pytest.mark.parametrize('packet', pktfiles, ids=[os.path.basename(f) for f in pktfiles]) |
| 48 | def test_load(self, packet): |
| 49 | b = binload(packet) + _trailer |
| 50 | _b = b[:] |
| 51 | p = Packet(_b) |
| 52 | |
| 53 | # parsed all bytes |
| 54 | assert _b == _trailer |
| 55 | |
| 56 | # length is computed correctly |
| 57 | assert p.header.length + len(p.header) == len(p) |
| 58 | if packet not in ('tests/testdata/packets/11.partial.literal',): |
| 59 | assert len(p) == len(b) - len(_trailer) |
| 60 | assert len(p.__bytes__()) == len(b) - len(_trailer) |
| 61 | |
| 62 | # __bytes__ output is correct |
| 63 | assert p.__bytes__() == b[:-len(_trailer)] |
| 64 | |
| 65 | # instantiated class is what we expected |
| 66 | if hasattr(p.header, 'version') and (p.header.tag, p.header.version) in _pclasses: |
| 67 | # versioned packet |
| 68 | assert p.__class__.__name__ == _pclasses[(p.header.tag, p.header.version)] |
| 69 | |
| 70 | elif (not hasattr(p.header, 'version')) and p.header.tag in _pclasses: |
| 71 | # unversioned packet |
| 72 | assert p.__class__.__name__ in _pclasses[p.header.tag] |
| 73 | |
| 74 | else: |
| 75 | # fallback to opaque |
| 76 | assert isinstance(p, Opaque) |
| 77 | |
| 78 | # if this is a key, ensure len(p.keymaterial) == len(bytes(p.keymaterial)) |
| 79 | if isinstance(p, (PubKeyV4, PubSubKeyV4, PrivKeyV4, PrivSubKeyV4)): |
| 80 | assert len(p.keymaterial) == len(p.keymaterial.__bytes__()) |