source: orange/Orange/testing/unit/tests/test_table.py @ 9679:3879dea56188

Revision 9679:3879dea56188, 2.6 KB checked in by Miha Stajdohar <miha.stajdohar@…>, 2 years ago (diff)

Moved and renamed testing.

Line 
1""" Orange.data.Table related unit-tests
2"""
3import unittest
4from Orange.misc import testing
5import Orange
6import cPickle
7
8def native(table):
9    table = table.native()
10    for i in range(len(table)):
11        table[i] = [v.native() for v in table[i].native()]
12    return table
13       
14def names_iter():
15    for name in testing.ALL_DATASETS:
16        yield name.replace(" ", "_").replace("-", "_"), (name,)
17       
18@testing.data_driven(data_iter=names_iter())
19class TestLoading(unittest.TestCase):
20   
21    @testing.test_on_data
22    def test_load_on(self, name):
23        """ Test the loading of the data set
24        """
25        table = Orange.data.Table(name)
26        self.assertIsNotNone(getattr(table, "attributeLoadStatus"), "No attributeLoadStatus")
27       
28    @testing.test_on_data
29    def test_pickling_on(self, name):
30        """ Test data table pickling.
31        """
32        table = Orange.data.Table(name)
33        s = cPickle.dumps(table)
34        table_clone = cPickle.loads(s)
35#        self.assertEqual(table.domain, table_clone.domain)
36#        self.assertEqual(table.domain.class_var, table_clone.domain.class_var)
37        self.assertEqual(native(table), native(table_clone), "Native representation is not equal!")
38       
39       
40import tempfile
41
42@testing.datasets_driven
43class TestSaving(unittest.TestCase):
44    @testing.test_on_data
45    def test_R_on(self, name):
46        data = Orange.data.Table(name)
47        with tempfile.NamedTemporaryFile(suffix=".R") as f:
48            data.save(f.name)
49   
50#    @testing.test_on_data
51#    def test_toC50(self, name):
52#        data = Orange.data.Table(name)
53
54    @testing.test_on_datasets(datasets=testing.CLASSIFICATION_DATASETS +\
55                              testing.REGRESSION_DATASETS)
56    def test_arff_on(self, data):
57        with tempfile.NamedTemporaryFile(suffix=".arff") as f:
58            data.save(f.name)
59            f.flush()
60            data_arff = Orange.data.Table(f.name)
61    @testing.test_on_datasets(datasets=testing.CLASSIFICATION_DATASETS +\
62                              testing.REGRESSION_DATASETS)
63    def test_svm_on(self, data):
64        with tempfile.NamedTemporaryFile(suffix=".svm") as f:
65            data.save(f.name)
66            f.flush()
67            data_svm = Orange.data.Table(f.name)
68       
69    @testing.test_on_datasets
70    def test_csv_on(self, data):
71        with tempfile.NamedTemporaryFile(suffix=".csv") as f:
72            Orange.data.io.save_csv(f, data, dialect="excel-tab")
73            f.flush()
74            f.seek(0)
75            Orange.data.io.load_csv(f)
76           
77       
78           
79       
80if __name__ == "__main__":
81    unittest.main()
82   
Note: See TracBrowser for help on using the repository browser.