Skip to content

Commit

Permalink
fix to_glue method, add test
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan Goldbaum committed Aug 28, 2018
1 parent f0c92d2 commit 3ec7ec5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ env:
MOCK=mock
NOSETIMER=nose-timer
REQUESTS=requests
GLUE=glueviz

before_install:
- |
Expand Down Expand Up @@ -55,7 +56,7 @@ install:
pip install --upgrade wheel
pip install --upgrade setuptools
# Install dependencies
pip install $MOCK $NUMPY $SCIPY $H5PY $CYTHON $MATPLOTLIB $SYMPY $FASTCACHE $IPYTHON $FLAKE8 $CODECOV $COVERAGE $PANDAS $NOSE $NOSETIMER $REQUESTS
pip install $MOCK $NUMPY $SCIPY $H5PY $CYTHON $MATPLOTLIB $SYMPY $FASTCACHE $IPYTHON $FLAKE8 $CODECOV $COVERAGE $PANDAS $NOSE $NOSETIMER $REQUESTS $GLUE
# install yt
if [[ $TRAVIS_BUILD_STAGE_NAME != "Lint" ]]; then
pip install -e .
Expand Down
21 changes: 15 additions & 6 deletions yt/data_objects/data_containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -637,20 +637,29 @@ def to_glue(self, fields, label="yt", data_collection=None):
the Glue environment, you can pass a *data_collection* object,
otherwise Glue will be started.
"""
from yt.config import ytcfg
from glue.core import DataCollection, Data
try:
from glue.app.qt.application import GlueApplication
except ImportError:
from glue.qt.glue_application import GlueApplication

if ytcfg.getboolean("yt", "__withintesting"):
from glue.core.application_base import \
Application as GlueApplication
else:
try:
from glue.app.qt.application import GlueApplication
except ImportError:
from glue.qt.glue_application import GlueApplication
gdata = Data(label=label)
for component_name in fields:
gdata.add_component(self[component_name], component_name)

if data_collection is None:
dc = DataCollection([gdata])
app = GlueApplication(dc)
app.start()
try:
app.start()
except AttributeError:
# In testing we're using a dummy glue application object
# that doesn't have a start method
pass
else:
data_collection.append(gdata)

Expand Down
13 changes: 13 additions & 0 deletions yt/data_objects/tests/test_glue.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import nose

from yt.config import ytcfg
from yt.testing import fake_random_ds

def setup_func():
ytcfg["yt", "__withintesting"] = "True"

@nose.with_setup(setup_func)
def test_glue_data_object():
ds = fake_random_ds(16)
ad = ds.all_data()
ad.to_glue([('gas', 'density')])

0 comments on commit 3ec7ec5

Please sign in to comment.