def test__ensure_node(self, gcimock): bep = BaseEndpoint() self.assertIsNone(bep.node) bep._ensure_node() self.assertEquals(bep.node, gcimock().node)
def test__ensure_node(self, gcimock): bep = BaseEndpoint() self.assertIsNone(bep.node) bep._ensure_node() self.assertEquals(bep.node, gcimock().node)
class TestBaseEndpoint(PyonTestCase): def setUp(self): self._node = Mock(spec=NodeB) self._ef = BaseEndpoint(node=self._node) self._ch = Mock(spec=SendChannel) self._node.channel.return_value = self._ch def test_create_endpoint(self): e = self._ef.create_endpoint() # check attrs self.assertTrue(hasattr(e, 'channel')) # make sure we can shut it down e.close() self._ch.close.assert_any_call() def test_create_endpoint_existing_channel(self): ch = Mock(spec=SendChannel) e = self._ef.create_endpoint(existing_channel=ch) self.assertEquals(e.channel, ch) self.assertEquals(ch.connect.call_count, 0) ch.connect("exist") ch.connect.assert_called_once_with('exist') e.close() def test_create_endpoint_kwarg(self): """ Make sure our kwarg gets set. """ class OptEndpointUnit(EndpointUnit): def __init__(self, opt=None, **kwargs): self._opt = opt EndpointUnit.__init__(self, **kwargs) self._ef.endpoint_unit_type = OptEndpointUnit e = self._ef.create_endpoint(opt="stringer") self.assertTrue(hasattr(e, "_opt")) self.assertEquals(e._opt, "stringer") def test__ensure_node_errors(self): bep = BaseEndpoint() gcimock = Mock() gcimock.return_value = None with patch('pyon.net.endpoint.BaseEndpoint._get_container_instance', gcimock): self.assertRaises(EndpointError, bep._ensure_node) @patch('pyon.net.endpoint.BaseEndpoint._get_container_instance') def test__ensure_node_existing_node(self, gcimock): self._ef._ensure_node() self.assertFalse(gcimock.called) @patch('pyon.net.endpoint.BaseEndpoint._get_container_instance') def test__ensure_node(self, gcimock): bep = BaseEndpoint() self.assertIsNone(bep.node) bep._ensure_node() self.assertEquals(bep.node, gcimock().node) def test__get_container_instance(self): c = Container() # ensure we've got an instance in Container.instance self.assertEquals(BaseEndpoint._get_container_instance(), c) def test_close(self): bep = BaseEndpoint() bep.close()
class TestBaseEndpoint(PyonTestCase): def setUp(self): self._node = Mock(spec=NodeB) self._ef = BaseEndpoint(node=self._node) self._ch = Mock(spec=SendChannel) self._node.channel.return_value = self._ch def test_create_endpoint(self): e = self._ef.create_endpoint() # check attrs self.assertTrue(hasattr(e, 'channel')) # make sure we can shut it down e.close() self._ch.close.assert_any_call() def test_create_endpoint_existing_channel(self): ch = Mock(spec=SendChannel) e = self._ef.create_endpoint(existing_channel=ch) self.assertEquals(e.channel, ch) self.assertEquals(ch.connect.call_count, 0) ch.connect("exist") ch.connect.assert_called_once_with('exist') e.close() def test_create_endpoint_kwarg(self): """ Make sure our kwarg gets set. """ class OptEndpointUnit(EndpointUnit): def __init__(self, opt=None, **kwargs): self._opt = opt EndpointUnit.__init__(self, **kwargs) self._ef.endpoint_unit_type = OptEndpointUnit e = self._ef.create_endpoint(opt="stringer") self.assertTrue(hasattr(e, "_opt")) self.assertEquals(e._opt, "stringer") def test__ensure_node_errors(self): bep = BaseEndpoint() gcimock = Mock() gcimock.return_value = None with patch('pyon.net.endpoint.BaseEndpoint._get_container_instance', gcimock): self.assertRaises(EndpointError, bep._ensure_node) @patch('pyon.net.endpoint.BaseEndpoint._get_container_instance') def test__ensure_node_existing_node(self, gcimock): self._ef._ensure_node() self.assertFalse(gcimock.called) @patch('pyon.net.endpoint.BaseEndpoint._get_container_instance') def test__ensure_node(self, gcimock): bep = BaseEndpoint() self.assertIsNone(bep.node) bep._ensure_node() self.assertEquals(bep.node, gcimock().node) def test__get_container_instance(self): c = Container() # ensure we've got an instance in Container.instance self.assertEquals(BaseEndpoint._get_container_instance(), c) def test_close(self): bep = BaseEndpoint() bep.close()
class TestBaseEndpoint(PyonTestCase): def setUp(self): self._node = Mock(spec=NodeB) self._ef = BaseEndpoint(node=self._node, name="EFTest") self._ch = Mock(spec=SendChannel) self._node.channel.return_value = self._ch def test_create_endpoint(self): e = self._ef.create_endpoint() # check attrs self.assertTrue(hasattr(e, "channel")) self.assertEquals(self._ch.connect.call_count, 1) self.assertTrue(self._ef.name in self._ch.connect.call_args[0]) # make sure we can shut it down e.close() self._ch.close.assert_any_call() def test_create_endpoint_new_name(self): e = self._ef.create_endpoint(to_name="reroute") self.assertEquals(self._ch.connect.call_count, 1) self.assertTrue("reroute" in self._ch.connect.call_args[0][0]) # @TODO: this is obtuse e.close() def test_create_endpoint_existing_channel(self): ch = Mock(spec=SendChannel) e = self._ef.create_endpoint(existing_channel=ch) self.assertEquals(e.channel, ch) self.assertEquals(ch.connect.call_count, 0) ch.connect("exist") ch.connect.assert_called_once_with("exist") e.close() def test_create_endpoint_kwarg(self): """ Make sure our kwarg gets set. """ class OptEndpointUnit(EndpointUnit): def __init__(self, opt=None, **kwargs): self._opt = opt EndpointUnit.__init__(self, **kwargs) self._ef.endpoint_unit_type = OptEndpointUnit e = self._ef.create_endpoint(opt="stringer") self.assertTrue(hasattr(e, "_opt")) self.assertEquals(e._opt, "stringer") def test__ensure_node_errors(self): bep = BaseEndpoint(name=sentinel.name) gcimock = Mock() gcimock.return_value = None with patch("pyon.net.endpoint.BaseEndpoint._get_container_instance", gcimock): self.assertRaises(EndpointError, bep._ensure_node) @patch("pyon.net.endpoint.BaseEndpoint._get_container_instance") def test__ensure_node_existing_node(self, gcimock): self._ef._ensure_node() self.assertFalse(gcimock.called) @patch("pyon.net.endpoint.BaseEndpoint._get_container_instance") def test__ensure_node(self, gcimock): bep = BaseEndpoint(name=sentinel.name) self.assertIsNone(bep.node) bep._ensure_node() self.assertEquals(bep.node, gcimock().node)