[PATCH 09/13] add couple of tests and support for them
Martin Sivak
msivak at redhat.com
Wed Aug 8 08:52:47 UTC 2012
---
pyanaconda/ui/tui/simpleline/base.py | 7 ++-
pyanaconda/ui/tui/simpleline/base_test.py | 87 +++++++++++++++++++++++++++++
2 files changed, 93 insertions(+), 1 deletion(-)
create mode 100644 pyanaconda/ui/tui/simpleline/base_test.py
diff --git a/pyanaconda/ui/tui/simpleline/base.py b/pyanaconda/ui/tui/simpleline/base.py
index 0c9f750..78c693f 100644
--- a/pyanaconda/ui/tui/simpleline/base.py
+++ b/pyanaconda/ui/tui/simpleline/base.py
@@ -243,7 +243,7 @@ class App(object):
continue
# get the input from user
- c = raw_input(prompt)
+ c = self.raw_input(prompt)
# process the input, if it wasn't processed (valid)
# increment the error counter
@@ -264,6 +264,11 @@ class App(object):
except ExitAllMainLoops:
raise
+ def raw_input(self, prompt):
+ """This method reads one input from user. Its basic form has only one line,
+ but we might need to override it for more complex apps or testing."""
+ return raw_input(prompt)
+
def input(self, key):
"""Method called internally to process unhandled input key presses.
Also handles the main quit and close commands.
diff --git a/pyanaconda/ui/tui/simpleline/base_test.py b/pyanaconda/ui/tui/simpleline/base_test.py
new file mode 100644
index 0000000..91b86e8
--- /dev/null
+++ b/pyanaconda/ui/tui/simpleline/base_test.py
@@ -0,0 +1,87 @@
+# Test routines for the simpleline framework
+#
+# Copyright (C) (2012) Red Hat, Inc.
+#
+# This copyrighted material is made available to anyone wishing to use,
+# modify, copy, or redistribute it subject to the terms and conditions of
+# the GNU General Public License v.2, or (at your option) any later version.
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY expressed or implied, including the implied warranties of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+# Public License for more details. You should have received a copy of the
+# GNU General Public License along with this program; if not, write to the
+# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301, USA. Any Red Hat trademarks that are incorporated in the
+# source code or documentation are not subject to the GNU General Public
+# License and may only be used or replicated with the express permission of
+# Red Hat, Inc.
+#
+# Red Hat Author(s): Martin Sivak <msivak at redhat.com>
+#
+import base
+import unittest
+
+class DummyScreen(base.UIScreen):
+ def refresh(self, args):
+ self._window = []
+ return True
+
+class TestApp(base.App):
+ def __init__(self, *args, **kwargs):
+ self.simulate_input = []
+ base.App.__init__(self, *args, **kwargs)
+
+ def simulate(self, input):
+ self.simulate_input.append(input)
+
+ def raw_input(self, prompt):
+ if not self.simulate_input:
+ raise Exception("No further input, the app probably failed the test")
+ return self.simulate_input.pop(0)
+
+class OKException(Exception):
+ pass
+
+def raiseOK():
+ raise OKException()
+
+class AppTests(unittest.TestCase):
+ def setUp(self):
+ self.app = TestApp("title")
+ self.screen = DummyScreen(self.app)
+
+ def test_schedule_adds_to_beginning_when_empty(self):
+ self.app.schedule_screen(base.UIScreen(self.app))
+ assert len(self.app._screens) == 1
+
+ def test_schedule_adds_to_beginning_when_not_empty(self):
+ self.app.schedule_screen(None)
+ self.app.schedule_screen(base.UIScreen(self.app))
+ assert len(self.app._screens) == 2
+ assert self.app._screens[0][0] is not None
+
+ def test_modal_starts_mainloop(self):
+ self.app.mainloop = raiseOK
+ self.assertRaises(OKException, self.app.switch_screen_modal, (self.screen,))
+
+ def test_exits_modal_screen(self):
+ self.app.simulate("c")
+ self.app.switch_screen_modal(self.screen)
+
+class WidgetTests(unittest.TestCase):
+ def setUp(self):
+ self.widget = base.Widget(default = u"test1\ntesting line\nte")
+
+ def test_height(self):
+ self.assertEquals(self.widget.height, 3)
+
+ def test_width(self):
+ self.assertEquals(self.widget.width, 12)
+
+ def test_clear(self):
+ self.widget.clear()
+ self.assertEquals(self.widget.content, [])
+ self.assertEquals(self.widget.cursor, (0, 0))
+
+if __name__ == '__main__':
+ unittest.main()
--
1.7.10.4
More information about the anaconda-patches
mailing list