mirror of
https://gitlab.freedesktop.org/libinput/libei.git
synced 2025-12-20 16:10:06 +01:00
This is a bit convoluted because ei-scanner is named like that, so it cannot be imported as python module. The solution for that is to copy/rename it with meson to the builddir and run pytest in that. This also allows us to set the path to the protocol XML file while we're at it so we can use it as a fixture. Actual tests are minimal for now, can be extended over time.
46 lines
1.5 KiB
Python
46 lines
1.5 KiB
Python
#!/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]
|