source: orange/Orange/testing/unit/tests/test_demo.py @ 10278:f3b1ffae9c29

Revision 10278:f3b1ffae9c29, 1.8 KB checked in by Miha Stajdohar <miha.stajdohar@…>, 2 years ago (diff)

Unittest2 for python 2.6.

Line 
1from Orange.misc import testing
2from Orange.misc.testing import data_driven, datasets_driven, test_on_data
3try:
4    import unittest2 as unittest
5except:
6    import unittest
7
8data = [("one", (1,)),
9        ("two", (2,))]
10
11# Data driven with data_iter arg
12@data_driven(data_iter=data)
13class TestDemo(unittest.TestCase):
14    @testing.test_on_data
15    def test_instance_on(self, arg):
16        print arg
17        self.assertIsInstance(arg, int)
18
19    @testing.test_on_data
20    def test_add(self, arg):
21        print arg
22        res = arg + arg
23
24# data_driven without arg
25@data_driven
26class TestDemo1(unittest.TestCase):
27    @test_on_data(data_iter=data)
28    def test_instance_on(self, arg):
29        self.assertIsInstance(arg, int)
30
31    @test_on_data(data_iter=data)
32    def test_add(self, arg):
33        res = arg + arg
34
35# data_driven without arg, using a static data_iter method
36@data_driven
37class TestDemo2(unittest.TestCase):
38    @test_on_data
39    def test_instance_on(self, arg):
40        self.assertIsInstance(arg, int)
41
42    @test_on_data
43    def test_add(self, arg):
44        res = arg + arg
45
46    @staticmethod
47    def data_iter():
48        return data
49
50@datasets_driven(datasets=testing.CLASSIFICATION_DATASETS + \
51                 testing.CLASSLES_DATASETS)
52class TestDefaultLearner(unittest.TestCase):
53    @test_on_data(data_iter=testing.datasets_iter(testing.CLASSIFICATION_DATASETS))
54    def test_learner_on(self, dataset):
55        import Orange
56        Orange.classification.majority.MajorityLearner(dataset)
57
58    # this overloads the class decorator's data_iter
59    @test_on_data(data_iter=testing.datasets_iter(testing.CLASSLES_DATASETS))
60    def test_raise_missing_class_on(self, dataset):
61        import Orange
62        self.assertRaises(Exception, Orange.classification.majority.MajorityLearner, dataset)
63
64if __name__ == "__main__":
65    unittest.main()
66
67
Note: See TracBrowser for help on using the repository browser.