Browse Source

EKF pytest save plots to pdf

master
Daniel Agar 7 years ago
parent
commit
372f9f430b
  1. 1
      .gitignore
  2. 8
      EKF/tests/pytest/CMakeLists.txt
  3. 27
      EKF/tests/pytest/plot_utils.py
  4. 1
      EKF/tests/pytest/requirements.txt
  5. 1
      Jenkinsfile
  6. 3
      Makefile

1
.gitignore vendored

@ -1,5 +1,6 @@
*.DS_Store *.DS_Store
*~ *~
.cache/ .cache/
.pytest_cache/
build/ build/
EKF/tests/pytest/__pycache__/ EKF/tests/pytest/__pycache__/

8
EKF/tests/pytest/CMakeLists.txt

@ -36,20 +36,23 @@ if(EKF_PYTHON_TESTS)
# pip3 install -r requirements.txt # pip3 install -r requirements.txt
add_custom_target(ecl_EKF_pytest add_custom_target(ecl_EKF_pytest
COMMAND ${CMAKE_COMMAND} -E env PYTHONPATH=${CMAKE_BINARY_DIR}/EKF/swig/python ${CMAKE_CURRENT_SOURCE_DIR}/ekf_test.py --verbose COMMAND ${CMAKE_COMMAND} -E env PYTHONPATH=${CMAKE_BINARY_DIR}/EKF/swig/python ${CMAKE_CURRENT_SOURCE_DIR}/ekf_test.py --verbose --plots
DEPENDS ecl_EKF _ecl_EKF DEPENDS ecl_EKF _ecl_EKF
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
USES_TERMINAL USES_TERMINAL
) )
add_custom_target(ecl_EKF_pytest-quick add_custom_target(ecl_EKF_pytest-quick
COMMAND ${CMAKE_COMMAND} -E env PYTHONPATH=${CMAKE_BINARY_DIR}/EKF/swig/python ${CMAKE_CURRENT_SOURCE_DIR}/ekf_test.py --quick --verbose COMMAND ${CMAKE_COMMAND} -E env PYTHONPATH=${CMAKE_BINARY_DIR}/EKF/swig/python ${CMAKE_CURRENT_SOURCE_DIR}/ekf_test.py --quick --verbose --plots
DEPENDS ecl_EKF _ecl_EKF DEPENDS ecl_EKF _ecl_EKF
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
USES_TERMINAL USES_TERMINAL
) )
add_custom_target(ecl_EKF_pytest-benchmark add_custom_target(ecl_EKF_pytest-benchmark
COMMAND ${CMAKE_COMMAND} -E env PYTHONPATH=${CMAKE_BINARY_DIR}/EKF/swig/python ${CMAKE_CURRENT_SOURCE_DIR}/ekf_test.py --benchmark COMMAND ${CMAKE_COMMAND} -E env PYTHONPATH=${CMAKE_BINARY_DIR}/EKF/swig/python ${CMAKE_CURRENT_SOURCE_DIR}/ekf_test.py --benchmark
DEPENDS ecl_EKF _ecl_EKF DEPENDS ecl_EKF _ecl_EKF
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
USES_TERMINAL USES_TERMINAL
) )
@ -57,6 +60,7 @@ if(EKF_PYTHON_TESTS)
add_custom_target(ecl_EKF_pytest-plots add_custom_target(ecl_EKF_pytest-plots
COMMAND ${CMAKE_COMMAND} -E env PYTHONPATH=${CMAKE_BINARY_DIR}/EKF/swig/python ${CMAKE_CURRENT_SOURCE_DIR}/ekf_test.py --plots COMMAND ${CMAKE_COMMAND} -E env PYTHONPATH=${CMAKE_BINARY_DIR}/EKF/swig/python ${CMAKE_CURRENT_SOURCE_DIR}/ekf_test.py --plots
DEPENDS ecl_EKF _ecl_EKF DEPENDS ecl_EKF _ecl_EKF
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
USES_TERMINAL USES_TERMINAL
) )

27
EKF/tests/pytest/plot_utils.py

@ -44,18 +44,26 @@ import inspect
from contextlib import contextmanager from contextlib import contextmanager
try: try:
from matplotlib import pyplot as plt # matplotlib don't use Xwindows backend (must be before pyplot import)
import seaborn as sns import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
from matplotlib.backends.backend_pdf import PdfPages
#from matplotlib import pyplot as plt
#from matplotlib.backends.backend_pdf import PdfPages
#import seaborn as sns
except ImportError as err: except ImportError as err:
print("Cannot import plotting libraries, " print("Cannot import plotting libraries, "
"please install matplotlib and seaborn.") "please install matplotlib.")
raise err raise err
# Nice plot defaults # Nice plot defaults
sns.set_style('darkgrid') #sns.set_style('darkgrid')
sns.set_palette('colorblind', #sns.set_palette('colorblind', desat=0.6)
desat=0.6)
pp = PdfPages("ecl_EKF_test.pdf")
def quit_figure_on_key(key, fig=None): def quit_figure_on_key(key, fig=None):
"""Add handler to figure (defaults to current figure) that closes it """Add handler to figure (defaults to current figure) that closes it
@ -82,10 +90,11 @@ def figure(name=None, params=None, figsize=None, subplots=None):
# Get name of function calling the context from the stack # Get name of function calling the context from the stack
name = inspect.stack()[2][3] name = inspect.stack()[2][3]
fig, axes = plt.subplots(*subplots, figsize=figsize) fig, axes = plt.subplots(*subplots, figsize=figsize)
fig.canvas.set_window_title(name) #fig.canvas.set_window_title(name)
quit_figure_on_key('q', fig) #quit_figure_on_key('q', fig)
yield fig, axes yield fig, axes
if params is not None: if params is not None:
name += "\n" + repr(params) name += "\n" + repr(params)
axes[0].set_title(name) axes[0].set_title(name)
plt.show(True) #plt.show(True)
pp.savefig()

1
EKF/tests/pytest/requirements.txt

@ -2,5 +2,4 @@ pytest>=3.2.1
hypothesis>=3.17.0 hypothesis>=3.17.0
numpy>=1.12.1 numpy>=1.12.1
matplotlib>=2.0.0 matplotlib>=2.0.0
seaborn>=0.7.1
pytest-benchmark>=3.1.1 pytest-benchmark>=3.1.1

1
Jenkinsfile vendored

@ -84,6 +84,7 @@ pipeline {
sh 'make distclean' sh 'make distclean'
sh 'make test_EKF' sh 'make test_EKF'
sh 'ccache -s' sh 'ccache -s'
archiveArtifacts(artifacts: 'build/**/*.pdf')
sh 'make distclean' sh 'make distclean'
} }
} }

3
Makefile

@ -99,6 +99,9 @@ test: test_build
test_EKF: test_build test_EKF: test_build
@cmake --build $(SRC_DIR)/build/test_build --target ecl_EKF_pytest-quick @cmake --build $(SRC_DIR)/build/test_build --target ecl_EKF_pytest-quick
test_EKF_plots: test_build
@cmake --build $(SRC_DIR)/build/test_build --target ecl_EKF_pytest-plots
# Cleanup # Cleanup
# -------------------------------------------------------------------- # --------------------------------------------------------------------

Loading…
Cancel
Save