Updated TODO.
[straw.git] / test / TestFeedparser.py
blob78c2c4bf200f245937f804f7b8b8a2c226d82a30
1 """ Feedparser threading problem testcase
3 This is a simple (non-scientific :P) testcase that helps reproduce the problem we
4 encountered when developing Straw feed reader.
6 The problem probably isn't specific to feedparser, but rather to SAX parser or
7 sgmllib (with both this problem occurs) that feedparser uses.
9 To run the testcase, enter the main Straw directory and execute the following command:
11 :~ nosetests -s test/TestFeedparser.py
13 Note: if using CountingThread, it's best to redirect test output to a file. Like this:
15 :~ nosetests -s test/TestFeedparser.py > result.txt
17 Description of this testcase:
19 - there are sample feeds in TEST_DATA_PATH directory
20 - testcase passes these feeds to feedparser's parse method
21 - before than testcase launches either GUIThread (Straw's main window from Glade file)
22 or CountingThread (simple thread that counts :-)
24 To observe the problem, do the following:
26 - GUIThread - open File menu and hold arrow down key - selection in the menu should
27 cycle smoothly, but it freezes from time to time - this effect can be also observed
28 in other parts of the GUI
30 - CountingThread - set some interval (default is 0.05), dump the counting results into
31 a file and observe that delays are often more than 0.1 or the other interval that has
32 been set
34 It is possible to control test CPU load by modifying sleep interval in parsing loop.
36 Also try uncommenting the line "while 1: pass". In that case, CPU load is constantly at
37 100%, but the background thread is working smoothly.
39 If you have any ideas on what might be the cause of this problem, please come to #straw
40 at irc.freenode.net and kindly enlighten us ;-)
42 """
44 from gtk import glade
45 from straw import feedparser
46 from threading import Thread
47 import gtk
48 import os
49 import time
51 TEST_DATA_PATH = "test/feeds/"
53 class TestFeedparser(object):
54 def setUp(self):
55 pass
57 def tearDown(self):
58 pass
60 def testPerformance(self):
61 gtk.gdk.threads_init()
62 gtk.gdk.threads_enter()
64 t = CountingThread()
65 #t = GUIThread()
67 t.start()
69 while 1: pass
71 for file in os.listdir(TEST_DATA_PATH):
72 #time.sleep(0.1)
73 fl = open(TEST_DATA_PATH + file, "r")
74 content = fl.read()
75 fl.close()
77 feedparser.parse(content)
79 t.join()
81 gtk.gdk.threads_leave()
83 class GUIThread(Thread):
84 def __init__(self):
85 Thread.__init__(self)
87 def run(self):
88 xml = glade.XML('data/straw.glade', "straw_main")
89 window = xml.get_widget('straw_main')
90 window.show_all()
91 gtk.main()
93 class CountingThread(Thread):
94 def __init__(self):
95 Thread.__init__(self)
97 def run(self):
98 while 1:
99 time.sleep(0.05)
100 print time.time()