From 04f112f8aef21ff1c2a334a1398cebcb37dadbb6 Mon Sep 17 00:00:00 2001 From: "Joachim Wuttke (h)" <j.wuttke@fz-juelich.de> Date: Tue, 8 Dec 2020 14:38:58 +0100 Subject: [PATCH] PyCore tests: configure path in CMake, not in Py --- Tests/Functional/Python/PyCore/CMakeLists.txt | 17 ++++---- Tests/Functional/Python/PyCore/histogram2d.py | 2 - .../Functional/Python/PyCore/intensitydata.py | 2 - .../Python/PyCore/intensitydata_io.py | 2 - .../Python/PyCore/intensitydata_io_tiff.py | 2 - .../Functional/Python/PyCore/parameterpool.py | 2 - .../Functional/Python/PyCore/samplebuilder.py | 2 - Tests/Functional/Python/PyCore/shape2d.py | 2 - Tests/Functional/Python/PyCore/utils.py | 42 ++----------------- 9 files changed, 12 insertions(+), 61 deletions(-) diff --git a/Tests/Functional/Python/PyCore/CMakeLists.txt b/Tests/Functional/Python/PyCore/CMakeLists.txt index 9d195c49ec5..bd77f6d3fd1 100644 --- a/Tests/Functional/Python/PyCore/CMakeLists.txt +++ b/Tests/Functional/Python/PyCore/CMakeLists.txt @@ -5,18 +5,17 @@ set(OUTPUT_DIR ${TEST_OUTPUT_DIR_PY_CORE}) file(MAKE_DIRECTORY ${OUTPUT_DIR}) -file(GLOB sources RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.py") +file(GLOB tests RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.py") +list(REMOVE_ITEM tests utils.py) if(NOT BORNAGAIN_TIFF_SUPPORT) - list(REMOVE_ITEM sources "intensitydata_io_tiff.py") + list(REMOVE_ITEM tests "intensitydata_io_tiff.py") endif() -foreach(_src ${sources}) - configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${_src} ${OUTPUT_DIR}/${_src} @ONLY) -endforeach() - -set(tests ${sources}) -list(REMOVE_ITEM tests utils.py) +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/utils.py ${OUTPUT_DIR}/utils.py) foreach(_test ${tests}) - add_test(PyCore.${_test} ${Python3_EXECUTABLE} ${OUTPUT_DIR}/${_test}) + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${_test} ${OUTPUT_DIR}/${_test} COPYONLY) + add_test(PyCore.${_test} + env PYTHONPATH=${CMAKE_LIBRARY_OUTPUT_DIRECTORY} + ${Python3_EXECUTABLE} ${OUTPUT_DIR}/${_test}) endforeach() diff --git a/Tests/Functional/Python/PyCore/histogram2d.py b/Tests/Functional/Python/PyCore/histogram2d.py index 84c639fe60a..c9df823fc10 100644 --- a/Tests/Functional/Python/PyCore/histogram2d.py +++ b/Tests/Functional/Python/PyCore/histogram2d.py @@ -1,6 +1,4 @@ import numpy, os, sys, unittest - -sys.path.append("@CMAKE_LIBRARY_OUTPUT_DIRECTORY@") import bornagain as ba diff --git a/Tests/Functional/Python/PyCore/intensitydata.py b/Tests/Functional/Python/PyCore/intensitydata.py index bb6befd4d55..e32620b5761 100644 --- a/Tests/Functional/Python/PyCore/intensitydata.py +++ b/Tests/Functional/Python/PyCore/intensitydata.py @@ -1,8 +1,6 @@ # Functional test: tests of IntensityData object import numpy, os, sys, unittest - -sys.path.append("@CMAKE_LIBRARY_OUTPUT_DIRECTORY@") import bornagain as ba diff --git a/Tests/Functional/Python/PyCore/intensitydata_io.py b/Tests/Functional/Python/PyCore/intensitydata_io.py index f45b73ce23b..d11811068d2 100644 --- a/Tests/Functional/Python/PyCore/intensitydata_io.py +++ b/Tests/Functional/Python/PyCore/intensitydata_io.py @@ -1,8 +1,6 @@ # Functional test: tests of IO operations with the IntensityData object import math, numpy, os, sys, time, unittest - -sys.path.append("@CMAKE_LIBRARY_OUTPUT_DIRECTORY@") import bornagain as ba from bornagain import deg, deg2rad, rad2deg diff --git a/Tests/Functional/Python/PyCore/intensitydata_io_tiff.py b/Tests/Functional/Python/PyCore/intensitydata_io_tiff.py index 8ae1ad26bb5..4b6e0f29ea8 100644 --- a/Tests/Functional/Python/PyCore/intensitydata_io_tiff.py +++ b/Tests/Functional/Python/PyCore/intensitydata_io_tiff.py @@ -1,8 +1,6 @@ # Functional test: tests of IO operations with the IntensityData object import math, numpy, os, sys, time, unittest - -sys.path.append("@CMAKE_LIBRARY_OUTPUT_DIRECTORY@") import bornagain as ba diff --git a/Tests/Functional/Python/PyCore/parameterpool.py b/Tests/Functional/Python/PyCore/parameterpool.py index ca8d9d0252d..d61107d8fa0 100644 --- a/Tests/Functional/Python/PyCore/parameterpool.py +++ b/Tests/Functional/Python/PyCore/parameterpool.py @@ -1,6 +1,4 @@ import numpy, os, sys, unittest - -sys.path.append("@CMAKE_LIBRARY_OUTPUT_DIRECTORY@") import bornagain as ba from bornagain import nm diff --git a/Tests/Functional/Python/PyCore/samplebuilder.py b/Tests/Functional/Python/PyCore/samplebuilder.py index 35dd5ab7026..a8628a3f002 100644 --- a/Tests/Functional/Python/PyCore/samplebuilder.py +++ b/Tests/Functional/Python/PyCore/samplebuilder.py @@ -1,7 +1,5 @@ import sys, unittest, ctypes import inspect - -sys.path.append("@CMAKE_LIBRARY_OUTPUT_DIRECTORY@") import bornagain as ba initial_width = 42 diff --git a/Tests/Functional/Python/PyCore/shape2d.py b/Tests/Functional/Python/PyCore/shape2d.py index ad92c8211c8..794763c8660 100644 --- a/Tests/Functional/Python/PyCore/shape2d.py +++ b/Tests/Functional/Python/PyCore/shape2d.py @@ -1,6 +1,4 @@ import numpy, os, sys, unittest - -sys.path.append("@CMAKE_LIBRARY_OUTPUT_DIRECTORY@") import bornagain as ba diff --git a/Tests/Functional/Python/PyCore/utils.py b/Tests/Functional/Python/PyCore/utils.py index e17bba8b054..ab4ff98bd51 100644 --- a/Tests/Functional/Python/PyCore/utils.py +++ b/Tests/Functional/Python/PyCore/utils.py @@ -3,8 +3,6 @@ Collection of utils for testing """ import gzip, numpy, sys, os - -sys.path.append("@CMAKE_LIBRARY_OUTPUT_DIRECTORY@") import bornagain as ba from bornagain import deg, angstrom @@ -42,39 +40,7 @@ def get_reference_data(filename): os.path.join(REFERENCE_DIR, filename)) -def get_simulation_MiniGISAS(sample=None): - simulation = ba.GISASSimulation() - simulation.setDetectorParameters(25, -2.0*deg, 2.0*deg, 25, 0.0*deg, - 2.0*deg) - simulation.setBeamParameters(1.0*angstrom, 0.2*deg, 0.0*deg) - if sample: - simulation.setSample(sample) - return simulation - - -def get_simulation_BasicGISAS(sample=None): - simulation = ba.GISASSimulation() - simulation.setDetectorParameters(100, 0.0*deg, 2.0*deg, 100, 0.0*deg, - 2.0*deg) - simulation.setBeamParameters(1.0*angstrom, 0.2*deg, 0.0*deg) - if sample: - simulation.setSample(sample) - return simulation - - -def plot_int(intensity): - import matplotlib, pylab - data = intensity.getArray() + 1 - # data = numpy.abs(intensity.getArray()) - phi_min = rad2deg(intensity.axis(0).lowerBound()) - phi_max = rad2deg(intensity.axis(0).upperBound()) - alpha_min = rad2deg(intensity.axis(1).lowerBound()) - alpha_max = rad2deg(intensity.axis(1).upperBound()) - im = pylab.imshow(data, - norm=matplotlib.colors.LogNorm(), - extent=[phi_min, phi_max, alpha_min, alpha_max]) - cb = pylab.colorbar(im) - cb.set_label(r'Intensity (arb. u.)', size=16) - pylab.xlabel(r'$\phi_f (^{\circ})$', fontsize=16) - pylab.ylabel(r'$\alpha_f (^{\circ})$', fontsize=16) - pylab.show() +def get_simulation_MiniGISAS(sample): + detector = ba.SphericalDetector(25, -2*deg, 2*deg, 25, 0*deg, 2*deg) + beam = ba.Beam(1., 1*angstrom, ba.Direction(0.2*deg, 0)) + return ba.GISASSimulation(beam, sample, detector) -- GitLab