Skip to content

Commit

Permalink
Modifies h5py as optional dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
usmanwardag committed Jun 18, 2016
1 parent 069827a commit 8079418
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 7 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,12 @@ env:
- NUMPY_VERSION=1.9
- SCIPY_VERSION=0.17.0
- ASTROPY_VERSION=stable
- H5PY_VERSION=2.5.0
- SETUP_CMD='test'
- PIP_DEPENDENCIES=''
# For this package-template, we include examples of Cython modules,
# so Cython is required for testing. If your package does not include
# Cython code, you can set CONDA_DEPENDENCIES=''
- CONDA_DEPENDENCIES='Cython numpy scipy h5py nose matplotlib'
- CONDA_DEPENDENCIES='Cython numpy scipy nose matplotlib'
matrix:
# Make sure that egg_info works without dependencies
- SETUP_CMD='egg_info'
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ environment:
PYTHON_ARCH: "64" # needs to be set for CMD_IN_ENV to succeed. If a mix
# of 32 bit and 64 bit builds are needed, move this
# to the matrix section.
CONDA_DEPENDENCIES: "scipy h5py numpy nose astropy matplotlib"
CONDA_DEPENDENCIES: "scipy numpy nose astropy matplotlib"
PIP_DEPENDENCIES: ""

matrix:
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ scipy
matplotlib
emcee
corner
h5py
9 changes: 7 additions & 2 deletions stingray/io.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import (absolute_import, division,
print_function)

import h5py
import numpy as np
import logging
import warnings
Expand Down Expand Up @@ -508,7 +507,13 @@ def write(input_, filename, format_='pickle', **kwargs):
_save_pickle_object(input_, filename)

elif format_ == 'hdf5':
_save_hdf5_object(input_, filename)
try:
import h5py
_save_hdf5_object(input_, filename)

except ImportError:
utils.simon('h5py not installed, using pickle instead to save object.')
_save_pickle_object(input_, filename)

elif format_ == 'ascii':
_save_ascii_object(input_, filename, **kwargs)
Expand Down
13 changes: 12 additions & 1 deletion stingray/tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
curdir = os.path.abspath(os.path.dirname(__file__))
datadir = os.path.join(curdir, 'data')


class TestIO(object):

"""Real unit tests."""
Expand Down Expand Up @@ -80,6 +79,15 @@ def __init__(self):
def test_operation(self):
return self.number * 10

H5PY_INSTALLED = True

try:
import h5py
except ImportError:
H5PY_INSTALLED = False

skip_condition = pytest.mark.skipif(not H5PY_INSTALLED,
reason = "H5PY not installed.")

class TestFileFormats(object):

Expand Down Expand Up @@ -111,19 +119,22 @@ def test_pickle_functions(self):
assert read('test.pickle', 'pickle').test_operation() == test_object.number * 10
os.remove('test.pickle')

@skip_condition
def test_hdf5_write(self):
"""Test write functionality of hdf5."""
test_object = TestIOReadWrite()
write(test_object, 'test.hdf5', 'hdf5')
os.remove('test.hdf5')

@skip_condition
def test_hdf5_read(self):
"""Test read functionality of hdf5."""
test_object = TestIOReadWrite()
write(test_object, 'test.hdf5', 'hdf5')
read('test.hdf5','hdf5')
os.remove('test.hdf5')

@skip_condition
def test_hdf5_data_recovery(self):
"""Test if hdf5 stored data is properly recovered."""
test_object = TestIOReadWrite()
Expand Down

0 comments on commit 8079418

Please sign in to comment.