source: orange/Orange/testing/unit/tests/test_name.py @ 11065:d374411d8f22

Revision 11065:d374411d8f22, 1.9 KB checked in by Janez Demšar <janez.demsar@…>, 16 months ago (diff)

Added property 'name' that resolves to an attribute name, if it exists,
otherwise it returns the class name with the first letter in lowercase and
without the suffix 'Learner', 'Classifier' or 'Discretization'.

Line 
1import orange
2import Orange
3import unittest
4
5class TestName(unittest.TestCase):
6    def test_Learner(self):
7        b = orange.BayesLearner()
8        self.assertEqual(b.name, "bayes")
9        b.name = "foo"
10        self.assertEqual(b.name, "foo")
11        b.name = "BayesLearner"
12        self.assertEqual(b.name, "BayesLearner")
13        b.name = "x.BayesLearner"
14        self.assertEqual(b.name, "x.BayesLearner")
15        b.name = ""
16        self.assertEqual(b.name, "")
17
18    def test_class(self):
19        class MyBla(orange.BayesLearner):
20            pass
21        b = MyBla()
22        self.assertEqual(b.name, "myBla")
23        b.name = "foo"
24        self.assertEqual(b.name, "foo")
25
26    def test_classLearner(self):
27        class MyBlaLearner(orange.BayesLearner):
28            pass
29        b = MyBlaLearner()
30        self.assertEqual(b.name, "myBla")
31
32    def test_class_short(self):
33        class A(orange.BayesLearner):
34            pass
35        b = A()
36        self.assertEqual(b.name, "a")
37        b.name = "foo"
38        self.assertEqual(b.name, "foo")
39
40    def test_Discretizer(self):
41        b = orange.EquiDistDiscretizer()
42        # The class is renamed internally
43        # "Discretizer" is removed and E is changed to e
44        self.assertEqual(b.name, "equalWidth")
45
46    def test_Classifier(self):
47        b = orange.TreeClassifier()
48        self.assertEqual(b.name, "tree")
49
50    def test_Orange(self):
51        b = Orange.classification.bayes.NaiveLearner()
52        self.assertEqual(b.name, "naive")
53
54    def test_static_name(self):
55        # Tests that class attributes work and are left
56        # (stripping off 'Learner' and lower cases are
57        # applied only to class names
58        class NaiveLearner(orange.BayesLearner):
59            name = "BayesLearner"
60        b = NaiveLearner()
61        self.assertEqual(b.name, "BayesLearner")
62
63
64if __name__ == "__main__":
65    unittest.main()
Note: See TracBrowser for help on using the repository browser.