Skip to content
Snippets Groups Projects
Unverified Commit 26a72acb authored by Wuttke, Joachim's avatar Wuttke, Joachim Committed by GitHub
Browse files

Merge pull request #1061 from jwuttke/pyex

PyExamples: comment and simplify test machinery
parents dbc82ddc d5390505
No related branches found
No related tags found
No related merge requests found
###############################################################################
# Tests/Functional/PyExamples/CMakeLists.txt
#
# > Test functionality of all examples found in PY_EXAMPLES_DIR = <BornAgain>/Examples/python
# > Validates selected examples against reference files
# Runs check_functionality.py over example scripts found in PY_EXAMPLES_DIR
#
###############################################################################
......@@ -15,15 +14,12 @@ file(GLOB fit_examples
set(examples ${sim_examples} ${fit_examples})
set(test_script ${output_dir}/check_functionality.py)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/check_functionality.py ${test_script} @ONLY)
foreach(example ${examples})
set(script_path ${example})
get_filename_component(script_name ${script_path} NAME_WE)
set(test_name PyExamples.${script_name})
foreach(example_path ${examples})
get_filename_component(example_name ${example_path} NAME_WE)
set(test_name PyExamples.${example_name})
add_test(${test_name} ${Python3_EXECUTABLE} ${test_script} ${script_path})
add_test(${test_name} ${Python3_EXECUTABLE} ${test_script} ${example_path})
set_tests_properties(${test_name} PROPERTIES LABELS "Fullcheck")
endforeach()
"""
Usage: python check_functionality.py <path-to-example>/<example>.py
Checks functionality of BornAgain Python example by running it in 'embedded' way.
Usage: python check_functionality.py <path-to-example>/example.py
Example is considered as functional, if it runs without exceptions thrown and
The check passes successfully if the example runs without exceptions thrown and
generates non-zero-size intensity image.
"""
import sys
......@@ -50,39 +50,30 @@ def run_example(filename):
Tries to run python example and produce a *.png image
"""
if not os.path.exists(filename):
raise Exception("File '"+filename+"' doesn't exist.")
raise Exception("Example script '"+filename+"' not found")
print(filename)
print("Input script: "+filename)
fig = get_figure(filename)
try:
exec_full(filename)
plot_file_name = os.path.splitext(os.path.basename(filename))[0] + ".png"
plot_file_name = os.path.join(output_dir, plot_file_name)
print(plot_file_name)
plt.savefig(plot_file_name, bbox_inches='tight')
plt.close(fig)
status = "OK"
kb = os.path.getsize(plot_file_name)/1000.
if kb < 4.0:
status = "EMPTY?"
exec_full(filename)
except:
e = sys.exc_info()[0]
print("Error {0} while trying to execute '{1}'".format(e, filename))
status = "FAILED"
plot_file_name = os.path.join(output_dir,
os.path.splitext(os.path.basename(filename))[0] + ".png")
print("Output image: "+plot_file_name)
plt.savefig(plot_file_name, bbox_inches='tight')
plt.close(fig)
print(status)
if status != "OK":
raise Exception(status)
imgSize = os.path.getsize(plot_file_name)
if imgSize == 0:
raise Exception("Image file is empty")
if imgSize < 20000:
raise Exception("Image file is unplausibly small")
if __name__ == '__main__':
if len(sys.argv) != 2:
exit("Error")
exit("Auxiliary script check_functionality called with wrong number of arguments")
run_example(sys.argv[1])
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment