comparison roundup/web/router.py @ 4907:c37069a99cec routing

routing: Add self-test to router.py
author anatoly techtonik <techtonik@gmail.com>
date Tue, 15 Jul 2014 13:47:28 +0300
parents b860ede03056
children f31c93abedf6
comparison
equal deleted inserted replaced
4906:b860ede03056 4907:c37069a99cec
48 pattern, handler = self.urlmap[i], self.urlmap[i+1] 48 pattern, handler = self.urlmap[i], self.urlmap[i+1]
49 match = re.match(pattern, urlpath) 49 match = re.match(pattern, urlpath)
50 if match: 50 if match:
51 return handler, match.groups() 51 return handler, match.groups()
52 return (None, ()) 52 return (None, ())
53
54
55
56 # [ ] len(urlmap) should be even to avoid errors
57 # (find a way to explain this to users)
58
59 if __name__ == '__main__':
60
61 import unittest
62 class test_Router(unittest.TestCase):
63 def test_example_routes(self):
64 router = Router(EXAMPLE_URLMAP)
65 self.assertEquals(router.get_handler(''), (None, ()))
66 handler, params = router.get_handler('/')
67 self.assertEquals(handler, ExampleHandler)
68 self.assertEquals(params, tuple())
69
70 unittest.main()

Roundup Issue Tracker: http://roundup-tracker.org/