[FIX] unittests
authorFlorian Schweikert <kelvan@logic.at>
Wed, 28 Sep 2011 00:43:12 +0000 (02:43 +0200)
committerFlorian Schweikert <kelvan@logic.at>
Wed, 28 Sep 2011 00:43:12 +0000 (02:43 +0200)
set coding to unicode
define interpreter

iTip.py
scotty.py
tests/realtime.py
tests/routing.py

diff --git a/iTip.py b/iTip.py
index 4b63f61..ab8a38b 100644 (file)
--- a/iTip.py
+++ b/iTip.py
@@ -1,3 +1,6 @@
+#!/usr/bin/env python
+# -*- coding: UTF-8 -*-
+
 from BeautifulSoup import BeautifulSoup
 from urllib2 import urlopen
 import settings
index 92005ff..4d22534 100644 (file)
--- a/scotty.py
+++ b/scotty.py
@@ -1,3 +1,6 @@
+#!/usr/bin/env python
+# -*- coding: UTF-8 -*-
+
 from BeautifulSoup import BeautifulSoup, NavigableString
 from urllib2 import urlopen
 from urllib import urlencode
index c6a07aa..9d2b1e3 100644 (file)
@@ -19,4 +19,7 @@ class ParseTest(unittest.TestCase):
         s = []
         for line in lines:
             s.append(parser.get_stations(line[0]))
-        self.assertTrue(s)
\ No newline at end of file
+        self.assertTrue(s)
+
+if __name__ == '__main__':
+    unittest.main()
index c382338..07a9d90 100644 (file)
@@ -1,38 +1,50 @@
+#!/usr/bin/env python
+# -*- coding: UTF-8 -*-
 import unittest
-from wlSearch import Search
+from scotty import search, ParserError, sParser, rParser, PageType
 from datetime import datetime
-from parseHtml import Parser, iParser, ParserError
 from BeautifulSoup import BeautifulSoup
 
-origin = 'Karlsplatz'
-destination = 'Handelskai'
 dtime = datetime.now()
 dtime = dtime.replace(hour=15, minute=0)
-search = Search(origin, destination)
-bs = BeautifulSoup(search.get_html(dtime))
 
-class FetchTest(unittest.TestCase):
+origin = u'Börse'.encode('UTF-8')
+destination = 'Handelskai'
+s = search((origin, 'stop'), (destination, 'stop'), dtime).read()
+parser = sParser(s)
+p = rParser(s)
+
 
-    def test_overview(self):
-        self.assertEquals(1, len(bs.findAll('table', {'id': 'tbl_fahrten'})))
+originc = 'Simmeri'
+destinationc = 'Karlspla'
+sc = search((originc, 'stop'), (destinationc, 'stop'), dtime).read()
+parserc = sParser(sc)
 
-    def test_details(self):
-        self.assertTrue(len(bs.findAll('div', {'class': 'data_table tourdetail'})) > 0)
 
-origin = 'Zwicklgasse 1'
-destination = 'Himmelstrasse 1'
+origina = 'Zwicklgasse 1'
+destinationa = 'Himmelstrasse 1'
 ot = dt = 'address'
-s = Search(origin, destination, origin_type=ot, destination_type=dt)
-p = Parser(s.get_html(dtime))
 
-origin = 'Foobar Strasse 123'
-destination = 'Bazgasse 321'
-s = Search(origin, destination, origin_type=ot, destination_type=dt)
-invalid_parser = Parser(s.get_html(dtime))
 
+originac = 'Foobar Strasse 123'
+destinationac = 'Bazgasse 321'
 
-class ParseTest(unittest.TestCase):
 
+class SearchTest(unittest.TestCase):
+
+    def test_state(self):
+        state = parser.check_page()
+        statec = parserc.check_page()
+        
+        self.assertEqual(PageType.RESULT, state)
+        self.assertEqual(PageType.CORRECTION, statec)
+        
+    def test_correction(self):
+        cor = parserc.get_correction()
+        s = search((cor[0][0], 'stop'), (cor[1][0], 'stop'), dtime).read()
+        parser = sParser(s)
+        self.assertEqual(PageType.RESULT, parser.check_page())
+    
     def test_overview_shouldFindMultipleItems(self):
         # TODO Replace with assertGreater in new python version
         self.assertTrue(len(p.overview) > 1)
@@ -48,10 +60,6 @@ class ParseTest(unittest.TestCase):
     def test_parser_overviewAndDetailsShouldHaveSameLength(self):
         self.assertEqual(len(p.details), len(p.overview))
 
-    def test_parser_shouldRaiseError(self):
-        # TODO Replace with expectedFailure decorator in new python version
-        self.assertRaises(ParserError, invalid_parser._parse_overview)
-
     def test_parser_shouldFindMoreThanOneChange(self):
         self.assertTrue(p.overview[0]['change'] > 0)