Skip to content

Commit

Permalink
tests/py: Install pytest based tests
Browse files Browse the repository at this point in the history
  • Loading branch information
swick committed Jan 9, 2025
1 parent 32516cc commit 99efdb6
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 21 deletions.
14 changes: 12 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
# Required environment variables by x-d-p:
# XDP_VALIDATE_ICON: the path to the xdg-desktop-portal-validate-icon binary
# XDP_VALIDATE_SOUND: the path to the xdg-desktop-portal-validate-sound binary
# OR
# XDP_VALIDATE_AUTO: if set, automatically discovers the icon and sound
# validators (only useful for installed tests)
#
# Environment variables for debugging:
# XDP_DBUS_MONITOR: if set, starts dbus_monitor on the custom bus
Expand Down Expand Up @@ -52,10 +55,17 @@ def ensure_environment_set() -> None:
"XDG_DESKTOP_PORTAL_PATH",
"XDG_PERMISSION_STORE_PATH",
"XDG_DOCUMENT_PORTAL_PATH",
"XDP_VALIDATE_ICON",
"XDP_VALIDATE_SOUND",
]

if not os.getenv("XDP_VALIDATE_AUTO"):
env_vars += [
"XDP_VALIDATE_ICON",
"XDP_VALIDATE_SOUND",
]
else:
os.environ.pop("XDP_VALIDATE_ICON", None)
os.environ.pop("XDP_VALIDATE_SOUND", None)

for env_var in env_vars:
if not os.getenv(env_var):
raise Exception(f"{env_var} must be set")
Expand Down
100 changes: 83 additions & 17 deletions tests/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ enable_pytest = get_option('pytest') \
.allowed()

if enable_pytest
pytest_args = [meson.current_source_dir(), '--verbose', '--log-level=DEBUG']
pytest_args = ['--verbose', '--log-level=DEBUG']

pytest_env = environment()
pytest_env.set('XDG_DESKTOP_PORTAL_PATH', xdg_desktop_portal.full_path())
Expand Down Expand Up @@ -323,17 +323,86 @@ if enable_pytest
'test_usb.py',
'test_wallpaper.py',
]

template_files = [
'templates/access.py',
'templates/account.py',
'templates/appchooser.py',
'templates/background.py',
'templates/clipboard.py',
'templates/email.py',
'templates/filechooser.py',
'templates/geoclue2.py',
'templates/globalshortcuts.py',
'templates/inhibit.py',
'templates/__init__.py',
'templates/inputcapture.py',
'templates/lockdown.py',
'templates/notification.py',
'templates/print.py',
'templates/remotedesktop.py',
'templates/screenshot.py',
'templates/settings.py',
'templates/usb.py',
'templates/wallpaper.py',
]

foreach pytest_file : pytest_files
testname = pytest_file.replace('.py', '')
test(
'pytest/@0@'.format(testname),
pytest,
args: pytest_args + ['-k', testname],
args: [meson.current_source_dir()] + pytest_args + ['-k', testname],
env: pytest_env,
suite: ['pytest'],
timeout: 120,
)
endforeach

if enable_installed_tests
install_data(
pytest_files,
'__init__.py',
'conftest.py',
'asan.suppression',
install_dir: installed_tests_dir / 'tests',
)
install_data(
template_files,
install_dir: installed_tests_dir / 'tests' / 'templates',
)

installed_env = {
'XDG_DESKTOP_PORTAL_PATH': libexecdir / 'xdg-desktop-portal',
'XDG_PERMISSION_STORE_PATH': libexecdir / 'xdg-permission-store',
'XDG_DOCUMENT_PORTAL_PATH': libexecdir / 'xdg-document-portal',
'XDP_VALIDATE_AUTO': '1',
}
env = ''
foreach key, value : installed_env
env += f'@key@=@value@ '
endforeach

foreach pytest_file : pytest_files
testname = pytest_file.replace('.py', '')

exec = [pytest.full_path(), installed_tests_dir / 'tests'] + pytest_args + ['-k', testname]
exec = ' '.join(exec)

data = configuration_data()
data.set('exec', exec)
data.set('env', env)
data.set('libdir', libdir)

configure_file(
input: 'template.test.in',
output: '@[email protected]'.format(testname),
configuration: data,
install: true,
install_dir: installed_tests_data_dir,
)
endforeach
endif
endif

if enable_installed_tests
Expand All @@ -344,6 +413,9 @@ if enable_installed_tests
install_dir: installed_tests_dir / 'services',
)

installed_tests_env = 'XDG_DATA_DIRS=@0@/share:@1@:/usr/local/share:/usr/share'
installed_tests_env = installed_tests_env.format(installed_tests_data_dir, datadir)

testfiles = [
'testdb',
'test-doc-portal',
Expand All @@ -352,13 +424,11 @@ if enable_installed_tests
]
foreach tf : testfiles
data = configuration_data()
data.set('datadir', datadir)
data.set('installed_testdir', installed_tests_dir)
data.set('installed_tests_data_dir', installed_tests_data_dir)
data.set('exec', installed_tests_dir / tf)
data.set('env', installed_tests_env)
data.set('libdir', libdir)
data.set('exec', tf)
configure_file(
input: 'template.test.in',
input: 'template-tap.test.in',
output: '@[email protected]'.format(tf),
configuration: data,
install: true,
Expand All @@ -368,13 +438,11 @@ if enable_installed_tests

foreach p : portal_tests
data = configuration_data()
data.set('datadir', datadir)
data.set('installed_testdir', installed_tests_dir)
data.set('installed_tests_data_dir', installed_tests_data_dir)
data.set('exec', '@0@ -p /portal/@1@'.format(installed_tests_dir / 'test-portals', p))
data.set('env', installed_tests_env)
data.set('libdir', libdir)
data.set('exec', 'test-portals -p /portal/@0@'.format(p))
configure_file(
input: 'template.test.in',
input: 'template-tap.test.in',
output: 'test-portals-@[email protected]'.format(p),
configuration: data,
install: true,
Expand All @@ -384,13 +452,11 @@ if enable_installed_tests

foreach p : portal_limited
data = configuration_data()
data.set('datadir', datadir)
data.set('installed_testdir', installed_tests_dir)
data.set('installed_tests_data_dir', installed_tests_data_dir)
data.set('exec', '@0@ -p /limited/@1@'.format(installed_tests_dir / 'limited-portals', p))
data.set('env', installed_tests_env)
data.set('libdir', libdir)
data.set('exec', 'limited-portals -p /limited/@0@'.format(p))
configure_file(
input: 'template.test.in',
input: 'template-tap.test.in',
output: 'test-limited-@[email protected]'.format(p),
configuration: data,
install: true,
Expand Down
4 changes: 4 additions & 0 deletions tests/template-tap.test.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[Test]
Type=session
Exec=env LSAN_OPTIONS=exitcode=0 LD_LIBRARY_PATH=@libdir@:$LD_LIBRARY_PATH @env@ @exec@ --tap
Output=TAP
3 changes: 1 addition & 2 deletions tests/template.test.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
[Test]
Type=session
Exec=env LSAN_OPTIONS=exitcode=0 LD_LIBRARY_PATH=@libdir@:$LD_LIBRARY_PATH XDG_DATA_DIRS=@installed_tests_data_dir@/share:@datadir@:/usr/local/share:/usr/share @installed_testdir@/@exec@ --tap
Output=TAP
Exec=env LSAN_OPTIONS=exitcode=0 LD_LIBRARY_PATH=@libdir@:$LD_LIBRARY_PATH @env@ @exec@

0 comments on commit 99efdb6

Please sign in to comment.