Exemplo n.º 1
0
def test_new_and_get_class():
    iclass1 = interface_class('IInt')
    assert interface_class(iclass1) == iclass1
    assert issubclass(iclass1, IInterface)


    iname0 = 'IInt'
    iname1 = interface_name(iname0)
    iname2 = interface_name(iclass1)
    iname3 = interface_name(iclass1())
    iname4 = interface_name(int)
    iname5 = interface_name('int')

    assert iname1 == iname0
    assert iname2 == iname0
    assert iname3 == iname0
    assert iname4 == iname0
    assert iname5 == iname0

    interface1 = new_interface(iname1, min=1, max=1)
    interface2 = new_interface(iclass1, min=1, max=2)
    interface3 = new_interface(interface2, min=1, max=3)
    interface4 = new_interface(iname1, 1, min=1, max=4)
    interface5 = new_interface(value=1, min=1, max=5)

    assert isinstance(interface1, iclass1)
    assert isinstance(interface2, iclass1)
    assert isinstance(interface3, iclass1)
    assert isinstance(interface4, iclass1)
    assert isinstance(interface5, iclass1)

    # Warning, normal behaviour is to keep interface unchanged if interface is yet an instance
    assert(interface3.max == 2)

    assert(interface1.max == 1)
    assert(interface2.max == 2)
    assert(interface4.max == 4)
    assert(interface5.max == 5)
    def test_interface_class(self):
        from openalea.core.interface import IInt, IFloat

        self.assertIs(interface_class('IInt'), IInt)
        self.assertIs(interface_class('int'), IInt)
        self.assertIs(interface_class(int), IInt)

        self.assertIs(interface_class('IFloat'), IFloat)
        self.assertIs(interface_class('float'), IFloat)
        self.assertIs(interface_class(float), IFloat)
Exemplo n.º 3
0
    def test_interface_class(self):
        from openalea.core.interface import IInt, IFloat

        self.assertIs(interface_class('IInt'), IInt)
        self.assertIs(interface_class('int'), IInt)
        self.assertIs(interface_class(int), IInt)

        self.assertIs(interface_class('IFloat'), IFloat)
        self.assertIs(interface_class('float'), IFloat)
        self.assertIs(interface_class(float), IFloat)
Exemplo n.º 4
0
def select_default_widgets():
    from IPython.display import display
    box = widgets.ContainerWidget(description="Select default widgets")
    dic = {}
    children = []
    for iname, widget_dict in preferred_widgets.iteritems():
        iclass = interface_class(iname)
#         for name, notebookclass in widgets.iteritems():
        values = widget_dict
        widget = widgets.SelectWidget(description=iclass.__alias__, values=values)
        children.append(widget)
        dic[iname] = widget
    box.children = children
    box.set_css('border', "1px solid")
    display(box)
    return dic
Exemplo n.º 5
0
def select_default_widgets():
    from IPython.display import display
    box = widgets.ContainerWidget(description="Select default widgets")
    dic = {}
    children = []
    for iname, widget_dict in preferred_widgets.iteritems():
        iclass = interface_class(iname)
        #         for name, notebookclass in widgets.iteritems():
        values = widget_dict
        widget = widgets.SelectWidget(description=iclass.__alias__,
                                      values=values)
        children.append(widget)
        dic[iname] = widget
    box.children = children
    box.set_css('border', "1px solid")
    display(box)
    return dic
Exemplo n.º 6
0
def set_interface(input_obj):
    if input_obj.interface is None:
        if isinstance(input_obj.default, str):
            try:
                default_eval = eval(input_obj.default)
                input_obj.interface = guess_interface(default_eval)
            except SyntaxError:
                input_obj.interface = guess_interface(input_obj.default)
        else:
            input_obj.interface = guess_interface(input_obj.default)
    else:
        try:
            input_obj.interface = interface_class(input_obj.interface)
        except ValueError:
            input_obj.interface = guess_interface(input_obj.default)
    if input_obj.interface == []:
        input_obj.interface = None
    elif isinstance(input_obj.interface, list):
        input_obj.interface = input_obj.interface[0]
Exemplo n.º 7
0
def set_interface(input_obj):
    if input_obj.interface is None:
        if isinstance(input_obj.default, str):
            try:
                default_eval = eval(input_obj.default)
                input_obj.interface = guess_interface(default_eval)
            except SyntaxError:
                input_obj.interface = guess_interface(input_obj.default)
        else:
            input_obj.interface = guess_interface(input_obj.default)
    else:
        try:
            input_obj.interface = interface_class(input_obj.interface)
        except ValueError:
            input_obj.interface = guess_interface(input_obj.default)
    if input_obj.interface == []:
        input_obj.interface = None
    elif isinstance(input_obj.interface, list):
        input_obj.interface = input_obj.interface[0]