Gui init test.
authorJack Miller <jack@codezen.org>
Thu, 24 Jun 2010 18:12:28 +0000 (13:12 -0500)
committerJack Miller <jack@codezen.org>
Thu, 24 Jun 2010 18:12:28 +0000 (13:12 -0500)
Signed-off-by: Jack Miller <jack@codezen.org>
canto_curses/gui.py
canto_curses/main.py
test.py
tests/gui.py

index fd43b45..0ac54bf 100755 (executable)
@@ -199,7 +199,7 @@ class Screen():
         curses.doupdate()
 
 class CantoCursesGui():
-    def init(self, backend):
+    def init(self, backend, do_curses=True):
         self.backend = backend
 
         self.backend.write("LISTFEEDS", u"")
@@ -241,9 +241,11 @@ class CantoCursesGui():
                     story.content[k] =\
                         self.backend.responses[0][1][story.id][k]
 
-        log.debug("Starting curses.")
-        self.screen = Screen()
-        self.screen.init()
+        # Short circuit for testing the above setup.
+        if do_curses:
+            log.debug("Starting curses.")
+            self.screen = Screen()
+            self.screen.init()
 
     def next_response(self):
         if self.backend.responses:
index 9b54d62..f12adc5 100755 (executable)
@@ -39,7 +39,7 @@ class CantoCurses(CantoClient):
     def __init__(self):
         pass
 
-    def init(self, args=None):
+    def init(self, args=None, do_log=True):
 
         # For good curses behavior.
         locale.setlocale(locale.LC_ALL, '')
@@ -61,7 +61,8 @@ class CantoCurses(CantoClient):
         if self.ensure_files():
             sys.exit(-1)
 
-        self.set_log()
+        if do_log:
+            self.set_log()
 
         self.response_lock = Lock()
 
@@ -82,7 +83,7 @@ class CantoCurses(CantoClient):
 
         log.debug("Response thread exiting.")
 
-    def run(self):
+    def start_thread(self):
         self.response_alive = True
         self.responses = []
 
@@ -91,6 +92,9 @@ class CantoCurses(CantoClient):
         thread = Thread(target=self.response_thread)
         thread.start()
 
+    def run(self):
+        self.start_thread()
+
         self.gui = CantoCursesGui()
         self.gui.init(self)
 
diff --git a/test.py b/test.py
index 624f9cb..888c4cf 100755 (executable)
--- a/test.py
+++ b/test.py
@@ -33,7 +33,8 @@ all_tests = {
         "test_ensure_files" : tests.main.Tests,
         "test_next_response_goodlock" : tests.gui.Tests,
         "test_next_response_badlock" : tests.gui.Tests,
-        "test_wait_response" : tests.gui.Tests
+        "test_wait_response" : tests.gui.Tests,
+        "test_init_gui" : tests.gui.Tests
 }
 
 if __name__ == "__main__":
index 58510e7..efdbc04 100644 (file)
@@ -7,7 +7,7 @@
 #   published by the Free Software Foundation.
 
 from canto_curses.main import CantoCurses
-from canto_curses.gui import CantoCursesGui
+from canto_curses.gui import CantoCursesGui, alltags
 
 from threading import Thread, Lock
 import unittest
@@ -106,3 +106,39 @@ class Tests(unittest.TestCase):
         self.assertTrue(g.backend.responses == [("RESP2", "b"),
                                                 ("RESP3", "c")])
 
+    def test_init_gui(self):
+        c = CantoCurses()
+
+        # Set args, don't handle log.
+        c.init(["-D", os.getenv("PWD") + "/tests/basic_dir"], False)
+
+        # Start real response thread.
+        c.start_thread()
+
+        g = CantoCursesGui()
+
+        # Init, but don't start curses.
+        g.init(c, False)
+
+        # Simple helper to get specific tag from list
+        def get_tag(tag):
+            for t in alltags:
+                if t.tag == tag:
+                    return list(t)
+            return None
+
+        self.assertTrue(len(alltags) == 2)
+        self.assertTrue(len(g.tracked_feeds) == 2)
+        self.assertTrue(get_tag("Test 1"))
+        self.assertTrue(get_tag("Test 2"))
+        self.assertTrue(len(get_tag("Test 1")) == 1)
+        self.assertTrue(len(get_tag("Test 2")) == 1)
+        self.assertTrue(get_tag("Test 1")[0].content["title"] == "Item 1")
+        self.assertTrue(get_tag("Test 1")[0].content["link"] ==
+                "http://example.com/item/1")
+        self.assertTrue(get_tag("Test 2")[0].content["title"] == "Item 1")
+        self.assertTrue(get_tag("Test 2")[0].content["link"] ==
+                "http://example.com/item/1")
+
+        # Kill daemon.
+        g.backend.write("DIE", "")