1
# -*- coding: utf-8 -*-
3
# Copyright (c) 2013, Alex Băluț <alexandru.balut@gmail.com>
5
# This program is free software; you can redistribute it and/or
6
# modify it under the terms of the GNU Lesser General Public
7
# License as published by the Free Software Foundation; either
8
# version 2.1 of the License, or (at your option) any later version.
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
# Lesser General Public License for more details.
15
# You should have received a copy of the GNU Lesser General Public
16
# License along with this program; if not, write to the
17
# Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18
# Boston, MA 02110-1301, USA.
20
from unittest import TestCase
22
from pitivi.utils.widgets import PathWidget, TextWidget, NumericWidget, ToggleWidget, ChoiceWidget, ColorWidget, FontWidget
25
class TestWidgets(TestCase):
27
def testConstruction(self):
29
(PathWidget, "file:///home/", ()),
30
(TextWidget, "banana", ()),
31
(NumericWidget, 42, (100, 1)),
32
(ToggleWidget, True, ()),
33
(ChoiceWidget, "banana", ((
37
(ColorWidget, 0x336699FF, (int,)),
38
(FontWidget, "Sans 9", ()))
40
for widget_class, default, args in widgets:
41
widget = widget_class(*args, default=default)
42
self.assertEqual(default, widget.getWidgetDefault())
43
widget.setWidgetToDefault()
44
self.assertEqual(default, widget.getWidgetValue())
45
widget.setWidgetValue(default)
46
self.assertEqual(default, widget.getWidgetValue())
48
def testValidation(self):
49
widget = TextWidget("^([a-zA-Z]+\s*)+$")
51
self.assertNotEqual(bad_value, widget.getWidgetValue())
53
widget = TextWidget("^\d+$", ("12", "14"))
54
bad_value = "non-digits"
55
self.assertNotEqual(bad_value, widget.getWidgetValue())