#!/usr/bin/env python3 # We can't import ei-scanner, so let's go via this route. The proper # handling would be to have ei-scanner be the entry point for a ei_scanner # module but.. well, one day we'll do that maybe. import pytest try: from eiscanner import parse, Protocol except ImportError: print("Run tests from within the build directory") pytest.skip(allow_module_level=True) from pathlib import Path # set to the protocol file by meson protofile = "@PROTOFILE@" @pytest.fixture def protocol_xml() -> Path: return Path(protofile) @pytest.fixture def protocol(protocol_xml: Path, component: str) -> Protocol: print(f"protocol for component {component}") return parse(protocol_xml, component) @pytest.mark.skipif( protofile.startswith("@"), reason="Protocol XML file path invalid, run tests in the build dir", ) class TestScanner: @pytest.mark.parametrize("component", ("eis", "ei", "brei")) def test_ei_names(self, component: str, protocol: Protocol): for interface in protocol.interfaces: assert interface.name.startswith(component) assert not interface.plainname.startswith(component) assert not interface.plainname.startswith("ei_") # just some manual checks assert "handshake" in [i.plainname for i in protocol.interfaces] assert "connection" in [i.plainname for i in protocol.interfaces] assert "button" in [i.plainname for i in protocol.interfaces]