Commits

Laurent Bachelier  committed 3196067

Towards better tests

  • Participants
  • Parent commits c28d7f7

Comments (0)

Files changed (2)

 
 import rtorrentnotify as rtn
 
-if len(sys.argv) < 3:
-    print "Usage: %s TYPE NAME" % sys.argv[0]
-    exit(1)
+if __name__ == '__main__':
+    if len(sys.argv) < 3:
+        print "Usage: %s TYPE NAME" % sys.argv[0]
+        exit(1)
 
-os.chdir(os.path.dirname(__file__))
+    os.chdir(os.path.dirname(__file__))
 
-eventname = unicode(sys.argv[1], locale.getpreferredencoding())
-name = unicode(" ".join(sys.argv[2:]), locale.getpreferredencoding())
+    eventname = unicode(sys.argv[1], locale.getpreferredencoding())
+    name = unicode(" ".join(sys.argv[2:]), locale.getpreferredencoding())
 
-event = rtn.Event(eventname, name)
+    event = rtn.Event(eventname, name)
 
-events = rtn.Events()
-events.load()
-events.append(event)
-events.save()
+    events = rtn.Events()
+    events.load()
+    events.append(event)
+    events.save()
 
-feed = events.build_rss()
-feed.write_xml(open("rt2rss.xml", "w"), "utf-8")
+    feed = events.build_rss()
+    feed.write_xml(open("rt2rss.xml", "w"), "utf-8")
 #!/usr/bin/env python
 # -*- coding: UTF-8 -*-
 import os
+from StringIO import StringIO
 
 import rtorrentnotify as rtn
 
-os.chdir(os.path.dirname(__file__))
 
-events = rtn.Events()
-events.load()
+def test_load():
+    # TODO create the actual DB
+    os.chdir(os.path.dirname(__file__))
 
-print unicode(events)
+    events = rtn.Events()
+    events.load()
+
+    print unicode(events)
+
+
+def test_add():
+    events = rtn.Events()
+    events.append(rtn.Event('LOL', 'cat'))
+    events.append(rtn.Event('LOL', 'cat'))
+    out = unicode(events)
+    assert len(out.splitlines()) == 2
+
+
+def test_rss():
+    events = rtn.Events()
+    events.append(rtn.Event('a', 'b'))
+    events.append(rtn.Event('c', u'héhéhé'))
+
+    feed = events.build_rss()
+    out = StringIO()
+    feed.write_xml(out, "utf-8")
+    out = out.getvalue()
+    assert 'guid' in out