On Fri, Jun 28, 2024 at 10:00 AM Dean Marx <dm...@iol.unh.edu> wrote: > > Test suite for verifying VLAN filtering, stripping, and insertion > functionality on Poll Mode Driver. > > Signed-off-by: Dean Marx <dm...@iol.unh.edu> > --- <snip> > + def send_vlan_packet_and_verify(self, should_receive: bool, strip: bool, > vlan_id: int) -> None: > + """Generate a vlan packet, send and verify a packet with > + the same payload is received on the dut. > + > + Args: > + should_receive: Indicate whether the packet should be > successfully received. > + strip: Indicates whether stripping is on or off, and when the > vlan tag is > + checked for a match. > + vlan_id: Expected vlan ID. > + """ > + packet = Ether() / Dot1Q(vlan=vlan_id) / Raw(load="xxxxx") > + received_packets = self.send_packet_and_capture(packet) > + test_packet = None > + for packet in received_packets: > + if b"xxxxx" in packet.load: > + test_packet = packet > + break > + if should_receive: > + self.verify( > + test_packet is not None, "Packet was dropped when it should > have been received" > + ) > + if test_packet is not None:
I assume this extra if-statement is added since the linter complains that test_packet could be None here. Obviously it can't be since you just verified it above, so another thing you could do here to make the warning go away if you wanted would be adding an `assert` statement (and preferably also a comment) here so that the linter would understand that it can't be None at this point. The if-statement also works fine, I just figured I would mention the alternative. > + if strip: > + self.verify( > + not test_packet.haslayer(Dot1Q), "Vlan tag was not > stripped successfully" > + ) > + else: > + self.verify( > + test_packet.vlan == vlan_id, > + "The received tag did not match the expected tag", > + ) > + else: > + self.verify( > + test_packet is None, > + "Packet was received when it should have been dropped", > + ) <snip> > -- > 2.44.0 >