def test_create_connected_stream(self): host="localhost" port = 51337 socket_type = zmq.SUB with capture_output() as (out, err): ret = self.a._create_connected_stream(host, port, socket_type) out = out[0] assert_is(ret.closed(), False) assert_equal(ret.socket.socket_type, zmq.SUB) #assert_equal(out, "Connecting to: tcp://%s:%i\n" % (host, port)) host="localhost" port = 51337 socket_type = zmq.REQ ret = self.a._create_connected_stream(host, port, socket_type) assert_is(ret.closed(), False) assert_equal(ret.socket.socket_type, zmq.REQ) host="localhost" port = 51337 socket_type = zmq.DEALER ret = self.a._create_connected_stream(host, port, socket_type) assert_is(ret.closed(), False) assert_equal(ret.socket.socket_type, zmq.DEALER)
def test_create_connected_stream(self): host = "localhost" port = 51337 socket_type = zmq.SUB with capture_output() as (out, err): ret = self.a._create_connected_stream(host, port, socket_type) out = out[0] assert_is(ret.closed(), False) assert_equal(ret.socket.socket_type, zmq.SUB) # assert_equal(out, "Connecting to: tcp://%s:%i\n" % (host, port)) host = "localhost" port = 51337 socket_type = zmq.REQ ret = self.a._create_connected_stream(host, port, socket_type) assert_is(ret.closed(), False) assert_equal(ret.socket.socket_type, zmq.REQ) host = "localhost" port = 51337 socket_type = zmq.DEALER ret = self.a._create_connected_stream(host, port, socket_type) assert_is(ret.closed(), False) assert_equal(ret.socket.socket_type, zmq.DEALER)
def test_restart_kernel_success(self): # depends on add_computer, new_session x = self.a.add_computer(self.default_comp_config) kern1 = self.a.new_session() kern2 = self.a.new_session() with capture_output() as (out, err): self.a.restart_kernel(kern2) out = out[0] y = ast.literal_eval(out) assert_is_instance(y, dict) assert_in("content", y) assert_len(y["content"], 2) assert_in("type", y) assert_equal(y["type"], "success") assert_in("kernel_id", y["content"]) assert_uuid(y["content"]["kernel_id"]) assert_in("connection", y["content"]) assert_len(y["content"]["connection"], 6) for s in ("stdin_port", "hb_port", "shell_port", "iopub_port"): assert_in(s, y["content"]["connection"]) assert_len(str(y["content"]["connection"][s]), 5) assert_in("ip", y["content"]["connection"]) assert_equal(y["content"]["connection"]["ip"], "127.0.0.1") assert_in("key", y["content"]["connection"]) assert_uuid(y["content"]["connection"]["key"])
def test_ssh_untrusted(self): client = self.a._setup_ssh_connection(self.default_comp_config["host"], self.default_comp_config["username"]) with capture_output() as (out, err): x = self.a._ssh_untrusted(self.default_comp_config, client) out = out[0] assert_is_not_none(x) assert_is_instance(x,int)
def test_ssh_untrusted(self): client = self.a._setup_ssh_connection(self.default_comp_config["host"], self.default_comp_config["username"]) with capture_output() as (out, err): x = self.a._ssh_untrusted(self.default_comp_config, client) out = out[0] assert_is_not_none(x) assert_is_instance(x, int)
def test_end_session_success(self): # depends on add_computer, new_session x = self.a.add_computer(self.default_comp_config) kern1 = self.a.new_session() kern2 = self.a.new_session() with capture_output(split=True) as (out,err): self.a.end_session(kern1) assert_not_in(kern1, self.a._kernels.keys()) for v in self.a._comps.values(): assert_not_in(kern1, v["kernels"]) #assert_in("Killing Kernel ::: %s at "%kern1, out[0]) #assert_in("Kernel %s successfully killed."%kern1, out[1]) with capture_output(split=True) as (out,err): self.a.end_session(kern2) assert_not_in(kern2, self.a._kernels) for v in self.a._comps.values(): assert_not_in(kern2, v["kernels"])
def test_end_session_success(self): # depends on add_computer, new_session x = self.a.add_computer(self.default_comp_config) kern1 = self.a.new_session() kern2 = self.a.new_session() with capture_output(split=True) as (out, err): self.a.end_session(kern1) assert_not_in(kern1, self.a._kernels.keys()) for v in self.a._comps.values(): assert_not_in(kern1, v["kernels"]) # assert_in("Killing Kernel ::: %s at "%kern1, out[0]) # assert_in("Kernel %s successfully killed."%kern1, out[1]) with capture_output(split=True) as (out, err): self.a.end_session(kern2) assert_not_in(kern2, self.a._kernels) for v in self.a._comps.values(): assert_not_in(kern2, v["kernels"])
def test_purge_kernels_no_kernels(self): # depends on add_computer x = self.a.add_computer(self.default_comp_config) with capture_output() as (out, err): self.a.purge_kernels(x) out = out[0] self._check_all_kernels_killed_out(out) assert_equal(self.a._comps[x]["kernels"], {}) assert_equal(self.a._kernels, {})
def test_remove_computer_success(self): # depends on add_computer, new_session x = self.a.add_computer(self.default_comp_config) kern1 = self.a.new_session() kern2 = self.a.new_session() b = self.a.add_computer(self.default_comp_config) # remove computer with active kernels with capture_output() as (out, err): self.a.remove_computer(x) out = out[0] self._check_all_kernels_killed_out(out) assert_not_in(kern1, self.a._kernels) assert_not_in(kern2, self.a._kernels) assert_not_in(x, self.a._comps) # remove computer with no kernels with capture_output() as (out, err): self.a.remove_computer(b) out = out[0] self._check_all_kernels_killed_out(out) assert_not_in(b, self.a._comps)
def test_add_computer_success(self): # depends on _setup_ssh_connection, _ssh_untrusted new_config = self.default_comp_config.copy() new_config.update({'beat_interval': 0.5, 'first_beat': 1, 'kernels': {}}) with capture_output(split=True) as (out,err): x = self.a.add_computer(self.default_comp_config) assert_is_not_none(x) assert_uuid(x) assert_in(x, self.a._comps) for k in new_config: assert_equal(self.a._comps[x][k], new_config[k], "config value %s (%s) does not agree (should be %s)"%(k,self.a._comps[x][k], new_config[k])) assert_in("ssh", self.a._clients[x]) #assert_regexp_matches(out[0], self.executing_re) assert_regexp_matches(out[0], r'ZMQ Connection with computer [a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12} at port \d+ established')
def test_new_session_success(self): # depends on add_computer x = self.a.add_computer(self.default_comp_config) with capture_output() as (out, err): kern1 = self.a.new_session() out = out[0] assert_in(kern1, self.a._kernels) assert_in("comp_id", self.a._kernels[kern1]) assert_uuid(self.a._kernels[kern1]["comp_id"]) assert_in("connection", self.a._kernels[kern1]) assert_in("executing", self.a._kernels[kern1]) assert_is(self.a._kernels[kern1]["executing"], False) assert_in("timeout", self.a._kernels[kern1]) assert_greater(time.time(), self.a._kernels[kern1]["timeout"]) x = self.a._kernels[kern1]["comp_id"] assert_in(kern1, self.a._comps[x]["kernels"]) assert_is_instance(self.a._sessions[kern1], Session)
def test_add_computer_success(self): # depends on _setup_ssh_connection, _ssh_untrusted new_config = self.default_comp_config.copy() new_config.update({"beat_interval": 0.5, "first_beat": 1, "kernels": {}}) with capture_output(split=True) as (out, err): x = self.a.add_computer(self.default_comp_config) assert_is_not_none(x) assert_uuid(x) assert_in(x, self.a._comps) for k in new_config: assert_equal( self.a._comps[x][k], new_config[k], "config value %s (%s) does not agree (should be %s)" % (k, self.a._comps[x][k], new_config[k]), ) assert_in("ssh", self.a._clients[x]) # assert_regexp_matches(out[0], self.executing_re) assert_regexp_matches( out[0], r"ZMQ Connection with computer [a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12} at port \d+ established", )