Skip to content

Commit

Permalink
Merge pull request #35 from ericpre/fix_closing_contrast_editor_tool
Browse files Browse the repository at this point in the history
Fix closing contrast editor tool
  • Loading branch information
francisco-dlp authored Apr 13, 2021
2 parents 4acd79c + 76779bb commit fa9c1e6
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 17 deletions.
45 changes: 34 additions & 11 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,29 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 30
env:
MPLBACKEND: agg
ETS_TOOLKIT: qt
PIP_ARGS: --upgrade -e
PYTEST_ARGS: --pyargs hyperspy_gui_traitsui
PYTEST_ARGS_COVERAGE:
strategy:
fail-fast: false
matrix:
PYTHON_VERSION: [3.6, 3.7]
PYTHON_VERSION: [3.6, 3.7, 3.9]
PIP_SELECTOR: ['[tests]']
LABEL: [-RnM]
include:
- PYTHON_VERSION: 3.8
PIP_SELECTOR: '[tests, coverage]'
PYTEST_ARGS_COVERAGE: --cov=. --cov-report=xml
LABEL: /coverage
LABEL: -non_uniform-coverage
- PYTHON_VERSION: 3.8
PIP_SELECTOR: '[tests]'
LABEL: -RnP
# Currently failing, re-enable when hyperspy released.
#- PYTHON_VERSION: 3.8
# PIP_SELECTOR: '[tests]'
# LABEL: -Release

steps:
- uses: actions/checkout@v2

Expand All @@ -35,28 +44,42 @@ jobs:
python --version
pip --version
- name: Install
- name: Install HyperSpy (RELEASE_next_minor)
shell: bash
if: contains( matrix.LABEL, 'RnM')
run: |
pip install ${{ env.PIP_ARGS }} .'${{ matrix.PIP_SELECTOR }}'
pip install https://github.com/hyperspy/hyperspy/archive/RELEASE_next_minor.zip
- name: Install HyperSpy (RELEASE_next_minor)
- name: Install HyperSpy (RELEASE_next_patch)
shell: bash
if: "!contains( matrix.PYTEST_ARGS_COVERAGE, 'cov')"
if: contains( matrix.LABEL, 'RnP')
run: |
pip install https://github.com/hyperspy/hyperspy/archive/RELEASE_next_minor.zip
pip install https://github.com/hyperspy/hyperspy/archive/RELEASE_next_patch.zip
- name: Install HyperSpy (non_uniform_axis)
# Test against the hyperspy `non_uniform_axes` branch
if: contains( matrix.PYTEST_ARGS_COVERAGE, 'cov')
if: contains( matrix.LABEL, 'non_uniform')
shell: bash
run: |
pip install https://github.com/hyperspy/hyperspy/archive/non_uniform_axes.zip
- name: Run test suite
- name: Install Dependencies
run: |
pytest ${{ env.PYTEST_ARGS }} ${{ matrix.PYTEST_ARGS_COVERAGE }}
pip install pyqt5
sudo apt-get install -y libxkbcommon-x11-0 libxcb-icccm4 libxcb-image0 libxcb-keysyms1 libxcb-randr0 libxcb-render-util0 libxcb-xinerama0 libxcb-xinput0 libxcb-xfixes0
- name: Install
shell: bash
run: |
pip install ${{ env.PIP_ARGS }} .'${{ matrix.PIP_SELECTOR }}'
- name: Run test suite
# run the tests headlessly
uses: GabrielBB/xvfb-action@v1
with:
run: pytest ${{ env.PYTEST_ARGS }} ${{ matrix.PYTEST_ARGS_COVERAGE }}

- name: Upload coverage to Codecov
if: contains( matrix.PYTEST_ARGS_COVERAGE, 'cov')
uses: codecov/codecov-action@v1

Empty file.
49 changes: 49 additions & 0 deletions hyperspy_gui_traitsui/tests/test_tools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# -*- coding: utf-8 -*-
# Copyright 2007-2021 The HyperSpy developers
#
# This file is part of HyperSpy.
#
# HyperSpy is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# HyperSpy is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with HyperSpy. If not, see <http://www.gnu.org/licenses/>.

import numpy as np
import hyperspy.api as hs

from hyperspy.signal_tools import ImageContrastEditor

from hyperspy_gui_traitsui.tests.utils import KWARGS


def test_image_contrast_tool():

s = hs.signals.Signal2D(np.random.random(10000).reshape((100, 100)))
s.plot()

ceditor = ImageContrastEditor(s._plot.signal_plot)
ceditor.gui(**KWARGS)

vmin = 5
ceditor.vmin_percentile = vmin
assert ceditor.vmin_percentile == vmin

vmax = 95
ceditor.vmax_percentile = vmax
assert ceditor.vmax_percentile == vmax

auto = False
ceditor.auto = auto
assert ceditor.auto == auto

for norm in ['Linear', 'Power', 'Log', 'Symlog']:
ceditor.norm = norm
assert ceditor.norm == norm
6 changes: 0 additions & 6 deletions hyperspy_gui_traitsui/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,7 @@ def apply(self, info, *args, **kwargs):
class ImageContrastHandler(tu.Handler):

def close(self, info, is_ok):
# Removes the span selector from the plot
# info.object.span_selector_switch(False)
# if is_ok is True:
# self.apply(info)
obj = info.object
if obj.is_ok is False:
obj.image.update()
obj.close()
return True

Expand Down

0 comments on commit fa9c1e6

Please sign in to comment.