Commit 3efeab0f authored by David Thompson's avatar David Thompson
Browse files

Fix and test the Exodus bridge.

parent 9cda4a93
......@@ -95,19 +95,27 @@ if(SMTK_BUILD_PYTHON_WRAPPINGS AND Shiboken_FOUND)
get_filename_component(shiboken_path "${SHIBOKEN_LIBRARY}" REALPATH)
file(COPY "${shiboken_path}" DESTINATION "${SMTK_BINARY_DIR}")
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/smtk/__init__.py"
"${SMTK_BINARY_DIR}/smtk/__init__.py" @ONLY)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/smtk/simple.py"
"${SMTK_BINARY_DIR}/smtk/simple.py" @ONLY)
set(SMTK_PYTHON_MODULE_SRCS
__init__
simple
testing
)
foreach(pyfile ${SMTK_PYTHON_MODULE_SRCS})
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/smtk/${pyfile}.py"
"${SMTK_BINARY_DIR}/smtk/${pyfile}.py" @ONLY
)
endforeach()
#todo we need to install this file in such a way that it can resolve
#the location of shiboken, which is going to mean running fixup bundle
#on the mac, and than fixing up the smtk.py package script
#on the mac, and then fixing up the smtk.py package script
get_filename_component(SHIBOKEN_LIBRARY_NAME ${SHIBOKEN_LIBRARY} NAME)
install(CODE "set(LIBRARY_OUTPUT_PATH \"${CMAKE_INSTALL_PREFIX}/lib\")
set(SHIBOKEN_LIBRARY \"${CMAKE_INSTALL_PREFIX}/lib/${SHIBOKEN_LIBRARY_NAME}\")
configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/smtk/__init__.py ${CMAKE_INSTALL_PREFIX}/python/smtk/__init__.py )
configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/smtk/testing.py ${CMAKE_INSTALL_PREFIX}/python/smtk/testing.py )
configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/smtk/simple.py ${CMAKE_INSTALL_PREFIX}/python/smtk/simple.py )" )
endif()
......
......@@ -7,7 +7,7 @@ set(smtkCGMSessionPythonTests
# Additional tests that require SMTK_DATA_DIR
set(smtkCGMSessionPythonDataTests
cgmLoadFile
cgmReadFile
)
foreach (test ${smtkCGMSessionPythonTests})
......
......@@ -96,5 +96,5 @@ if (SMTK_ENABLE_TESTING)
vtkCommonDataModel
vtksys
)
#add_subdirectory(testing)
add_subdirectory(testing)
endif()
#add_subdirectory(cxx)
if(SMTK_BUILD_PYTHON_WRAPPINGS AND Shiboken_FOUND)
add_subdirectory(python)
endif()
set(smtkExodusSessionPythonTests
# Empty for now.
)
# Additional tests that require SMTK_DATA_DIR
set(smtkExodusSessionPythonDataTests
exoReadFile
)
foreach (test ${smtkExodusSessionPythonTests})
add_test(${test}Py ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/${test}.py)
set_tests_properties(${test}Py
PROPERTIES
ENVIRONMENT "PYTHONPATH=${SHIBOKEN_SMTK_PYTHON};${LIB_ENV_VAR}"
)
endforeach()
if (SMTK_DATA_DIR AND EXISTS ${SMTK_DATA_DIR}/ReadMe.mkd)
foreach (test ${smtkExodusSessionPythonDataTests})
add_test(${test}Py
${PYTHON_EXECUTABLE}
${CMAKE_CURRENT_SOURCE_DIR}/${test}.py
--data-dir=${SMTK_DATA_DIR})
set_tests_properties(${test}Py
PROPERTIES
ENVIRONMENT "PYTHONPATH=${SHIBOKEN_SMTK_PYTHON};${LIB_ENV_VAR}"
)
endforeach()
endif()
......@@ -10,10 +10,63 @@
#
#=============================================================================
import smtk
mgr = smtk.model.Manager.create()
sess = mgr.createSession('exodus')
rdr = sess.op('read')
rdr.findAsFile('filename').setValue('disk_out_ref.ex2')
res = rdr.operate()
me = smtk.model.Model(res.findModelEntity('model').value(0))
print me.groups()
import smtk.testing
from smtk.simple import *
try:
import unittest2 as unittest
except ImportError:
import unittest
class TestExodusSession(unittest.TestCase):
def setUp(self):
import os, sys
self.filename = os.path.join(smtk.testing.DATA_DIR, 'exodus', 'disk_out_ref.ex2')
self.mgr = smtk.model.Manager.create()
sess = self.mgr.createSession('exodus')
SetActiveSession(sess)
def testRead(self):
ents = Read(self.filename)
self.model = smtk.model.Model(ents[0])
#Verify that the file contains the proper number of groups.
numGroups = len(self.model.groups())
self.assertEqual(numGroups, 11, 'Expected 11 groups, found %d' % numGroups)
#Verify that the group names match those from the Exodus file.
nameset = set([
'Unnamed block ID: 1 Type: HEX8',
'Unnamed set ID: 1',
'Unnamed set ID: 2',
'Unnamed set ID: 3',
'Unnamed set ID: 4',
'Unnamed set ID: 5',
'Unnamed set ID: 6',
'Unnamed set ID: 7'])
self.assertTrue(all([x.name() in nameset for x in self.model.groups()]),
'Not all group names recognized.')
# Verify that no groups which are not in the list above are present.
groupnames = [x.name() for x in self.model.groups()]
self.assertTrue(all([x in groupnames for x in nameset]),
'Some expected group names not present.')
# Count the number of each *type* of group (node, face, volume)
grouptypes = [x.flagSummary() for x in self.model.groups()]
gtc = {x:grouptypes.count(x) for x in grouptypes}
expectedgrouptypecounts = {
'boundary group (0-d entities)': 3,
'boundary group (0,1,2-d entities)': 7,
'domain group (3-d entities)': 1
}
for entry in gtc.items():
print '%40s: %d' % entry
self.assertEqual(gtc, expectedgrouptypecounts,
'At least one group was of the wrong type.')
if __name__ == '__main__':
smtk.testing.process_arguments()
unittest.main()
......@@ -419,6 +419,18 @@ def Sweep(stuffToSweep, method = SweepType.EXTRUDE, **kwargs):
PrintResultLog(res)
return res.findModelEntity('entities').value(0)
def Read(filename, **kwargs):
"""Read entities from an file (in the native modeling kernel format).
"""
sref = GetActiveSession()
rdr = sref.op('read')
rdr.findAsFile('filename').setValue(0, filename)
if 'filetype' in kwargs:
rdr.findAsString('filetype').setValue(0, kwargs['filetype'])
res = rdr.operate()
PrintResultLog(res)
return GetVectorValue(res.findModelEntity('entities'))
def Write(filename, entities = [], **kwargs):
"""Write a set of entities to an file (in the native modeling kernel format).
"""
......
#=============================================================================
#
# Copyright (c) Kitware, Inc.
# All rights reserved.
# See LICENSE.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even
# the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
# PURPOSE. See the above copyright notice for more information.
#
#=============================================================================
import sys
DATA_DIR=''
def process_arguments():
"""Process common options to python tests.
This module parses command line arguments and sets module
variable values based on them. It then removes the options
from sys.argv so that the unittest framework will not treat
them as module names.
"""
global DATA_DIR
from argparse import ArgumentParser
parser = ArgumentParser()
parser.add_argument("-D", "--data-dir",
action="store", dest="datadir", default='',
help="Top-level testing data directory.")
args = parser.parse_args()
if args.datadir:
DATA_DIR=args.datadir
sys.argv = sys.argv[:1]
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