[Scipy-svn] r4096 - in trunk/scipy/io/arff/tests: . data

scipy-svn@scip... scipy-svn@scip...
Mon Apr 7 14:21:29 CDT 2008


Author: cdavid
Date: 2008-04-07 14:21:25 -0500 (Mon, 07 Apr 2008)
New Revision: 4096

Added:
   trunk/scipy/io/arff/tests/data/test2.arff
Modified:
   trunk/scipy/io/arff/tests/test_header.py
Log:
Add test for parsing type in header of arff files.

Added: trunk/scipy/io/arff/tests/data/test2.arff
===================================================================
--- trunk/scipy/io/arff/tests/data/test2.arff	2008-04-07 19:13:43 UTC (rev 4095)
+++ trunk/scipy/io/arff/tests/data/test2.arff	2008-04-07 19:21:25 UTC (rev 4096)
@@ -0,0 +1,15 @@
+@RELATION test2
+
+@ATTRIBUTE attr0	REAL
+@ATTRIBUTE attr1 	real
+@ATTRIBUTE attr2 	integer
+@ATTRIBUTE attr3	Integer
+@ATTRIBUTE attr4 	Numeric
+@ATTRIBUTE attr5	numeric
+@ATTRIBUTE attr6 	string
+@ATTRIBUTE attr7 	STRING
+@ATTRIBUTE attr8 	{bla}
+@ATTRIBUTE attr9 	{bla, bla}
+
+@DATA
+0.1, 0.2, 0.3, 0.4,class1

Modified: trunk/scipy/io/arff/tests/test_header.py
===================================================================
--- trunk/scipy/io/arff/tests/test_header.py	2008-04-07 19:13:43 UTC (rev 4095)
+++ trunk/scipy/io/arff/tests/test_header.py	2008-04-07 19:21:25 UTC (rev 4096)
@@ -4,13 +4,25 @@
 
 from scipy.testing import *
 
-from scipy.io.arff.arffread import read_header, MetaData
+from scipy.io.arff.arffread import read_header, MetaData, parse_type
 
 data_path = os.path.join(os.path.dirname(__file__), 'data')
 
 test1 = os.path.join(data_path, 'test1.arff')
+test2 = os.path.join(data_path, 'test2.arff')
 
 class HeaderTest(TestCase):
+    def test_type_parsing(self):
+        """Test parsing type of attribute from their value."""
+        ofile = open(test2)
+        rel, attrs = read_header(ofile)
+
+        expected = ['numeric', 'numeric', 'numeric', 'numeric', 'numeric',
+                    'numeric', 'string', 'string', 'nominal', 'nominal']
+
+        for i in range(len(attrs)):
+            assert parse_type(attrs[i][1]) == expected[i]
+
     def test_fullheader1(self):
         """Parsing trivial header with nothing."""
         ofile = open(test1)



More information about the Scipy-svn mailing list