Commits

Andriy Kornatskyy committed 0bcd65b

Prefer KeyError in case requested path is not found; do not silence to None.

Comments (0)

Files changed (2)

src/wheezy/routing/router.py

             Otherwise None
 
             >>> r.path_for(r'unknown')
+            Traceback (most recent call last):
+                ...
+            KeyError: 'unknown'
         """
         if name in self.route_map:
             return self.route_map[name](kwargs)
         else:
-            try:
-                return ''.join([path(kwargs) for path
-                                in self.inner_route_map[name]])
-            except KeyError:
-                return None
+            return ''.join([path(kwargs) for path
+                            in self.inner_route_map[name]])

src/wheezy/routing/tests/test_router.py

     def test_no_match(self):
         """ no match
         """
-        path = self.r.path_for('n', a=1)
-        self.assertEquals(None, path)
+        self.assertRaises(KeyError, lambda: self.r.path_for('n', a=1))
 
     def test_route_map(self):
         """ the name exists in ``route_map``.
         self.m.replay()
 
         self.r.include('abc/', [])
-        p = self.r.path_for('n')
-
-        assert p is None
+        self.assertRaises(KeyError, lambda: self.r.path_for('n'))
 
     def test_match(self):
         """ match inner router