File: test_default_override.py

package info (click to toggle)
python-traitsui 4.4.0-1.3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 3,680 kB
  • ctags: 6,394
  • sloc: python: 32,786; makefile: 16; sh: 5
file content (77 lines) | stat: -rw-r--r-- 2,660 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77

from nose.tools import assert_equals

from traitsui.api import DefaultOverride, EditorFactory
from traits.api import HasTraits, Int


class DummyEditor(EditorFactory):

    x = Int(10)
    y = Int(20)

    def simple_editor(self, ui, object, name, description, parent):
        return ('simple_editor', self, ui, object, name, description, parent)

    def custom_editor(self, ui, object, name, description, parent):
        return ('custom_editor', self, ui, object, name, description, parent)

    def text_editor(self, ui, object, name, description, parent):
        return ('text_editor', self, ui, object, name, description, parent)

    def readonly_editor(self, ui, object, name, description, parent):
        return ('readonly_editor', self, ui, object, name, description, parent)


class NewInt(Int):
    def create_editor(self):
        return DummyEditor()


class Dummy(HasTraits):
    x = NewInt()


dummy_object = Dummy()
do = DefaultOverride(x=15, y=25, format_str='%r')


def test_simple_override():
    editor_name, editor, ui, obj, name, description, parent = do.simple_editor('ui', dummy_object, 'x', 'description', 'parent')
    assert_equals(editor_name, 'simple_editor')
    assert_equals(editor.x, 15)
    assert_equals(editor.y, 25)
    assert_equals(obj, dummy_object)
    assert_equals(name, 'x')
    assert_equals(description, 'description')
    assert_equals(parent, 'parent')

def test_text_override():
    editor_name, editor, ui, obj, name, description, parent = do.text_editor('ui', dummy_object, 'x', 'description', 'parent')
    assert_equals(editor_name, 'text_editor')
    assert_equals(editor.x, 15)
    assert_equals(editor.y, 25)
    assert_equals(obj, dummy_object)
    assert_equals(name, 'x')
    assert_equals(description, 'description')
    assert_equals(parent, 'parent')

def test_custom_override():
    editor_name, editor, ui, obj, name, description, parent = do.custom_editor('ui', dummy_object, 'x', 'description', 'parent')
    assert_equals(editor_name, 'custom_editor')
    assert_equals(editor.x, 15)
    assert_equals(editor.y, 25)
    assert_equals(obj, dummy_object)
    assert_equals(name, 'x')
    assert_equals(description, 'description')
    assert_equals(parent, 'parent')

def test_readonly_override():
    editor_name, editor, ui, obj, name, description, parent = do.readonly_editor('ui', dummy_object, 'x', 'description', 'parent')
    assert_equals(editor_name, 'readonly_editor')
    assert_equals(editor.x, 15)
    assert_equals(editor.y, 25)
    assert_equals(obj, dummy_object)
    assert_equals(name, 'x')
    assert_equals(description, 'description')
    assert_equals(parent, 'parent')