Commit ec8ad4da authored by John Tourtellott's avatar John Tourtellott
Browse files

Add tests to extract modelbuilder package and check python import

Only enabled for linux to start
parent 66693516
......@@ -273,6 +273,7 @@ function (superbuild_add_packaging)
if (cmb_enabled)
include(cmb.suffix)
include(package.test)
list(APPEND superbuild_export_variables
CMB_PACKAGE_SUFFIX)
......@@ -285,6 +286,16 @@ function (superbuild_add_packaging)
superbuild_add_extra_package_test(modelbuilder "${generator}"
LABELS "CMB"
TIMEOUT 6400)
add_package_extract_test("${generator}"
DEPENDS "cpack-modelbuilder-${generator}"
LABELS "CMB"
)
add_package_import_test("${generator}"
DEPENDS "extract-modelbuilder-${generator}"
LABELS "CMB"
)
endforeach ()
endif ()
......
include (SuperbuildTestingMacros)
set(modelbuilder_extract_root "${CMAKE_BINARY_DIR}/Testing/Temporary")
if (CMB_PACKAGE_FILE_NAME)
set(glob_prefix "${CMB_PACKAGE_FILE_NAME}")
else ()
set(glob_prefix "modelbuilder-*")
if (CMB_PACKAGE_SUFFIX)
set(glob_prefix "${glob_prefix}-${CMB_PACKAGE_SUFFIX}")
endif ()
endif ()
#[==[.md
Test that extracts modelbuilder package file
```
add_package_extract_test(generator)
```
This test calls the superbuild_add_extract_test to extract the modelbuilder
package file.
#]==]
function (add_package_extract_test generator)
set(extract_dir "${modelbuilder_extract_root}/modelbuilder-${generator}/test-extracted")
superbuild_add_extract_test("modelbuilder" "${glob_prefix}" "${generator}" "${extract_dir}")
endfunction ()
#[==[.md
Tests that extracted modelbuilder executable can import smtk python modules.
```
add_package_import_test(generator)
```
This test runs modelbuilder and checks if it can import a minimal smtk operation,
which requires the python environment to be configured correctly. The logic is
a bit circuitous:
* The test itself runs a shell script, which can be found in the scripts
subfolder.
* The arguments passed in to the shell script form a modelbuilder execution
command that runs an xml script, which is also in the scripts subfolder.
* The xml script invokes the modelbuilder "Import Python Operation..." menu
item and selects a python file (which is also in the scripts subfolder).
* If the import-operation is successful, the python operation creates a
small text file in the test directory.
* The shell scripts verifies that the text file has been generated.
#]==]
function (add_package_import_test generator)
set(extract_dir "${modelbuilder_extract_root}/modelbuilder-${generator}/test-extracted")
set(this_dir "${CMAKE_SOURCE_DIR}/cmake")
# Current implementation only supports linux
if (UNIX AND NOT APPLE AND NOT CYGWIN)
set(exe_path "bin/modelbuilder")
set(shell_script "import_python_test.sh")
add_test(
NAME "package-import-test-${generator}"
COMMAND "${this_dir}/scripts/${shell_script}"
"${extract_dir}/${exe_path}"
"-dr"
"--data-directory=${this_dir}/scripts"
"--test-directory=${CMAKE_BINARY_DIR}/Testing/Temporary"
"--test-script=${this_dir}/scripts/import_minimum_operation.xml"
"--exit"
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/Testing/Temporary"
)
endif ()
endfunction ()
<?xml version="1.0" ?>
<pqevents>
<pqevent object="pqClientMainWindow/menubar" command="activate" arguments="menu_File" />
<pqevent object="pqClientMainWindow/menubar/menu_File" command="activate" arguments="&amp;Import Operation..." />
<pqevent object="pqClientMainWindow/OperationImportDialog" command="filesSelected" arguments="$PARAVIEW_DATA_ROOT/minimum_operation.py" />
</pqevents>
#!/usr/bin/env bash
# bash script for running import-python test
# - The full set of input arguments are the
# command + arguments to run modelbuilder.
# - The commands are expected to create a file
# minimum_operation.txt in the working directory
# Remove expected from from the working directory
filename=minimum_operation.txt
rm -f ${filename}
# Run the input arguments, which should constitute a
# modelbuilder command that runs an xml script and exits.
$*
# Check for the expected file in the working directory
if [ -f "${filename}" ]; then
exit 0
fi
echo "ERROR: File ${filename} NOT found"
exit 1
"""A minimum pythonn operation to verify that smtk python modules
can be imported and operations loaded.
"""
import os
import smtk
import smtk.attribute
import smtk.common
import smtk.io
import smtk.mesh
import smtk.model
import smtk.operation
import smtk.resource
import smtk.simulation
import smtk.view
class MinimumOperation(smtk.operation.Operation):
def __init__(self):
smtk.operation.Operation.__init__(self)
def name(self):
return "Minimal Operation"
def operateInternal(self):
outcome = int(smtk.operation.Operation.Outcome.SUCCEEDED)
result = self.createResult(outcome)
return result
def createSpecification(self):
spec = self.createBaseSpecification()
return spec
# Write small text file, which is used to confirm that import was successful.
wd = os.getcwd()
filename = 'minimum_operation.txt'
path = os.path.join(wd, filename)
with open(path, 'w') as f2:
f2.write(filename)
print('Wrote', path)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment