From 14873a246d3f990d8dbbe876c4d42855b71f5019 Mon Sep 17 00:00:00 2001 From: Hans Johnson Date: Wed, 21 Oct 2020 20:52:09 -0500 Subject: [PATCH] ENH: Explicitly test the itkConfig.LazyLoad=False option The default lazy loading is well tested, but the non-lazy load path is never routinely tested. --- .../Generators/Python/Tests/CMakeLists.txt | 1 + Wrapping/Generators/Python/Tests/extras.py | 7 ++-- Wrapping/Generators/Python/Tests/nolazy.py | 33 +++++++++++++++++++ 3 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 Wrapping/Generators/Python/Tests/nolazy.py diff --git a/Wrapping/Generators/Python/Tests/CMakeLists.txt b/Wrapping/Generators/Python/Tests/CMakeLists.txt index dc4069c03a5..c4d56050fd0 100644 --- a/Wrapping/Generators/Python/Tests/CMakeLists.txt +++ b/Wrapping/Generators/Python/Tests/CMakeLists.txt @@ -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}") diff --git a/Wrapping/Generators/Python/Tests/extras.py b/Wrapping/Generators/Python/Tests/extras.py index 36a9537a898..5c8ec458752 100644 --- a/Wrapping/Generators/Python/Tests/extras.py +++ b/Wrapping/Generators/Python/Tests/extras.py @@ -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) @@ -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) diff --git a/Wrapping/Generators/Python/Tests/nolazy.py b/Wrapping/Generators/Python/Tests/nolazy.py new file mode 100644 index 00000000000..ad3547319c8 --- /dev/null +++ b/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