desktop

tests/test_dialog.py

69:1bd81cc4989e
2009-06-21 Paul Boddie Added tag rel-0-4 for changeset dc20c296a651
     1 #!/usr/bin/env python     2      3 import desktop.dialog     4      5 def test_open(obj, desktop=None):     6     try:     7         return obj.open(desktop)     8     except OSError:     9         return None    10     11 def test_question():    12     obj = desktop.dialog.Question("Are you sure?", 40, 5)    13     print test_open(obj)    14     print test_open(obj, "KDE")    15     print test_open(obj, "GNOME")    16     print test_open(obj, "X11")    17     18 def test_message():    19     obj = desktop.dialog.Message("Hello world!", 40, 5)    20     print test_open(obj)    21     print test_open(obj, "KDE")    22     print test_open(obj, "GNOME")    23     print test_open(obj, "X11")    24     25 def test_warning():    26     obj = desktop.dialog.Warning("Beware of the penguin!", 40, 5)    27     print test_open(obj)    28     print test_open(obj, "KDE")    29     print test_open(obj, "GNOME")    30     print test_open(obj, "X11")    31     32 def test_error():    33     obj = desktop.dialog.Error("Penguin invasion complete!", 40, 5)    34     print test_open(obj)    35     print test_open(obj, "KDE")    36     print test_open(obj, "GNOME")    37     print test_open(obj, "X11")    38     39 def test_menu():    40     obj = desktop.dialog.Menu("Choose an animal", ["Animal"], width=40, height=15, list_height=5)    41     obj.add("a", "Antelope")    42     obj.add("b", "Badger")    43     obj.add("c", "Cow")    44     obj.add("d", "Dog")    45     obj.add("e", "Elephant")    46     obj.add("f", "Fox")    47     obj.add("g", "Giraffe")    48     obj.add("h", "Horse")    49     obj.add("i", "Iguana")    50     print repr(test_open(obj))    51     print repr(test_open(obj, "KDE"))    52     print repr(test_open(obj, "GNOME"))    53     print repr(test_open(obj, "X11"))    54     55 def test_checklist():    56     obj = desktop.dialog.CheckList("Choose some animals", ["Animal"], width=40, height=15, list_height=5)    57     obj.add("a", "Antelope")    58     obj.add("b", "Badger", 1)    59     obj.add("c", "Cow", 0)    60     obj.add("d", "Dog")    61     obj.add("e", "Elephant")    62     obj.add("f", "Fox", 1)    63     obj.add("g", "Giraffe")    64     obj.add("h", "Horse")    65     obj.add("i", "Iguana")    66     print repr(test_open(obj))    67     print repr(test_open(obj, "KDE"))    68     print repr(test_open(obj, "GNOME"))    69     print repr(test_open(obj, "X11"))    70     71 def test_radiolist():    72     obj = desktop.dialog.RadioList("Choose one animal", ["Animal"], width=40, height=15, list_height=5)    73     obj.add("a", "Antelope")    74     obj.add("b", "Badger", 1)    75     obj.add("c", "Cow", 0)    76     obj.add("d", "Dog")    77     obj.add("e", "Elephant")    78     obj.add("f", "Fox", 1)    79     obj.add("g", "Giraffe")    80     obj.add("h", "Horse")    81     obj.add("i", "Iguana")    82     print repr(test_open(obj))    83     print repr(test_open(obj, "KDE"))    84     print repr(test_open(obj, "GNOME"))    85     print repr(test_open(obj, "X11"))    86     87 def test_pulldown():    88     obj = desktop.dialog.Pulldown("Choose an animal", ["Animal"], width=40, height=15, list_height=5)    89     obj.add("Antelope")    90     obj.add("Badger")    91     obj.add("Cow")    92     obj.add("Dog")    93     obj.add("Elephant")    94     obj.add("Fox")    95     obj.add("Giraffe")    96     obj.add("Horse")    97     obj.add("Iguana")    98     print repr(test_open(obj))    99     print repr(test_open(obj, "KDE"))   100     print repr(test_open(obj, "GNOME"))   101     print repr(test_open(obj, "X11"))   102    103 def test_input():   104     obj = desktop.dialog.Input("Enter your name!", "Monty", 40, 5)   105     print repr(test_open(obj))   106     print repr(test_open(obj, "KDE"))   107     print repr(test_open(obj, "GNOME"))   108     print repr(test_open(obj, "X11"))   109    110 def test_password():   111     obj = desktop.dialog.Password("Enter your password!", "Python", 40, 5)   112     print repr(test_open(obj))   113     print repr(test_open(obj, "KDE"))   114     print repr(test_open(obj, "GNOME"))   115     print repr(test_open(obj, "X11"))   116    117 def test_textfile():   118     obj = desktop.dialog.TextFile("README.txt", "Showing file...", 80, 25)   119     print repr(test_open(obj))   120     print repr(test_open(obj, "KDE"))   121     print repr(test_open(obj, "GNOME"))   122     print repr(test_open(obj, "X11"))   123    124 test_question()   125 test_message()   126 test_warning()   127 test_error()   128 test_menu()   129 test_checklist()   130 test_radiolist()   131 test_pulldown()   132 test_input()   133 test_password()   134 test_textfile()   135    136 # vim: tabstop=4 expandtab shiftwidth=4