def on_line(self, line): r = router.router(( (r"^add network\s+(.*?)\s+(.*?)$", self._add_network), (r"^set network\s+(.*?)\s+(.*?)$", self._set_network), (r"^show enclosure\s*$", self._show_enclosure), (r"^set enet-connection\s+(.*?)\s+(.*?)$", self._set_enetconnection) ), self._missing) r.dispatch(line) self._endl() self._prompt()
def test_dispatch_gives_the_line_that_originated_the_event_plus_the_matching_groups(self): m = mock.Mock() r = router.router(((r"^foo(bar)$", m),), "default") r.dispatch("foobar") m.assert_called_with("foobar", "bar")
def on_line(self, line): r = router.router(( (r"^ping$", self._pong), ), self._missing) r.dispatch(line) self._endl() self._prompt()
def test_dispatch_gives_the_line_that_originated_the_event(self): m = mock.Mock() r = router.router((), m) r.dispatch("foobar") m.assert_called_with("foobar")
def test_find_action_returns_matching_groups(self): r = router.router(((r"^foo(bar)$", "success"),), "default") self.assertEqual(("success", ("bar",)), r.find_action("foobar"))
def test_find_action_uses_default_route(self): r = router.router((), "default") self.assertEqual(("default",()), r.find_action("foobar"))
def test_find_action_uses_routes_as_regexp(self): r = router.router(((r"^foobar$", "success"),), "default") self.assertEqual(("success",()), r.find_action("foobar"))
def test_init(self): r = router.router("router", "default") self.assertEqual("router", r.routes) self.assertEqual("default", r.default)