Skip to content

Commit

Permalink
Run the pip packaging tests in tmt
Browse files Browse the repository at this point in the history
Signed-off-by: Cristian Le <[email protected]>
  • Loading branch information
LecrisUT committed Sep 3, 2024
1 parent 3db8a97 commit 24a313e
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 15 deletions.
21 changes: 21 additions & 0 deletions .distro/plans/python.fmf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
summary: Test python integration

prepare:
- how: install
package:
- python3dist(pip)
- gcc-c++
- cmake
- ninja-build
# Defining all python dependencies manually here
- python3dist(scikit-build-core)
- how: shell
script: |
python3 -m venv --system-site-packages $TMT_PLAN_DATA/venv

discover+:
how: fmf
path: .
filter: "tag:python"
execute:
how: tmt
3 changes: 1 addition & 2 deletions test/ctest.fmf
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
summary: Run the bundled ctests
tag: [ cmake ]
framework: beakerlib
test: ./test.sh
2 changes: 2 additions & 0 deletions test/main.fmf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
framework: beakerlib
test: ./test.sh
17 changes: 4 additions & 13 deletions test/package/pip/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,10 @@ project(example_spglib LANGUAGES CXX)

find_package(Template REQUIRED CONFIG)

# Make sure the executable is runnable after the pip install
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH True)

add_executable(main main.cpp)
target_link_libraries(main PRIVATE Template::Template)

enable_testing()
add_test(NAME smoke_test
COMMAND $<TARGET_FILE:main>
)
set_tests_properties(smoke_test PROPERTIES
PASS_REGULAR_EXPRESSION "^Hello, World!"
)
if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.27)
# https://stackoverflow.com/a/77990416
set_property(TEST smoke_test APPEND PROPERTY
ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$<JOIN:$<TARGET_RUNTIME_DLL_DIRS:main>,\;>"
)
endif ()
install(TARGETS main DESTINATION ${SKBUILD_SCRIPTS_DIR})
2 changes: 2 additions & 0 deletions test/package/pip/main.fmf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
summary: Test the python installation
tag: [ python ]
26 changes: 26 additions & 0 deletions test/package/pip/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash
# vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
# shellcheck disable=all
source /usr/share/beakerlib/beakerlib.sh || exit 1

rlJournalStart
rlPhaseStartSetup
rlRun "tmp=\$(mktemp -d)" 0 "Create tmp directory"
rlRun "source \$TMT_PLAN_DATA/venv/bin/activate" 0 "Source the plan's virtual environment"
# Secondary venv inheriting from the main virtual environment
# keeps the plan's vnev clean
rlRun "python3 -m venv --site-packages \$tmp/venv" 0 "Create the test's virtual environment"
rlRun "deactivate && source \$tmp/venv/bin/activate" 0 "Source the test's virtual environment"
rlRun "set -o pipefail"
rlPhaseEnd

rlPhaseStartTest
rlRun "pip install -v --no-build-isolation ." 0 "Install the test package"
rlRun -s "main" 0 "Run the test executable"
rlAssertGrep "Hello, World!" $rlRun_LOG
rlPhaseEnd

rlPhaseStartCleanup
rlRun "rm -r $tmp" 0 "Remove tmp directory"
rlPhaseEnd
rlJournalEnd

0 comments on commit 24a313e

Please sign in to comment.