source: orange/Orange/OrangeCanvas/registry/tests/test_discovery.py @ 11098:b743937fe90a

Revision 11098:b743937fe90a, 2.3 KB checked in by Ales Erjavec <ales.erjavec@…>, 19 months ago (diff)

Added new widget/category description classes and new widget discovery.

This includes a Qt item model interface for the registry.

Line 
1"""
2Test widget discovery
3
4"""
5
6import os
7import logging
8
9import unittest
10
11from ..discovery import WidgetDiscovery, widget_descriptions_from_package
12
13from ..description import CategoryDescription, WidgetDescription
14
15
16class TestDiscovery(unittest.TestCase):
17
18    def setUp(self):
19        logging.basicConfig()
20
21    def discovery_class(self):
22        return WidgetDiscovery()
23
24    def test_handle(self):
25        disc = self.discovery_class()
26
27        desc = CategoryDescription(name="C", qualified_name="M.C")
28        disc.handle_category(desc)
29
30        desc = WidgetDescription(name="SomeWidget", category="C",
31                                 qualified_name="Some.Widget")
32        disc.handle_widget(desc)
33
34    def test_file(self):
35        from Orange.OrangeWidgets.Data import OWFile
36        disc = self.discovery_class()
37        disc.process_file(OWFile.__file__)
38
39    def test_process_directory(self):
40        from Orange.OrangeWidgets import Data, Visualize
41        data_dirname = os.path.dirname(Data.__file__)
42        visualize_dirname = os.path.dirname(Visualize.__file__)
43
44        disc = self.discovery_class()
45        disc.process_directory(data_dirname)
46        disc.process_directory(visualize_dirname)
47
48    def test_process_module(self):
49        disc = self.discovery_class()
50        disc.process_category_package(
51            "Orange.OrangeWidgets.Data"
52        )
53        disc.process_widget_module(
54            "Orange.OrangeWidgets.Classify.OWNaiveBayes"
55        )
56
57    def test_process_loader(self):
58        disc = self.discovery_class()
59
60        def callable(discovery):
61            desc = CategoryDescription(
62                name="Data", qualified_name="Data")
63
64            discovery.handle_category(desc)
65
66            desc = WidgetDescription.from_module(
67                "Orange.OrangeWidgets.Data.OWFile"
68            )
69            discovery.handle_widget(desc)
70
71        disc.process_loader(callable)
72
73    def test_process_iter(self):
74        disc = self.discovery_class()
75        cat_desc = CategoryDescription.from_package(
76            "Orange.OrangeWidgets.Data"
77        )
78        wid_desc = widget_descriptions_from_package(
79            "Orange.OrangeWidgets.Data"
80        )
81        disc.process_iter([cat_desc] + wid_desc)
82
83    def test_run(self):
84        disc = self.discovery_class()
85        disc.run()
Note: See TracBrowser for help on using the repository browser.