[PATCH 10/13] add couple of tests and fix write method of widget (newline added unwanted space)

Martin Sivak msivak at redhat.com
Wed Aug 8 08:52:48 UTC 2012


---
 pyanaconda/ui/tui/simpleline/base.py      |   21 +++++++++----------
 pyanaconda/ui/tui/simpleline/base_test.py |   31 ++++++++++++++++++++++++++++-
 2 files changed, 41 insertions(+), 11 deletions(-)

diff --git a/pyanaconda/ui/tui/simpleline/base.py b/pyanaconda/ui/tui/simpleline/base.py
index 78c693f..1a07211 100644
--- a/pyanaconda/ui/tui/simpleline/base.py
+++ b/pyanaconda/ui/tui/simpleline/base.py
@@ -539,7 +539,7 @@ class Widget(object):
         if col is None:
             col = self._cursor[1]
 
-        if width is None:
+        if width is None and self._max_width:
             width = self._max_width - col
 
         x = row
@@ -547,6 +547,15 @@ class Widget(object):
 
         # emulate typing machine
         for c in text:
+            # process newline
+            if c == "\n":
+                x += 1
+                if block:
+                    y = col
+                else:
+                    y = 0
+                continue
+
             # if the line is not in buffer, create it
             if x >= len(self._buffer):
                 for i in range(x - len(self._buffer) + 1):
@@ -556,21 +565,13 @@ class Widget(object):
             if y >= len(self._buffer[x]):
                 self._buffer[x] += ((y - len(self._buffer[x]) + 1) * list(u" "))
 
-            # process newline
-            if c == "\n":
-                x += 1
-                if block:
-                    y = col
-                else:
-                    y = 0
-                continue
 
             # "type" character
             self._buffer[x][y] = c
 
             # shift to the next char
             y += 1
-            if y >= col + width:
+            if not width is None and y >= col + width:
                 x += 1
                 if block:
                     y = col
diff --git a/pyanaconda/ui/tui/simpleline/base_test.py b/pyanaconda/ui/tui/simpleline/base_test.py
index 91b86e8..a84f2b7 100644
--- a/pyanaconda/ui/tui/simpleline/base_test.py
+++ b/pyanaconda/ui/tui/simpleline/base_test.py
@@ -69,8 +69,12 @@ class AppTests(unittest.TestCase):
         self.app.switch_screen_modal(self.screen)
 
 class WidgetTests(unittest.TestCase):
+    TEXT = u"test1\ntesting line\nte"
+    BLOCK = u"xxy\nxxx\nxxx"
+    BLOCK_TEXT = u"test1xxy\ntestixxxline\nte   xxx"
+
     def setUp(self):
-        self.widget = base.Widget(default = u"test1\ntesting line\nte")
+        self.widget = base.Widget(default = self.TEXT)
 
     def test_height(self):
         self.assertEquals(self.widget.height, 3)
@@ -83,5 +87,30 @@ class WidgetTests(unittest.TestCase):
         self.assertEquals(self.widget.content, [])
         self.assertEquals(self.widget.cursor, (0, 0))
 
+    def test_rendering(self):
+        self.assertEqual(unicode(self.widget), self.TEXT)
+
+    def test_draw(self):
+        target = base.Widget()
+        target.draw(self.widget)
+        self.assertEqual(unicode(target), self.TEXT)
+
+    def test_write(self):
+        self.widget.clear()
+        self.widget.write(self.TEXT)
+        self.assertEqual(unicode(self.widget), self.TEXT)
+
+    def test_block_write(self):
+        self.widget.setxy(0, 5)
+        self.widget.write(self.BLOCK, block = True)
+        self.assertEqual(unicode(self.widget), self.BLOCK_TEXT)
+
+    def test_block_draw(self):
+        source = base.Widget()
+        source.write(self.BLOCK)
+        self.widget.draw(source, row = 0, col = 5)
+        self.assertEqual(unicode(self.widget), self.BLOCK_TEXT)
+
+
 if __name__ == '__main__':
     unittest.main()
-- 
1.7.10.4



More information about the anaconda-patches mailing list