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 7, 2025
1 parent 6280d08 commit 435c5bb
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 19 deletions.
101 changes: 84 additions & 17 deletions tests/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,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 @@ -324,17 +324,87 @@ 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_ICON': libexecdir / 'xdg-desktop-portal-validate-icon',
'XDP_VALIDATE_SOUND': libexecdir / 'xdg-desktop-portal-validate-sound',
}
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 @@ -345,6 +415,9 @@ if enable_installed_tests
install_dir: installed_tests_dir / 'services',
)

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

testfiles = [
'testdb',
'test-doc-portal',
Expand All @@ -353,13 +426,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 @@ -369,13 +440,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 @@ -385,13 +454,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 435c5bb

Please sign in to comment.