Skip to content

Commit

Permalink
Merge 2ab54d0 into d637b6a
Browse files Browse the repository at this point in the history
  • Loading branch information
katherinekolman authored Nov 1, 2019
2 parents d637b6a + 2ab54d0 commit d438085
Show file tree
Hide file tree
Showing 7 changed files with 317 additions and 26 deletions.
54 changes: 54 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
language: python
env:
global:
# Set defaults to avoid repeating in most cases
- PYTHON_VERSION=$TRAVIS_PYTHON_VERSION
- NUMPY_VERSION=stable
- MAIN_CMD='python setup.py'
- CONDA_DEPENDENCIES='hdf5 rasterio matplotlib scipy numba pyproj coveralls pytest pytest-cov pytest-xvfb vispy pyopengl netcdf4 h5py imageio imageio-ffmpeg ffmpeg pillow pyshp pyqtgraph shapely sqlalchemy pyqt appdirs pyyaml satpy eccodes'
- PIP_DEPENDENCIES='quamash'
- SETUP_XVFB=True
- EVENT_TYPE='push pull_request'
- SETUP_CMD='test'
- CONDA_CHANNELS='conda-forge'
- CONDA_CHANNEL_PRIORITY='strict'
matrix:
include:
- env: PYTHON_VERSION=3.7
os: linux
- env: PYTHON_VERSION=3.7
os: osx
language: generic
- env: PYTHON_VERSION=3.7
os: windows
language: shell
install:
- git clone --depth 1 git://github.com/astropy/ci-helpers.git
- source ci-helpers/travis/setup_conda.sh
- if [ "${TRAVIS_OS_NAME}" = "windows" ]; then git clone --depth 1 git://github.com/vtkiorg/gl-ci-helpers.git; fi;
- if [ "${TRAVIS_OS_NAME}" = "windows" ]; then powershell -Command "Set-ExecutionPolicy RemoteSigned -scope CurrentUser"; fi;
- if [ "${TRAVIS_OS_NAME}" = "windows" ]; then powershell gl-ci-helpers/appveyor/install_opengl.ps1; fi;
- if [ "${TRAVIS_OS_NAME}" = "windows" ]; then pip install PyQt5==5.9; fi;

before_script:
- export DISPLAY=:99.0
- if [ "${TRAVIS_OS_NAME}" = "osx" ]; then ( sudo Xvfb :99 -ac -screen 0 1400x900x24 +render +iglx; echo ok )& fi;
#- if [ "${TRAVIS_OS_NAME}" = "linux" ]; then
# /sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_99.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :99 -screen 0 1400x900x24 -ac +extension GLX +render;
# fi;
script:
- if [ "${TRAVIS_OS_NAME}" = "linux" ] || [ "${TRAVIS_OS_NAME}" = "osx" ]; then conda install pygrib; fi;
- pip install -e .
- pytest -s --cov-report term --cov=uwsift uwsift/tests
after_success:
- if [[ $PYTHON_VERSION == 3.7 ]]; then coveralls; fi;
#deploy:
# - provider: pypi
# user: dhoese
# password:
# # secure: frK+0k1STeTM7SizRseP0qdTfOVz9ZMIra+3qEytPdxCLceXAH8LxPU16zj5rdNQxasF1hZ6rAd952fly+ypw2TEf5r2WnStrt7G5QlyE7VB6XGSDpIUxKF1FYccLvYs0/R6Y35MTEPqdM51PM5yEBjoY5b4tA3RF3fDq11cqc/SiWr6DgSLB1WJZULOdtCzBbfGbm5LyJ7yeNbISASSAwVvZTGWw7kJDgi0W5zxwEX82N5tBGbfKIu59qmxyj8FxmcrUwKZ4P3rQNg1kN1utzAB+PSf3GAVvbZfWJQuAKwMqpZgaV9lX0V7eUd/AxPobzEk9WyoNBMIdrSPej5BKWTDiYvaeRTOsggoUCSQJJA/SITEvkJgLWXoKKX2OWrM8RBUO4MoZJpPGXN42PRtMJkV2sx6ZigkpJlHdn39SsIRZX31zsfv8bBhclb70bt1Ts0fDd0rVdZAI6gMI+sgUePwEUn+XbWrvI0sMfDX3QsXDMV393RHgaIPxd+lRqUlYsNOxjsWpsbsvX55ePLxYHsNrv11KKyL/iGjGotVeVUO5D78qvfd4JrsUnMalQyZfW8NTEKa5Ebcs7gYJTwYEOTCQU12BkHOv1zFkjZG5RdGwkEvG3pykLhx+qDyYEd7pKB3TvhzLPqZPSrPxirwcoc0UzCc6ocYdzpqVuViFuk=
# distributions: sdist
# skip_existing: true`
# on:
# tags: true
# repo: sift/sift
16 changes: 8 additions & 8 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
include sift/data/shadedrelief.jpg
include sift/data/ne_50m_admin_0_countries/*
include sift/data/ne_110m_admin_0_countries/*
include sift/data/ne_50m_admin_1_states_provinces_lakes/*
recursive-include sift/data/fonts *.ttf
recursive-include sift/data/colormaps *.cmap
recursive-include sift/data/grib_definitions *.def
include sift/ui/*.ui
include uwsift/data/shadedrelief.jpg
include uwsift/data/ne_50m_admin_0_countries/*
include uwsift/data/ne_110m_admin_0_countries/*
include uwsift/data/ne_50m_admin_1_states_provinces_lakes/*
recursive-include uwsift/data/fonts *.ttf
recursive-include uwsift/data/colormaps *.cmap
recursive-include uwsift/data/grib_definitions *.def
include uwsift/ui/*.ui
include LICENSE.txt
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,9 @@ def run(self):
include_package_data=True,
install_requires=['numpy', 'pillow', 'scipy', 'numba', 'vispy>=0.6.0',
'PyOpenGL', 'netCDF4', 'h5py', 'pyproj',
'pyshp', 'shapely', 'rasterio', 'goesr', 'sqlalchemy',
'goesr', 'appdirs', 'pyyaml', 'pyqtgraph', 'satpy',
'pygrib', 'imageio', 'pyqt5>=5.9'
'pyshp', 'shapely', 'rasterio', 'sqlalchemy',
'appdirs', 'pyyaml', 'pyqtgraph', 'satpy',
'pygrib;sys_platform=="linux" or sys_platform=="darwin"', 'imageio', 'pyqt5>=5.9'
],
python_requires='>=3.6',
extras_require=extras_require,
Expand Down
6 changes: 3 additions & 3 deletions sift.spec
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import distributed

block_cipher = None
exe_name = "SIFT"
main_script_pathname = os.path.join("sift", "__main__.py")
main_script_pathname = os.path.join("uwsift", "__main__.py")
_script_base = os.path.dirname(os.path.realpath(sys.argv[0]))

data_files = [
Expand All @@ -22,7 +22,7 @@ data_files = [

for shape_dir in ["ne_50m_admin_0_countries", "ne_110m_admin_0_countries", "ne_50m_admin_1_states_provinces_lakes",
"fonts", "colormaps", "grib_definitions"]:
data_files.append((os.path.join("sift", "data", shape_dir), os.path.join("sift_data", shape_dir)))
data_files.append((os.path.join("uwsift", "data", shape_dir), os.path.join("sift_data", shape_dir)))

hidden_imports = [
"vispy.ext._bundled.six",
Expand Down Expand Up @@ -66,7 +66,7 @@ else:
bin_dir = sys.executable.replace("python.exe", os.path.join("Library", "bin"))
lib_dir = sys.executable.replace("python.exe", os.path.join("Library", "lib"))
binaries += [(os.path.join(bin_dir, 'ffmpeg.exe'), '.')]

# Add ffmpeg dependencies that pyinstaller doesn't automatically find
if is_linux:
so_ext = '.so*'
Expand Down
230 changes: 230 additions & 0 deletions uwsift/tests/view/export_image_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,230 @@
import PyQt5.QtWebEngineWidgets
from uwsift.__main__ import Main
from uwsift.util.default_paths import USER_CONFIG_DIR
from uwsift.view import export_image
from numpy.testing import assert_array_equal
from PIL import Image
from matplotlib import pyplot as plt
from collections import namedtuple
import pytest
import datetime
import os
import imageio


#window = Main(config_dir=USER_CONFIG_DIR, workspace_dir=tmpdir)

@pytest.fixture(scope="session")
def window(tmp_path_factory):
d = tmp_path_factory.mktemp("tmp")
window = Main(config_dir=USER_CONFIG_DIR, workspace_dir=str(d))
return window

def _get_mock_doc():
class MockPrez():
def __init__(self):
self.colormap = 'Rainbow (IR Default)'
self.climits = (0, 1)

class MockDocBasicLayer():
def __init__(self):
self.attrs = {}
self.attrs['unit_conversion'] = ('unit', lambda t: t, lambda t: t)
self.attrs['timeline'] = datetime.datetime(2000, 1, 1, 0, 0, 0, 0)
self.attrs['display_name'] = 'name'

def __getitem__(self, item):
return self.attrs[item]

class MockDoc():
def __init__(self):
self.layer = MockDocBasicLayer()
self.prez = MockPrez()

def __getitem__(self, item):
return self.layer

def colormap_for_uuid(self, u):
return 'Rainbow (IR Default)'

def prez_for_uuid(self, u):
return MockPrez()

return MockDoc()


def _get_mock_sd(fr, fn):
class MockScreenshotDialog:
def __init__(self, frame_range, filename):
self.info = {
'frame_range': frame_range,
'include_footer': True,
'filename': filename,
'colorbar': True,
'font_size': 10,
'loop': True,
}

def get_info(self):
return self.info

return MockScreenshotDialog(fr, fn)


def _get_mock_sgm(frame_order):
class MockLayerSet:
def __init__(self, fo):
self.frame_order = fo

def top_layer_uuid(self):
return 1

class MockSGM:
def __init__(self, fo):
self.layer_set = MockLayerSet(fo)

def get_screenshot_array(self, fr):
if fr is None:
return None
return [[fr[1], fr[1] - fr[0]]]

return MockSGM(frame_order)


def _get_mock_writer():
class MockWriter:
def __init__(self):
self.data = []

def append_data(self, data):
self.data.append(data)

def close(self):
pass

return MockWriter()


@pytest.mark.parametrize("size,exp,mode", [
((100, 100), [0.1, 1.2], 'vertical'),
((100, 100), [1.2, 0.1], 'horizontal'),
((0, 0), [0, 0], 'vertical'),
])
def test_create_colorbar(size, exp, mode, monkeypatch, window):
monkeypatch.setattr(window.export_image, 'doc', _get_mock_doc())
monkeypatch.setattr(window.export_image.sgm.main_canvas, 'dpi', 100)

res = window.export_image._create_colorbar(mode, None, size)

assert_array_equal(res.get_size_inches(), exp)
assert res.dpi == 100


@pytest.mark.parametrize("mode,size,cbar_size", [
(None, (100, 100), (0, 0)),
('vertical', (108, 100), (10, 120)),
('horizontal', (100, 108), (120, 10)),
])
def test_append_colorbar(mode, size, cbar_size, monkeypatch, window):
monkeypatch.setattr(window.export_image, 'doc', _get_mock_doc())
monkeypatch.setattr(window.export_image.sgm.main_canvas, 'dpi', 100)
monkeypatch.setattr(window.export_image, '_create_colorbar', lambda x, y, z: plt.figure(figsize=cbar_size))

im = Image.new('RGBA', (100, 100))
res = window.export_image._append_colorbar(mode, im, None)

assert res.size == size


def test_add_screenshot_footer(window):
im = Image.new('RGBA', (100, 100))
res = window.export_image._add_screenshot_footer(im, 'text', font_size=10)
assert res.size == (100, 110)


@pytest.mark.parametrize('range,exp', [
(None, None),
((None, 2), (0, 1)),
((1, None), (0, 0)),
((1, 5), (0, 4)),
])
def test_convert_frame_range(range, exp, window):
res = window.export_image._convert_frame_range(range)
assert res == exp


@pytest.mark.parametrize('info,isgif,exp', [
({'fps': None, 'filename': None, 'loop': 0}, True, {'duration': [0.1, 0.1], 'loop': 0}),
({'fps': None, 'filename': None, 'loop': 0}, False, {'fps': 10}),
({'fps': 1, 'filename': None}, True, {'fps': 1, 'loop': 0}),
({'fps': 1, 'filename': None}, False, {'fps': 1})
])
def test_get_animation_parameters(info, isgif, exp, monkeypatch, window):
monkeypatch.setattr(window.export_image, 'doc', _get_mock_doc())
monkeypatch.setattr(export_image, 'is_gif_filename', lambda x: isgif)

im = Image.new('RGBA', (100, 100))

res = window.export_image._get_animation_parameters(info, [(0, im), (0, im)])
assert res == exp


@pytest.mark.parametrize('fn,exp', [
('test.gif', True),
('test.png', False)
])
def test_is_gif_filename(fn, exp):
res = export_image.is_gif_filename(fn)
assert res == exp


@pytest.mark.parametrize('fn,exp', [
('test.gif', True),
('test.m4v', True),
('test.mp4', True),
('test.png', False)
])
def test_is_video_filename(fn, exp):
res = export_image.is_video_filename(fn)
assert res == exp


@pytest.mark.parametrize('uuids,base,exp', [
([0, 0], 'test.gif', ([0, 0], ["test.gif"])),
([0, 0], 'test.png', ([0, 0], ["test_001.png", "test_002.png"])),
(None, 'test.gif', ([None], ['test.gif']))
])
def test_create_filenames(uuids, base, exp, monkeypatch, window):
monkeypatch.setattr(window.export_image, 'doc', _get_mock_doc())
res = window.export_image._create_filenames(uuids, base)
assert res == exp


@pytest.mark.parametrize('fr,fn,overwrite,exp', [
([1, 2], 'test.gif', True, 1),
([1, 2], 'test.m4v', True, 1),
(None, 'test.m4v', True, 0),
([1, 2], 'test.gif', False, 0)
])
def test_save_screenshot(fr, fn, overwrite, exp, monkeypatch, window):
writer = _get_mock_writer()
IFormat = namedtuple('IFormat', 'name')

monkeypatch.setattr(window.export_image, '_screenshot_dialog', _get_mock_sd(fr, fn))
monkeypatch.setattr(window.export_image, '_convert_frame_range', lambda x: fr)
monkeypatch.setattr(window.export_image, 'sgm', _get_mock_sgm(fr))
monkeypatch.setattr(window.export_image, '_create_filenames', lambda x, y: ([1], [fn]))
monkeypatch.setattr(window.export_image, 'doc', _get_mock_doc())
monkeypatch.setattr(window.export_image, '_overwrite_dialog', lambda: overwrite)
monkeypatch.setattr(window.export_image, '_append_colorbar', lambda x, y, z: y)
monkeypatch.setattr(window.export_image, '_add_screenshot_footer', lambda x, y, font_size=10: x)
monkeypatch.setattr(window.export_image, '_get_animation_parameters', lambda x, y: {'loop': True})
monkeypatch.setattr(export_image, 'get_imageio_format', lambda x: IFormat(name='test'))
monkeypatch.setattr(os.path, 'isfile', lambda x: True)
monkeypatch.setattr(Image, 'fromarray', lambda x: x)
monkeypatch.setattr(imageio, 'get_writer', lambda x, y: writer)

window.export_image._save_screenshot()

assert len(writer.data) == exp

Loading

0 comments on commit d438085

Please sign in to comment.