[yt-svn] commit/yt: 2 new changesets

Bitbucket commits-noreply at bitbucket.org
Tue Jan 29 04:42:31 PST 2013


2 new commits in yt:

https://bitbucket.org/yt_analysis/yt/commits/ca1589adc8e6/
changeset:   ca1589adc8e6
branch:      yt
user:        xarthisius
date:        2013-01-29 08:32:46
summary:     Get rid of libmagic dependency for plotwindow tests. Yield tests
affected #:  1 file

diff -r 597ce0513a71c07d1fe023d375d2ea31ae0ac24c -r ca1589adc8e6360795669277a0548b657f1e475c yt/visualization/tests/test_plotwindow.py
--- a/yt/visualization/tests/test_plotwindow.py
+++ b/yt/visualization/tests/test_plotwindow.py
@@ -23,23 +23,14 @@
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 """
 import os
-import sys
 import tempfile
 import shutil
 from yt.testing import \
-    fake_random_pf
+    fake_random_pf, assert_equal
 from yt.mods import \
     SlicePlot, ProjectionPlot, OffAxisSlicePlot, OffAxisProjectionPlot
 
 
-EXT_TO_TYPE = {
-    '.ps': 'PostScript document text conforming DSC level 3.0',
-    '.eps': 'PostScript document text conforming DSC level 3.0, type EPS',
-    '.pdf': 'PDF document, version 1.4',
-    '.png': 'PNG image data, 1070 x 1000, 8-bit/color RGBA, non-interlaced'
-}
-
-
 def setup():
     """Test specific setup."""
     from yt.config import ytcfg
@@ -51,19 +42,24 @@
     if fname is None:
         return
 
-    try:
-        import magic
-    except ImportError:
-        # OS X doesn't come with libmagic
-        pass
+    with open(fname, 'rb') as fimg:
+        data = fimg.read()
+    data = str(data)
+    image_type = ''
 
-    if 'magic' in sys.modules:
-        ext = os.path.splitext(fname)[1]
-        mds = magic.open(magic.MAGIC_NONE)
-        mds.load()
-        magic_text = mds.file(fname)
-        mds.close()
-        assert magic_text == EXT_TO_TYPE[ext]
+    if data.startswith('\211PNG\r\n\032\n'):
+        image_type = '.png'
+    elif data.startswith('\377\330'):
+        image_type = '.jpeg'
+    elif data.startswith('%!PS-Adobe'):
+        if 'EPSF' in data[:data.index('\n')]:
+            image_type = '.eps'
+        else:
+            image_type = '.ps'
+    elif data.startswith('%PDF'):
+        image_type = '.pdf'
+
+    return image_type == os.path.splitext(fname)[1]
 
 
 def test_plotwindow():
@@ -81,16 +77,16 @@
     for fname in test_flnms:
         for dim in [0, 1, 2]:
             obj = SlicePlot(test_pf, dim, 'Density')
-            assert_fname(obj.save(fname)[0])
+            yield assert_equal, assert_fname(obj.save(fname)[0]), True
 
             obj = ProjectionPlot(test_pf, dim, 'Density')
-            assert_fname(obj.save(fname)[0])
+            yield assert_equal, assert_fname(obj.save(fname)[0]), True
 
         obj = OffAxisSlicePlot(test_pf, normal, 'Density')
-        assert_fname(obj.save(fname)[0])
+        yield assert_equal, assert_fname(obj.save(fname)[0]), True
 
         obj = OffAxisProjectionPlot(test_pf, normal, 'Density')
-        assert_fname(obj.save(fname)[0])
+        yield assert_equal, assert_fname(obj.save(fname)[0]), True
 
     os.chdir(curdir)
     # clean up


https://bitbucket.org/yt_analysis/yt/commits/0514b030f647/
changeset:   0514b030f647
branch:      yt
user:        xarthisius
date:        2013-01-29 08:55:03
summary:     [test_plotwindow:assert_fname] Add links explaining hardcoded magic numbers
affected #:  1 file

diff -r ca1589adc8e6360795669277a0548b657f1e475c -r 0514b030f6479c0adb75df5bf3da7ab7310caa91 yt/visualization/tests/test_plotwindow.py
--- a/yt/visualization/tests/test_plotwindow.py
+++ b/yt/visualization/tests/test_plotwindow.py
@@ -47,8 +47,10 @@
     data = str(data)
     image_type = ''
 
+    # see http://www.w3.org/TR/PNG/#5PNG-file-signature
     if data.startswith('\211PNG\r\n\032\n'):
         image_type = '.png'
+    # see http://www.mathguide.de/info/tools/media-types/image/jpeg
     elif data.startswith('\377\330'):
         image_type = '.jpeg'
     elif data.startswith('%!PS-Adobe'):

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