[Scipy-svn] r6783 - trunk/scipy/io/arff/tests

scipy-svn@scip... scipy-svn@scip...
Sun Sep 12 12:21:12 CDT 2010


Author: ptvirtan
Date: 2010-09-12 12:21:12 -0500 (Sun, 12 Sep 2010)
New Revision: 6783

Added:
   trunk/scipy/io/arff/tests/test_arffread.py
Removed:
   trunk/scipy/io/arff/tests/test_data.py
   trunk/scipy/io/arff/tests/test_header.py
Log:
TST: io/arff: reorganize arff tests

Added: trunk/scipy/io/arff/tests/test_arffread.py
===================================================================
--- trunk/scipy/io/arff/tests/test_arffread.py	                        (rev 0)
+++ trunk/scipy/io/arff/tests/test_arffread.py	2010-09-12 17:21:12 UTC (rev 6783)
@@ -0,0 +1,99 @@
+#!/usr/bin/env python
+import os
+from os.path import join as pjoin
+
+import numpy as np
+
+from numpy.testing import TestCase, assert_array_almost_equal, assert_equal
+
+from scipy.io.arff.arffread import loadarff
+from scipy.io.arff.arffread import read_header, parse_type, ParseArffError
+
+data_path = pjoin(os.path.dirname(__file__), 'data')
+
+test1 = os.path.join(data_path, 'test1.arff')
+test2 = os.path.join(data_path, 'test2.arff')
+test3 = os.path.join(data_path, 'test3.arff')
+
+test4 = pjoin(data_path, 'test4.arff')
+test5 = pjoin(data_path, 'test5.arff')
+expect4_data = [(0.1, 0.2, 0.3, 0.4, 'class1'),
+        (-0.1, -0.2, -0.3, -0.4, 'class2'),
+        (1, 2, 3, 4, 'class3')]
+expected_types = ['numeric', 'numeric', 'numeric', 'numeric', 'nominal']
+
+missing = pjoin(data_path, 'missing.arff')
+expect_missing_raw = np.array([[1, 5], [2, 4], [np.nan, np.nan]])
+expect_missing = np.empty(3, [('yop', np.float), ('yap', np.float)])
+expect_missing['yop'] = expect_missing_raw[:, 0]
+expect_missing['yap'] = expect_missing_raw[:, 1]
+
+class DataTest(TestCase):
+    def test1(self):
+        """Parsing trivial file with nothing."""
+        self._test(test4)
+
+    def test2(self):
+        """Parsing trivial file with some comments in the data section."""
+        self._test(test5)
+
+    def _test(self, test_file):
+        data, meta = loadarff(test_file)
+        for i in range(len(data)):
+            for j in range(4):
+                assert_array_almost_equal(expect4_data[i][j], data[i][j])
+        assert_equal(meta.types(), expected_types)
+
+
+class MissingDataTest(TestCase):
+    def test_missing(self):
+        data, meta = loadarff(missing)
+        for i in ['yop', 'yap']:
+            assert_array_almost_equal(data[i], expect_missing[i])
+
+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_badtype_parsing(self):
+        """Test parsing wrong type of attribute from their value."""
+        ofile = open(test3)
+        rel, attrs = read_header(ofile)
+
+        for name, value in attrs:
+            try:
+                parse_type(value)
+                raise Error("Could parse type of crap, should not happen.")
+            except ParseArffError:
+                pass
+
+    def test_fullheader1(self):
+        """Parsing trivial header with nothing."""
+        ofile = open(test1)
+        rel, attrs = read_header(ofile)
+
+        # Test relation
+        assert rel == 'test1'
+
+        # Test numerical attributes
+        assert len(attrs) == 5
+        for i in range(4):
+            assert attrs[i][0] == 'attr%d' % i
+            assert attrs[i][1] == 'REAL'
+        classes = attrs[4][1]
+
+        # Test nominal attribute
+        assert attrs[4][0] == 'class'
+        assert attrs[4][1] == '{class0, class1, class2, class3}'
+
+if __name__ == "__main__":
+    import nose
+    nose.run(argv=['', __file__])

Deleted: trunk/scipy/io/arff/tests/test_data.py
===================================================================
--- trunk/scipy/io/arff/tests/test_data.py	2010-09-12 17:20:54 UTC (rev 6782)
+++ trunk/scipy/io/arff/tests/test_data.py	2010-09-12 17:21:12 UTC (rev 6783)
@@ -1,51 +0,0 @@
-#!/usr/bin/env python
-"""Tests for parsing full arff files."""
-
-import os
-from os.path import join as pjoin
-
-import numpy as np
-
-from numpy.testing import TestCase, assert_array_almost_equal, assert_equal
-
-from scipy.io.arff.arffread import loadarff
-
-
-data_path = pjoin(os.path.dirname(__file__), 'data')
-
-test4 = pjoin(data_path, 'test4.arff')
-test5 = pjoin(data_path, 'test5.arff')
-expect4_data = [(0.1, 0.2, 0.3, 0.4, 'class1'),
-        (-0.1, -0.2, -0.3, -0.4, 'class2'),
-        (1, 2, 3, 4, 'class3')]
-expected_types = ['numeric', 'numeric', 'numeric', 'numeric', 'nominal']
-
-missing = pjoin(data_path, 'missing.arff')
-expect_missing_raw = np.array([[1, 5], [2, 4], [np.nan, np.nan]])
-expect_missing = np.empty(3, [('yop', np.float), ('yap', np.float)])
-expect_missing['yop'] = expect_missing_raw[:, 0]
-expect_missing['yap'] = expect_missing_raw[:, 1]
-
-
-class DataTest(TestCase):
-    def test1(self):
-        """Parsing trivial file with nothing."""
-        self._test(test4)
-
-    def test2(self):
-        """Parsing trivial file with some comments in the data section."""
-        self._test(test5)
-
-    def _test(self, test_file):
-        data, meta = loadarff(test_file)
-        for i in range(len(data)):
-            for j in range(4):
-                assert_array_almost_equal(expect4_data[i][j], data[i][j])
-        assert_equal(meta.types(), expected_types)
-
-
-class MissingDataTest(TestCase):
-    def test_missing(self):
-        data, meta = loadarff(missing)
-        for i in ['yop', 'yap']:
-            assert_array_almost_equal(data[i], expect_missing[i])

Deleted: trunk/scipy/io/arff/tests/test_header.py
===================================================================
--- trunk/scipy/io/arff/tests/test_header.py	2010-09-12 17:20:54 UTC (rev 6782)
+++ trunk/scipy/io/arff/tests/test_header.py	2010-09-12 17:21:12 UTC (rev 6783)
@@ -1,59 +0,0 @@
-#!/usr/bin/env python
-"""Test for parsing arff headers only."""
-import os
-
-from numpy.testing import *
-
-from scipy.io.arff.arffread import read_header, parse_type, ParseArffError
-
-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')
-test3 = os.path.join(data_path, 'test3.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_badtype_parsing(self):
-        """Test parsing wrong type of attribute from their value."""
-        ofile = open(test3)
-        rel, attrs = read_header(ofile)
-
-        for name, value in attrs:
-            try:
-                parse_type(value)
-                raise Error("Could parse type of crap, should not happen.")
-            except ParseArffError:
-                pass
-
-    def test_fullheader1(self):
-        """Parsing trivial header with nothing."""
-        ofile = open(test1)
-        rel, attrs = read_header(ofile)
-
-        # Test relation
-        assert rel == 'test1'
-
-        # Test numerical attributes
-        assert len(attrs) == 5
-        for i in range(4):
-            assert attrs[i][0] == 'attr%d' % i
-            assert attrs[i][1] == 'REAL'
-        classes = attrs[4][1]
-
-        # Test nominal attribute
-        assert attrs[4][0] == 'class'
-        assert attrs[4][1] == '{class0, class1, class2, class3}'
-
-if __name__ == "__main__":
-    nose.run(argv=['', __file__])



More information about the Scipy-svn mailing list