mirror of
https://gitlab.freedesktop.org/libinput/libei.git
synced 2026-02-04 04:50:28 +01:00
test: add some tests for the ei-scanner itself
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.
This commit is contained in:
parent
f142f802f4
commit
ca06927371
3 changed files with 69 additions and 5 deletions
|
|
@ -1,6 +1,9 @@
|
|||
scanner = find_program('ei-scanner')
|
||||
protocol_xml = files('protocol.xml')
|
||||
protocol_dtd = files('protocol.dtd')
|
||||
scanner_source = files('ei-scanner')
|
||||
scanner = find_program(scanner_source)
|
||||
protocol_xml_path = meson.current_source_dir() / 'protocol.xml'
|
||||
protocol_dtd_path = meson.current_source_dir() / 'protocol.dtd'
|
||||
protocol_xml = files(protocol_xml_path)
|
||||
protocol_dtd = files(protocol_dtd_path)
|
||||
|
||||
xmllint = find_program('xmllint', required: false)
|
||||
if xmllint.found()
|
||||
|
|
|
|||
|
|
@ -149,7 +149,7 @@ if enable_pytest
|
|||
configuration: protocol_test_config)
|
||||
|
||||
test('protocol-test', pytest,
|
||||
args: pytest_args,
|
||||
args: pytest_args + ['-k', 'TestEiProtocol'],
|
||||
suite: 'python',
|
||||
workdir: meson.project_build_root(),
|
||||
)
|
||||
|
|
@ -157,7 +157,7 @@ if enable_pytest
|
|||
env = environment()
|
||||
env.set('LIBEI_USE_VALGRIND', '1')
|
||||
test('protocol-test-valgrind', pytest,
|
||||
args: pytest_args,
|
||||
args: pytest_args + ['-k', 'TestEiProtocol'],
|
||||
suite: 'python',
|
||||
workdir: meson.project_build_root(),
|
||||
env: env
|
||||
|
|
@ -174,6 +174,21 @@ if enable_pytest
|
|||
env: env,
|
||||
)
|
||||
endif
|
||||
|
||||
test_scanner_config = configuration_data()
|
||||
test_scanner_config.set('PROTOFILE', protocol_xml_path)
|
||||
|
||||
# ei-scanner can't be imported as-is in python, so we copy + rename it
|
||||
configure_file(input: scanner_source,
|
||||
output: 'eiscanner.py',
|
||||
copy: true)
|
||||
configure_file(input: 'test_scanner.py',
|
||||
output: '@PLAINNAME@',
|
||||
configuration: test_scanner_config)
|
||||
test('scanner-pytest', pytest,
|
||||
args: pytest_args + ['-k', 'TestScanner'],
|
||||
suite: 'python',
|
||||
workdir: meson.current_build_dir())
|
||||
endif
|
||||
|
||||
summary({'valgrind available': valgrind.found(),
|
||||
|
|
|
|||
46
test/test_scanner.py
Normal file
46
test/test_scanner.py
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
#!/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]
|
||||
Loading…
Add table
Reference in a new issue