[yt-svn] commit/yt: xarthisius: Merged in ngoldbaum/yt (pull request #1662)

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Thu Aug 6 07:14:31 PDT 2015


1 new commit in yt:

https://bitbucket.org/yt_analysis/yt/commits/5157b9fc6114/
Changeset:   5157b9fc6114
Branch:      yt
User:        xarthisius
Date:        2015-08-06 14:14:19+00:00
Summary:     Merged in ngoldbaum/yt (pull request #1662)

[BUGFIX] Avoid hard-to-decipher tracebacks when loading empty files or directories
Affected #:  4 files

diff -r fffa77d2fdc205b54fb87befaa50ade850f826d6 -r 5157b9fc61144f54817ec418fdfba9e484c842a7 yt/frontends/gadget/data_structures.py
--- a/yt/frontends/gadget/data_structures.py
+++ b/yt/frontends/gadget/data_structures.py
@@ -264,7 +264,11 @@
         # or the byte swapped equivalents (65536 and 134217728).
         # The int32 following the header (first 4+256 bytes) must equal this
         # number.
-        (rhead,) = struct.unpack('<I',f.read(4))
+        try:
+            (rhead,) = struct.unpack('<I',f.read(4))
+        except struct.error:
+            f.close()
+            return False, 1
         # Use value to check endianess
         if rhead == 256:
             endianswap = '<'

diff -r fffa77d2fdc205b54fb87befaa50ade850f826d6 -r 5157b9fc61144f54817ec418fdfba9e484c842a7 yt/frontends/stream/tests/test_outputs.py
--- /dev/null
+++ b/yt/frontends/stream/tests/test_outputs.py
@@ -0,0 +1,45 @@
+"""
+Tests for loading in-memory datasets
+
+
+
+"""
+
+#-----------------------------------------------------------------------------
+# Copyright (c) 2013, yt Development Team.
+#
+# Distributed under the terms of the Modified BSD License.
+#
+# The full license is in the file COPYING.txt, distributed with this software.
+#-----------------------------------------------------------------------------
+
+import os
+import shutil
+import tempfile
+import unittest
+
+from yt.testing import assert_raises
+from yt.utilities.answer_testing.framework import data_dir_load
+from yt.utilities.exceptions import YTOutputNotIdentified
+
+class TestEmptyLoad(unittest.TestCase):
+
+    def setUp(self):
+        self.tmpdir = tempfile.mkdtemp()
+        self.curdir = os.getcwd()
+        os.chdir(self.tmpdir)
+
+        # create 0 byte file
+        open("empty_file", "a")
+
+        # create empty directory
+        os.makedirs("empty_directory")
+
+    def tearDown(self):
+        os.chdir(self.curdir)
+        shutil.rmtree(self.tmpdir)
+
+    def test_load_empty_file(self):
+        assert_raises(YTOutputNotIdentified, data_dir_load, "not_a_file")
+        assert_raises(YTOutputNotIdentified, data_dir_load, "empty_file")
+        assert_raises(YTOutputNotIdentified, data_dir_load, "empty_directory")

diff -r fffa77d2fdc205b54fb87befaa50ade850f826d6 -r 5157b9fc61144f54817ec418fdfba9e484c842a7 yt/frontends/tipsy/data_structures.py
--- a/yt/frontends/tipsy/data_structures.py
+++ b/yt/frontends/tipsy/data_structures.py
@@ -255,7 +255,7 @@
             f.seek(0, os.SEEK_SET)
             #Read in the header
             t, n, ndim, ng, nd, ns = struct.unpack("<diiiii", f.read(28))
-        except IOError:
+        except (IOError, struct.error):
             return False, 1
         endianswap = "<"
         #Check Endianness

diff -r fffa77d2fdc205b54fb87befaa50ade850f826d6 -r 5157b9fc61144f54817ec418fdfba9e484c842a7 yt/utilities/hierarchy_inspection.py
--- a/yt/utilities/hierarchy_inspection.py
+++ b/yt/utilities/hierarchy_inspection.py
@@ -32,6 +32,9 @@
 
     counters = [Counter(mro) for mro in mros]
 
+    if len(counters) == 0:
+        return counters
+
     count = reduce(lambda x, y: x + y, counters)
 
     return [x for x in count.keys() if count[x] == 1]

Repository URL: https://bitbucket.org/yt_analysis/yt/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.



More information about the yt-svn mailing list