source: orange/Orange/OrangeCanvas/scheme/tests/test_scheme.py @ 11101:e5aa7c1c5b23

Revision 11101:e5aa7c1c5b23, 2.9 KB checked in by Ales Erjavec <ales.erjavec@…>, 19 months ago (diff)

Added scheme package, containing the scheme graph workflow data structure/model.

Line 
1"""
2Tests for Scheme
3"""
4
5from ...gui import test
6from ...registry.tests import small_testing_registry
7
8from .. import Scheme, SchemeNode, SchemeLink, \
9               SchemeTextAnnotation, SchemeArrowAnnotation, \
10               SchemeTopologyError, IncompatibleChannelTypeError
11
12
13class TestScheme(test.QAppTestCase):
14    def test_scheme(self):
15        import Orange
16        reg = small_testing_registry()
17        base = "Orange.OrangeWidgets"
18        file_desc = reg.widget(base + ".Data.OWFile.OWFile")
19        discretize_desc = reg.widget(base + ".Data.OWDiscretize.OWDiscretize")
20        bayes_desc = reg.widget(base + ".Classify.OWNaiveBayes.OWNaiveBayes")
21        # Create the scheme
22        scheme = Scheme()
23
24        self.assertEqual(scheme.title, "untitled")
25        self.assertEqual(scheme.description, "")
26        self.assertEqual(scheme.path, "")
27
28        nodes_added = []
29        links_added = []
30
31        scheme.node_added.connect(nodes_added.append)
32        scheme.link_added.connect(links_added.append)
33        scheme.link_removed.connect(links_added.remove)
34
35        w1 = scheme.new_node(file_desc)
36        self.assertTrue(len(nodes_added) == 1)
37        self.assertTrue(isinstance(nodes_added[-1], SchemeNode))
38        self.assertTrue(nodes_added[-1] is w1)
39
40        w2 = scheme.new_node(discretize_desc)
41        self.assertTrue(len(nodes_added) == 2)
42        self.assertTrue(isinstance(nodes_added[-1], SchemeNode))
43        self.assertTrue(nodes_added[-1] is w2)
44
45        w3 = scheme.new_node(bayes_desc)
46        self.assertTrue(len(nodes_added) == 3)
47        self.assertTrue(isinstance(nodes_added[-1], SchemeNode))
48        self.assertTrue(nodes_added[-1] is w3)
49
50        self.assertTrue(len(links_added) == 0)
51        l1 = SchemeLink(w1, "Data", w2, "Data")
52        scheme.add_link(l1)
53        self.assertTrue(len(links_added) == 1)
54        self.assertTrue(isinstance(links_added[-1], SchemeLink))
55        self.assertTrue(links_added[-1] is l1)
56
57        l2 = SchemeLink(w1, "Data", w3, "Data")
58        scheme.add_link(l2)
59        self.assertTrue(len(links_added) == 2)
60        self.assertTrue(isinstance(links_added[-1], SchemeLink))
61        self.assertTrue(links_added[-1] is l2)
62
63        # Test find_links.
64        found = scheme.find_links(w1, None, w2, None)
65        self.assertSequenceEqual(found, [l1])
66        found = scheme.find_links(None, None, w3, None)
67        self.assertSequenceEqual(found, [l2])
68
69        scheme.remove_link(l2)
70        self.assertTrue(l2 not in links_added)
71
72        # Add a link to itself.
73        self.assertRaises(SchemeTopologyError, scheme.new_link,
74                          w2, "Data", w2, "Data")
75
76        # Add an link with incompatible types
77        self.assertRaises(IncompatibleChannelTypeError,
78                          scheme.new_link, w3, "Learner", w2, "Data")
79
80        # Add a link to a node with no input channels
81        self.assertRaises(ValueError, scheme.new_link,
82                          w2, "Data", w1, "Data")
Note: See TracBrowser for help on using the repository browser.