[pitivi] widgets: Move the tests to a test file
- From: Mathieu Duponchelle <mathieudu src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pitivi] widgets: Move the tests to a test file
- Date: Tue, 4 Feb 2014 21:55:04 +0000 (UTC)
commit 96f80ed7a4df576d77f932c41cbf9566c0f80c96
Author: Alexandru Băluț <alexandru balut gmail com>
Date: Sun Jan 12 20:04:01 2014 +0100
widgets: Move the tests to a test file
pitivi/render.py | 3 +-
pitivi/utils/widgets.py | 58 +----------------------------------------------
tests/Makefile.am | 3 +-
tests/test_widgets.py | 55 ++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 59 insertions(+), 60 deletions(-)
---
diff --git a/pitivi/render.py b/pitivi/render.py
index 550a64c..af711be 100644
--- a/pitivi/render.py
+++ b/pitivi/render.py
@@ -828,8 +828,7 @@ class RenderDialog(Loggable):
self._destroyProgressWindow()
def _shutDown(self):
- """ The render process has been aborted, shutdown the gstreamer pipeline
- and disconnect from its signals """
+ """Shutdown the gstreamer pipeline and disconnect from its signals."""
self.project.set_rendering(False)
self._is_rendering = False
self._rendering_is_paused = False
diff --git a/pitivi/utils/widgets.py b/pitivi/utils/widgets.py
index e399605..a38d887 100644
--- a/pitivi/utils/widgets.py
+++ b/pitivi/utils/widgets.py
@@ -70,9 +70,6 @@ class DynamicWidget(object):
def getWidgetDefault(self):
return self.default
- def setWidgetDefault(self, value):
- self.default = value
-
def setWidgetToDefault(self):
if self.default is not None:
self.setWidgetValue(self.default)
@@ -498,8 +495,7 @@ class PathWidget(Gtk.FileChooserButton, DynamicWidget):
def __init__(self, action=Gtk.FileChooserAction.OPEN, default=None):
DynamicWidget.__init__(self, default)
self.dialog = Gtk.FileChooserDialog(action=action)
- self.dialong.add_buttons(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_CLOSE,
- Gtk.ResponseType.CLOSE)
+ self.dialog.add_buttons(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_CLOSE,
Gtk.ResponseType.CLOSE)
self.dialog.set_default_response(Gtk.ResponseType.OK)
Gtk.FileChooserButton.__init__(self, self.dialog)
self.dialog.connect("response", self._responseCb)
@@ -579,58 +575,6 @@ class FontWidget(Gtk.FontButton, DynamicWidget):
return self.get_font_name()
-if __name__ == '__main__':
-
- def valueChanged(unused_widget, widget, target):
- target.set_text(str(widget.getWidgetValue()))
-
- widgets = (
- (PathWidget, "file:///home/", ()),
- (TextWidget, "banana", ()),
- (TextWidget, "words only", ("^([a-zA-Z]+\s*)+$",)),
- (TextWidget, "numbers only", ("^\d+$",
- ("12", "14"))),
- (NumericWidget, 42, (100, 1)),
- (ToggleWidget, True, ()),
- (ChoiceWidget, "banana", ((
- ("banana", "banana"),
- ("apple", "apple"),
- ("pear", "pear")),)),
- (ColorWidget, 0x336699FF, (int,)),
- (FontWidget, "Sans 9", ()),
- (FractionWidget, "30M", (
- Gst.FractionRange(Gst.Fraction(1, 1),
- Gst.Fraction(30000, 1001)),
- )),
- (FractionWidget, Gst.Fraction(25000, 1001), (
- Gst.FractionRange(
- Gst.Fraction(1, 1),
- Gst.Fraction(30000, 1001)
- ),
- ("25:1", Gst.Fraction(30, 1), "30M", ),
- )),
- )
-
- W = Gtk.Window()
- v = Gtk.VBox()
- t = Gtk.Table()
-
- for y, (klass, default, args) in enumerate(widgets):
- w = klass(*args)
- w.setWidgetValue(default)
- l = Gtk.Label(label=str(w.getWidgetValue()))
- w.connectValueChanged(valueChanged, w, l)
- w.show()
- l.show()
- t.attach(w, 0, 1, y, y + 1)
- t.attach(l, 1, 2, y, y + 1)
- t.show()
-
- W.add(t)
- W.show()
- Gtk.main()
-
-
class GstElementSettingsWidget(Gtk.VBox, Loggable):
"""
Widget to view/modify properties of a Gst.Element
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 3ec9c72..1a313dd 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -16,7 +16,8 @@ tests = test_basic.py \
test_system.py \
test_timeline_undo.py \
test_undo.py \
- test_utils.py
+ test_utils.py \
+ test_widgets.py
# Keep the list sorted!
EXTRA_DIST = \
diff --git a/tests/test_widgets.py b/tests/test_widgets.py
new file mode 100644
index 0000000..cd3c062
--- /dev/null
+++ b/tests/test_widgets.py
@@ -0,0 +1,55 @@
+# -*- coding: utf-8 -*-
+#
+# Copyright (c) 2013, Alexandru Băluț <alexandru balut gmail com>
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this program; if not, write to the
+# Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+# Boston, MA 02110-1301, USA.
+
+from unittest import TestCase
+
+from pitivi.utils.widgets import PathWidget, TextWidget, NumericWidget, ToggleWidget, ChoiceWidget,
ColorWidget, FontWidget
+
+
+class TestWidgets(TestCase):
+
+ def testConstruction(self):
+ widgets = (
+ (PathWidget, "file:///home/", ()),
+ (TextWidget, "banana", ()),
+ (NumericWidget, 42, (100, 1)),
+ (ToggleWidget, True, ()),
+ (ChoiceWidget, "banana", ((
+ ("banana", "banana"),
+ ("apple", "apple"),
+ ("pear", "pear")),)),
+ (ColorWidget, 0x336699FF, (int,)),
+ (FontWidget, "Sans 9", ()))
+
+ for widget_class, default, args in widgets:
+ widget = widget_class(*args, default=default)
+ self.assertEqual(default, widget.getWidgetDefault())
+ widget.setWidgetToDefault()
+ self.assertEqual(default, widget.getWidgetValue())
+ widget.setWidgetValue(default)
+ self.assertEqual(default, widget.getWidgetValue())
+
+ def testValidation(self):
+ widget = TextWidget("^([a-zA-Z]+\s*)+$")
+ bad_value = "1"
+ self.assertNotEqual(bad_value, widget.getWidgetValue())
+
+ widget = TextWidget("^\d+$", ("12", "14"))
+ bad_value = "non-digits"
+ self.assertNotEqual(bad_value, widget.getWidgetValue())
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]