Skip to content

Commit

Permalink
ENH: Explicitly test the itkConfig.LazyLoad=False option
Browse files Browse the repository at this point in the history
The default lazy loading is well tested, but
the non-lazy load path is never routinely tested.
  • Loading branch information
hjmjohnson committed Oct 27, 2020
1 parent e98a301 commit 14873a2
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
1 change: 1 addition & 0 deletions Wrapping/Generators/Python/Tests/CMakeLists.txt
Expand Up @@ -18,6 +18,7 @@ itk_python_add_test(NAME PythonTypeTest COMMAND PythonTypeTest.py)
itk_python_add_test(NAME PythonComplex COMMAND complex.py)
itk_python_add_test(NAME PythonHelperFunctions COMMAND helpers.py)
itk_python_add_test(NAME PythonLazyModule COMMAND lazy.py)
itk_python_add_test(NAME PythonNoLazyModule COMMAND nolazy.py)

# some tests will fail if dim=2 and unsigned short are not wrapped
INTERSECTION(WRAP_2 2 "${ITK_WRAP_IMAGE_DIMS}")
Expand Down
7 changes: 4 additions & 3 deletions Wrapping/Generators/Python/Tests/extras.py
Expand Up @@ -18,6 +18,10 @@

# also test the import callback feature

import itk
import sys
import os

def custom_callback(name, progress):
if progress == 0:
print("Loading %s..." % name, file=sys.stderr)
Expand All @@ -26,9 +30,6 @@ def custom_callback(name, progress):
import itkConfig
itkConfig.ImportCallback = custom_callback

import itk
import sys
import os

# test setting the number of threads
itk.set_nthreads(4)
Expand Down
33 changes: 33 additions & 0 deletions Wrapping/Generators/Python/Tests/nolazy.py
@@ -0,0 +1,33 @@
#==========================================================================
#
# Copyright NumFOCUS
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0.txt
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#==========================================================================*/
import itkConfig
itkConfig.LazyLoading = False
import itk

# Test PEP 366 compliance of LazyITKModule
assert(itk.__package__ == 'itk')
from itk import ITKCommon
assert(ITKCommon.__package__ == 'itk')

# Test pickling used bash Dask
try:
import cloudpickle
itkpickled = cloudpickle.dumps(itk)
cloudpickle.loads(itkpickled)
except ImportError:
pass

0 comments on commit 14873a2

Please sign in to comment.