Repository: sunpy/sunpy

Issue:
Write unit tests for sunpy.io.jp2



Discussion:

Resolving patch:
diff --git a/sunpy/io/jp2.py b/sunpy/io/jp2.py
--- a/sunpy/io/jp2.py
+++ b/sunpy/io/jp2.py
@@ -35,7 +35,7 @@ def read(filepath, j2k_to_image='opj_decompress'):
     header = get_header(filepath)
     data = _get_data(filepath, j2k_to_image=j2k_to_image)
     
-    return [(data, header)]
+    return [(data, header[0])]
 
 def get_header(filepath):
     """


Test patch:
diff --git a/sunpy/tests/io/test_filetools.py b/sunpy/tests/io/test_filetools.py
--- a/sunpy/tests/io/test_filetools.py
+++ b/sunpy/tests/io/test_filetools.py
@@ -9,16 +9,16 @@
 # Test, read, get_header and write through the file independant layer
 #==============================================================================
 class TestFiletools():
-    
+
     def test_read_file_fits(self):
         #Test read FITS
-        pair = sunpy.io.read_file(sunpy.AIA_171_IMAGE)
-        assert isinstance(pair, list)
-        assert len(pair) == 1
-        assert len(pair[0]) == 2
-        assert isinstance(pair[0][0], np.ndarray)
-        assert isinstance(pair[0][1], sunpy.io.header.FileHeader)
-        
+        aiapair = sunpy.io.read_file(sunpy.AIA_171_IMAGE)
+        assert isinstance(aiapair, list)
+        assert len(aiapair) == 1
+        assert len(aiapair[0]) == 2
+        assert isinstance(aiapair[0][0], np.ndarray)
+        assert isinstance(aiapair[0][1], sunpy.io.header.FileHeader)
+
         #Test read multi HDU list
         pairs = sunpy.io.read_file(sunpy.RHESSI_IMAGE)
         assert isinstance(pairs, list)
@@ -27,29 +27,42 @@ def test_read_file_fits(self):
         assert all([isinstance(p[0], np.ndarray) for p in pairs])
         assert all([isinstance(p[1],
                                sunpy.io.header.FileHeader) for p in pairs])
-        
+
     def test_read_file_jp2(self):
-        pass
-        
         #Test read jp2
-#        pair = sunpy.io.read_file(os.path.join(sunpy.data.test.rootdir,
-#                               "2013_06_24__17_31_30_84__SDO_AIA_AIA_193.jp2"),
-#                               j2k_to_image='j2k_to_image')
-#        assert isinstance(pair, list)
-#        assert len(pair) == 1
-#        assert len(pair[0]) == 2
-#        assert isinstance(pair[0][0], np.ndarray)
-#        assert isinstance(pair[0][1], sunpy.io.header.FileHeader)
-    
-    def test_read_file_header(self):    
+        pair = sunpy.io.read_file(os.path.join(sunpy.data.test.rootdir,
+                               "2013_06_24__17_31_30_84__SDO_AIA_AIA_193.jp2"),
+                               j2k_to_image='j2k_to_image')
+        assert isinstance(pair, list)
+        assert len(pair) == 1
+        assert len(pair[0]) == 2
+        assert isinstance(pair[0][0], np.ndarray)
+        assert isinstance(pair[0][1], sunpy.io.header.FileHeader)
+
+    def test_read_file_header_fits(self):
         #Test FITS
         hlist = sunpy.io.read_file_header(sunpy.AIA_171_IMAGE)
         assert isinstance(hlist, list)
         assert len(hlist) == 1
         assert isinstance(hlist[0], sunpy.io.header.FileHeader)
-        
+
+    def test_read_file_header_jp2(self):
         #Test jp2
-    
-    #Test write FITS
-    
-    #Test write jp2
\ No newline at end of file
+        hlist = sunpy.io.read_file_header(os.path.join(sunpy.data.test.rootdir,
+                               "2013_06_24__17_31_30_84__SDO_AIA_AIA_193.jp2"))
+        assert isinstance(hlist, list)
+        assert len(hlist) == 1
+        assert isinstance(hlist[0], sunpy.io.header.FileHeader)
+
+
+    def test_write_file_fits(self):
+        #Test write FITS
+        aiapair = sunpy.io.read_file(sunpy.AIA_171_IMAGE)[0]
+        sunpy.io.write_file("aia_171_image.fits", aiapair[0], aiapair[1])
+        assert os.path.exists("aia_171_image.fits")
+        outpair = sunpy.io.read_file(sunpy.AIA_171_IMAGE)
+        assert np.all(np.equal(outpair[0][1], aiapair[1]))
+        assert outpair[0][1] == aiapair[1]
+        os.remove("aia_171_image.fits")
+
+    #Test write jp2
diff --git a/sunpy/tests/map/test_header.py b/sunpy/tests/map/test_header.py
new file mode 100644
--- /dev/null
+++ b/sunpy/tests/map/test_header.py
@@ -0,0 +1,40 @@
+# -*- coding: utf-8 -*-
+import os
+import copy
+
+import sunpy
+import sunpy.map
+#==============================================================================
+# Test, read, get_header and write through the file independant layer
+#==============================================================================
+class TestMapMeta():
+    
+    def test_upcasing(self):
+        meta = sunpy.map.MapMeta({'wibble':1, 'WOBBLE':2})
+        #__getitem__
+        assert meta['wibble'] == meta['WIBBLE']
+        #get
+        assert meta.get('wibble') == meta.get('WIBBLE')
+        #has_key
+        assert meta.has_key('wibble') == meta.has_key('WIBBLE')
+        #Copy
+        meta2 = meta.copy()
+        assert meta2 == meta
+        #pop
+        assert meta.pop('wibble') == meta2.pop('WIBBLE')
+        #update
+        meta.update({'spam':'eggs'})
+        meta2.update({'SPAM':'eggs'})
+        assert meta == meta2
+        #setdefault
+        meta.setdefault('dave',3)
+        meta2.setdefault('DAVE',3)
+        assert meta.get('DAVE') == meta2.get('dave')
+        #__setitem__
+        meta['wibble'] = 10
+        assert meta['wibble'] == 10
+        meta['WIBBLE'] = 20
+        assert meta['wibble'] == 20
+        #__contains__
+        assert 'wibble' in meta
+        assert 'WIBBLE' in meta
\ No newline at end of file