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 Dec 4, 2024
1 parent 76a9440 commit dd4ec29
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 13 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ RUN apt install -y --no-install-recommends \
# Install meson
RUN apt install -y --no-install-recommends meson

# Install pip
RUN apt install -y --no-install-recommends python3-pip

# Install pytest
RUN apt install -y --no-install-recommends \
python3-pytest \
Expand All @@ -52,9 +55,7 @@ RUN apt install -y --no-install-recommends \
libumockdev-dev \
umockdev \
gir1.2-umockdev-1.0

# Install pip
RUN apt install -y --no-install-recommends python3-pip
RUN pip install --prefix=/usr pytest-tap

# Install doc dependencies
RUN pip install --user --break-system-packages furo">=2024.04.27" \
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/container.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
env:
IMAGE_TAG: 20241204-1
IMAGE_TAG: 20241204-4

on:
workflow_call:
Expand Down
85 changes: 77 additions & 8 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 @@ -323,17 +323,86 @@ if enable_pytest
'test_trash.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/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: '@0@.test'.format(testname),
configuration: data,
install: true,
install_dir: installed_tests_data_dir,
)
endforeach
endif
endif

if enable_installed_tests
Expand All @@ -352,9 +421,9 @@ if enable_installed_tests
]
foreach tf : testfiles
data = configuration_data()
data.set('installed_testdir', installed_tests_dir)
data.set('exec', installed_tests_dir / tf)
data.set('env', '')
data.set('libdir', libdir)
data.set('exec', tf)
configure_file(
input: 'template.test.in',
output: '@0@.test'.format(tf),
Expand All @@ -366,9 +435,9 @@ if enable_installed_tests

foreach p : portal_tests
data = configuration_data()
data.set('installed_testdir', installed_tests_dir)
data.set('exec', '@0@ -p /portal/@1@'.format(installed_tests_dir / 'test-portals', p))
data.set('env', '')
data.set('libdir', libdir)
data.set('exec', 'test-portals -p /portal/@0@'.format(p))
configure_file(
input: 'template.test.in',
output: 'test-portals-@0@.test'.format(p),
Expand All @@ -380,9 +449,9 @@ if enable_installed_tests

foreach p : portal_limited
data = configuration_data()
data.set('installed_testdir', installed_tests_dir)
data.set('exec', '@0@ -p /limited/@1@'.format(installed_tests_dir / 'limited-portals', p))
data.set('env', '')
data.set('libdir', libdir)
data.set('exec', 'limited-portals -p /limited/@0@'.format(p))
configure_file(
input: 'template.test.in',
output: 'test-limited-@0@.test'.format(p),
Expand Down
2 changes: 1 addition & 1 deletion tests/template.test.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[Test]
Type=session
Exec=env LSAN_OPTIONS=exitcode=0 LD_LIBRARY_PATH=@libdir@:$LD_LIBRARY_PATH @installed_testdir@/@exec@ --tap
Exec=env LSAN_OPTIONS=exitcode=0 LD_LIBRARY_PATH=@libdir@:$LD_LIBRARY_PATH @env@ @exec@ --tap
Output=TAP

0 comments on commit dd4ec29

Please sign in to comment.