Skip to content

Commit

Permalink
Merge 1d6f2ba into 1158b95
Browse files Browse the repository at this point in the history
  • Loading branch information
ericpre committed Dec 6, 2018
2 parents 1158b95 + 1d6f2ba commit 90c77ab
Show file tree
Hide file tree
Showing 64 changed files with 122 additions and 137 deletions.
13 changes: 6 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,16 @@ before_install:
install:

- if [[ $MINIMAL_ENV == 'False' ]] ; then
DEPS="pip numpy scipy matplotlib=2.2.3 ipython h5py sympy scikit-learn dill natsort setuptools scikit-image cython ipyparallel dask traits traitsui numexpr numba";
else DEPS="pip ipython numpy scipy matplotlib=2.2.3 h5py sympy scikit-image numexpr";
DEPS="pip numpy scipy matplotlib>2.2.3 ipython h5py sympy scikit-learn dill natsort setuptools scikit-image cython ipyparallel dask traits traitsui numexpr numba";
else DEPS="pip ipython numpy scipy matplotlib>2.2.3 h5py sympy scikit-image numexpr";
fi
- conda create -n testenv --yes python=$PYTHON;
source activate testenv;
conda install -y -c conda-forge $DEPS;
- if [[ $MINIMAL_ENV == 'False' ]] ; then
pip install .[all];
else pip install .;
pip install .[dev] && pip install 'matplotlib>=3.0.0';
else pip install "matplotlib>=3.0.0" && pip install .[tests];
fi
- python setup.py build_ext --inplace;

before_script: # configure a headless display to test plot generation
- if [ "${TRAVIS_OS_NAME}" = "linux" ]; then sh -e /etc/init.d/xvfb start; fi
Expand All @@ -64,8 +63,8 @@ before_script: # configure a headless display to test plot generation

script:
- python -c 'import matplotlib.pyplot as plt; print(plt.get_backend())';
- pip install coverage coveralls pytest pytest-cov pytest-mpl;
py.test --mpl --cov=hyperspy --pyargs hyperspy;
- pip install coverage coveralls pytest-cov;
pytest --mpl --cov=hyperspy --pyargs hyperspy;

#after_failure: # run only on failure in case there is a need to check matplotlib image comparison
# This needs a service to upload the artifacts (and corresponding configuration)
Expand Down
10 changes: 4 additions & 6 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ environment:

global:
TEST_DEPS: "pytest pytest-cov pytest-mpl wheel"
DEPS: "numpy scipy matplotlib=2.2.3 ipython h5py sympy scikit-learn dill setuptools natsort scikit-image cython ipyparallel dask numexpr sparse numba"
DEPS: "numpy scipy matplotlib ipython h5py sympy scikit-learn dill setuptools natsort scikit-image cython ipyparallel dask numexpr sparse numba pywinpty"
MPLBACKEND: "agg"


Expand Down Expand Up @@ -47,19 +47,17 @@ install:

# Install the dependencies of the project.
- ps: Add-AppveyorMessage "Installing conda packages..."
- "conda install -yq -c conda-forge %TEST_DEPS%"
- "conda install -yq -c conda-forge %DEPS%"
- "conda install -yq -c conda-forge %DEPS% %TEST_DEPS%"

- ps: Add-AppveyorMessage "Installing hyperspy..."
- "pip install .[all]"
- "pip install \"matplotlib>=3.0.0\" & pip install .[dev]"

build: false # Not a C# project, build stuff at the test step instead.

test_script:
# Run the project tests
- ps: Add-AppveyorMessage "Running tests..."
- "python setup.py build_ext --inplace"
- "py.test --mpl"
- "pytest --mpl"
- "python setup.py clean"
- ps: Add-AppveyorMessage "Testing completed."

Expand Down
1 change: 0 additions & 1 deletion doc/README.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
1. To build the documentation you need the following libraries to be installed:
- sphinx
- numpydoc
- sphinxcontrib-napoleon
- sphinx_rtd_theme
2. Run the make command in this folder, for example 'make html' to build the whole documentation in html format. See the make command documentation for more details.
11 changes: 2 additions & 9 deletions doc/dev_guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -239,18 +239,11 @@ If you need to add or change some plots, follow the workflow below:
3. Run again the tests and this time they should pass.
4. Use ``git add`` to put the new file in the git repository.

During the execution of plot tests, the figures are created but not deleted
after execution. It is necessary to delete the figure and this can be done
by using mpl_cleanup fixture: you juste need to add ``mpl_cleanup``
as the first argument of the tests.

When the plotting tests are failling, it is possible to download the figure comparison images generated by pytest-mpl in the `artifacts tabs <https://ci.appveyor.com/project/hyperspy/hyperspy/build/1.0.2500/job/2c2qccaktd90po2q/artifacts>`_ of the corresponding build.


The plotting tests need matplotlib > 2.0.0, since the matplotlib `style change
<http://matplotlib.org/style_changes.html>`_ between matplotlib 1.x and 2.x is
enough to make the test failed. Freetype>=2.8 is also required to pass the
plotting tests.
The plotting tests need matplotlib > 3.0.0, since small changes in the way
matplotlib generates the figure can make the tests fail.

In travis and appveyor, the matplotlib backend is set to ``agg`` by setting
the ``MPLBACKEND`` environment variable to ``agg``. At the first import of
Expand Down
10 changes: 1 addition & 9 deletions hyperspy/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,4 @@ def setup_module(mod):
import dask
dask.set_options(get=dask.local.get_sync)


@pytest.fixture
def mpl_cleanup():
from matplotlib.testing.decorators import _do_cleanup

original_units_registry = matplotlib.units.registry.copy()
original_settings = matplotlib.rcParams.copy()
yield
_do_cleanup(original_units_registry, original_settings)
from matplotlib.testing.conftest import mpl_test_settings
15 changes: 7 additions & 8 deletions hyperspy/io_plugins/msa.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,9 @@ def parse_msa_string(string, filename=None):
# The data parameter needs some extra care
# It is necessary to change the locale to US english to read the date
# keyword
loc = locale.getlocale(locale.LC_TIME)
# Setting locale can raise an exception because
# their name depends on library versions, platform etc.
# https://docs.python.org/3.7/library/locale.html
try:
if os_name == 'posix':
locale.setlocale(locale.LC_TIME, ('en_US', 'utf8'))
Expand All @@ -232,18 +232,17 @@ def parse_msa_string(string, filename=None):
mapped.set_item('General.time', time.time().isoformat())
except BaseException:
if 'TIME' in parameters and parameters['TIME']:
_logger.warning('The time information could not be retrieved')
_logger.warning('The time information could not be retrieved.')
try:
date = dt.strptime(parameters['DATE'], "%d-%b-%Y")
mapped.set_item('General.date', date.date().isoformat())
except BaseException:
if 'DATE' in parameters and parameters['DATE']:
_logger.warning('The date information could not be retrieved')
except BaseException:
warnings.warn("I couldn't read the date information due to"
"an unexpected error. Please report this error to "
"the developers")
locale.setlocale(locale.LC_TIME, loc) # restore saved locale
_logger.warning('The date information could not be retrieved.')
except locale.Error:
_logger.warning("The date and time could not be retrieved because the "
"english US locale is not installed on the system.")
locale.setlocale(locale.LC_TIME, '') # restore user’s default settings

axes = [{
'size': len(y),
Expand Down
Binary file modified hyperspy/tests/drawing/plot_markers/test_plot_eds_lines.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified hyperspy/tests/drawing/plot_model1d/test_default_signal_plot.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified hyperspy/tests/drawing/plot_model1d/test_plot_components.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified hyperspy/tests/drawing/plot_roi/test_plot_circle_roi_signal.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified hyperspy/tests/drawing/plot_signal2d/test_plot_log_scale.png
2 changes: 1 addition & 1 deletion hyperspy/tests/drawing/test_mpl_testing_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def test_mpl_version():
" not working.",
strict=True)
@pytest.mark.mpl_image_compare(baseline_dir='', tolerance=2)
def test_plotting_test_working(mpl_cleanup):
def test_plotting_test_working():
# If this test passes, it means that the plotting tests are not working!
# In this case, the test will be reported as failed because the xfail is
# 'strict'.
Expand Down
38 changes: 19 additions & 19 deletions hyperspy/tests/drawing/test_plot_markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def test_add_marker_not_plot(self):
m = markers.point(x=5, y=5)
s.add_marker(m, plot_marker=False)

def test_add_marker_signal1d_navigation_dim(self, mpl_cleanup):
def test_add_marker_signal1d_navigation_dim(self):
s = Signal1D(np.zeros((3, 50, 50)))
m0 = markers.point(5, 5)
m1 = markers.point((5, 10), (10, 15))
Expand All @@ -147,7 +147,7 @@ def test_add_marker_signal1d_navigation_dim(self, mpl_cleanup):
s.add_marker(m1)
s.add_marker(m2)

def test_add_marker_signal2d_navigation_dim(self, mpl_cleanup):
def test_add_marker_signal2d_navigation_dim(self):
s = Signal2D(np.zeros((3, 50, 50)))
m0 = markers.point(5, 5)
m1 = markers.point((5, 10), (10, 15))
Expand All @@ -157,7 +157,7 @@ def test_add_marker_signal2d_navigation_dim(self, mpl_cleanup):
s.add_marker(m1)
s.add_marker(m2)

def test_add_markers_as_list(self, mpl_cleanup):
def test_add_markers_as_list(self):
s = Signal1D(np.arange(10))
marker_list = []
for i in range(12):
Expand All @@ -167,7 +167,7 @@ def test_add_markers_as_list(self, mpl_cleanup):

class Test_permanent_markers:

def test_add_permanent_marker(self, mpl_cleanup):
def test_add_permanent_marker(self):
s = Signal1D(np.arange(10))
m = markers.point(x=5, y=5)
s.add_marker(m, permanent=True)
Expand All @@ -179,7 +179,7 @@ def test_add_permanent_marker_not_plot(self):
s.add_marker(m, permanent=True, plot_marker=False)
assert list(s.metadata.Markers)[0][1] == m

def test_remove_permanent_marker_name(self, mpl_cleanup):
def test_remove_permanent_marker_name(self):
s = Signal1D(np.arange(10))
m = markers.point(x=5, y=5)
m.name = 'test'
Expand All @@ -188,7 +188,7 @@ def test_remove_permanent_marker_name(self, mpl_cleanup):
del s.metadata.Markers.test
assert len(list(s.metadata.Markers)) == 0

def test_permanent_marker_names(self, mpl_cleanup):
def test_permanent_marker_names(self):
s = Signal1D(np.arange(10))
m0 = markers.point(x=5, y=5)
m1 = markers.point(x=5, y=5)
Expand All @@ -201,22 +201,22 @@ def test_permanent_marker_names(self, mpl_cleanup):
assert s.metadata.Markers.test1 == m1
assert m1.name == 'test1'

def test_add_permanent_marker_twice(self, mpl_cleanup):
def test_add_permanent_marker_twice(self):
s = Signal1D(np.arange(10))
m = markers.point(x=5, y=5)
s.add_marker(m, permanent=True)
with pytest.raises(ValueError):
s.add_marker(m, permanent=True)

def test_add_permanent_marker_twice_different_signal(self, mpl_cleanup):
def test_add_permanent_marker_twice_different_signal(self):
s0 = Signal1D(np.arange(10))
s1 = Signal1D(np.arange(10))
m = markers.point(x=5, y=5)
s0.add_marker(m, permanent=True)
with pytest.raises(ValueError):
s1.add_marker(m, permanent=True)

def test_add_several_permanent_markers(self, mpl_cleanup):
def test_add_several_permanent_markers(self):
s = Signal1D(np.arange(10))
m_point = markers.point(x=5, y=5)
m_line = markers.line_segment(x1=5, x2=10, y1=5, y2=10)
Expand All @@ -238,15 +238,15 @@ def test_add_several_permanent_markers(self, mpl_cleanup):
with pytest.raises(ValueError):
s.add_marker(m_rect, permanent=True)

def test_add_markers_as_list(self, mpl_cleanup):
def test_add_markers_as_list(self):
s = Signal1D(np.arange(10))
marker_list = []
for i in range(10):
marker_list.append(markers.point(1, 2))
s.add_marker(marker_list, permanent=True)
assert len(s.metadata.Markers) == 10

def test_add_markers_as_list_add_same_twice(self, mpl_cleanup):
def test_add_markers_as_list_add_same_twice(self):
s = Signal1D(np.arange(10))
marker_list = []
for i in range(10):
Expand All @@ -255,7 +255,7 @@ def test_add_markers_as_list_add_same_twice(self, mpl_cleanup):
with pytest.raises(ValueError):
s.add_marker(marker_list, permanent=True)

def test_add_markers_as_list_add_different_twice(self, mpl_cleanup):
def test_add_markers_as_list_add_different_twice(self):
s = Signal1D(np.arange(10))
marker_list0 = []
for i in range(10):
Expand All @@ -268,13 +268,13 @@ def test_add_markers_as_list_add_different_twice(self, mpl_cleanup):
s.add_marker(marker_list1, permanent=True)
assert len(s.metadata.Markers) == 20

def test_add_permanent_marker_signal2d(self, mpl_cleanup):
def test_add_permanent_marker_signal2d(self):
s = Signal2D(np.arange(100).reshape(10, 10))
m = markers.point(x=5, y=5)
s.add_marker(m, permanent=True)
assert list(s.metadata.Markers)[0][1] == m

def test_deepcopy_permanent_marker(self, mpl_cleanup):
def test_deepcopy_permanent_marker(self):
x, y, color, name = 2, 9, 'blue', 'test_point'
s = Signal2D(np.arange(100).reshape(10, 10))
m = markers.point(x=x, y=y, color=color)
Expand Down Expand Up @@ -372,7 +372,7 @@ def _test_plot_rectange_markers():

@pytest.mark.mpl_image_compare(
baseline_dir=baseline_dir, tolerance=default_tol, style=style_pytest_mpl)
def test_plot_rectange_markers(mpl_cleanup):
def test_plot_rectange_markers():
im = _test_plot_rectange_markers()
return im._plot.signal_plot.figure

Expand All @@ -397,7 +397,7 @@ def _test_plot_point_markers():

@pytest.mark.mpl_image_compare(
baseline_dir=baseline_dir, tolerance=default_tol, style=style_pytest_mpl)
def test_plot_point_markers(mpl_cleanup):
def test_plot_point_markers():
s = _test_plot_point_markers()
return s._plot.signal_plot.figure

Expand All @@ -421,14 +421,14 @@ def _test_plot_text_markers():

@pytest.mark.mpl_image_compare(
baseline_dir=baseline_dir, tolerance=default_tol, style=style_pytest_mpl)
def test_plot_text_markers_nav(mpl_cleanup):
def test_plot_text_markers_nav():
s = _test_plot_text_markers()
return s._plot.navigator_plot.figure


@pytest.mark.mpl_image_compare(
baseline_dir=baseline_dir, tolerance=default_tol, style=style_pytest_mpl)
def test_plot_text_markers_sig(mpl_cleanup):
def test_plot_text_markers_sig():
s = _test_plot_text_markers()
return s._plot.signal_plot.figure

Expand All @@ -455,7 +455,7 @@ def _test_plot_line_markers():

@pytest.mark.mpl_image_compare(
baseline_dir=baseline_dir, tolerance=default_tol, style=style_pytest_mpl)
def test_plot_line_markers(mpl_cleanup):
def test_plot_line_markers():
im = _test_plot_line_markers()
return im._plot.signal_plot.figure

Expand Down

0 comments on commit 90c77ab

Please sign in to comment.