Ejemplo n.º 1
0
    def test_kill_kernel_success(self):  # depends on start_kernel
        y = self.a.start_kernel()
        kernel_id = y["kernel_id"]
        assert_in(kernel_id, self.a._kernels)

        retval = self.a.kill_kernel(kernel_id)
        assert_is(retval, True)
        assert_not_in(kernel_id, self.a._kernels)
    def test_kill_kernel_success(self):  # depends on start_kernel
        y = self.a.start_kernel()
        kernel_id = y["kernel_id"]
        assert_in(kernel_id, self.a._kernels)

        retval = self.a.kill_kernel(kernel_id)
        assert_is(retval, True)
        assert_not_in(kernel_id, self.a._kernels)
    def test_purge_kernels_with_failures(self):  # depends on start_kernel
        for i in xrange(5):
            self.a.start_kernel()
        self.a._kernels.add(55)
        self.a._kernels.add(66)

        retval = self.a.purge_kernels()
        assert_in(55, retval)
        assert_in(66, retval)
        assert_len(retval, 2)
Ejemplo n.º 4
0
    def test_purge_kernels_with_failures(self):  # depends on start_kernel
        for i in xrange(5):
            self.a.start_kernel()
        self.a._kernels.add(55)
        self.a._kernels.add(66)

        retval = self.a.purge_kernels()
        assert_in(55, retval)
        assert_in(66, retval)
        assert_len(retval, 2)
Ejemplo n.º 5
0
    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_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_get_kernel_ids_success(self):
     self._populate_comps_kernels()
     x = self.a.get_kernel_ids("testcomp1")
     y = self.a.get_kernel_ids("testcomp2")
     assert_len(x, 2)
     assert_len(y, 1)
     assert_in("kone", x)
     assert_in("ktwo", x)
     assert_not_in("kthree", x)
     assert_in("kthree", y)
Ejemplo n.º 8
0
 def test_get_kernel_ids_success(self):
     self._populate_comps_kernels()
     x = self.a.get_kernel_ids("testcomp1")
     y = self.a.get_kernel_ids("testcomp2")
     assert_len(x, 2)
     assert_len(y, 1)
     assert_in("kone", x)
     assert_in("ktwo", x)
     assert_not_in("kthree", x)
     assert_in("kthree", y)
def test_init():
    fkm = forking_kernel_manager.ForkingKernelManager("testing.log", '127.0.0.1', update_function=test_init)
    assert_len(fkm.kernels, 0)
    assert_equal(fkm.filename, "testing.log")
    assert_in("function test_init at ", repr(fkm.update_function))
Ejemplo n.º 10
0
    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_start_kernel_success(self):
        y = self.a.start_kernel()

        assert_is_instance(y, dict)
        assert_len(y, 2)
        assert_in("kernel_id", y)
        assert_uuid(y["kernel_id"])
        assert_in("connection", y)
        assert_len(y["connection"], 6)
        for s in ("stdin_port", "hb_port", "shell_port", "iopub_port"):
            assert_in(s, y["connection"])
            assert_len(str(y["connection"][s]), 5)
        assert_in("ip", y["connection"])
        assert_equal(y["connection"]["ip"], "127.0.0.1")
        assert_in("key", y["connection"])
        assert_uuid(y["connection"]["key"])

        assert_in(y["kernel_id"], self.a.kernels.keys())
        assert_is_instance(self.a.kernels[y["kernel_id"]][0], Process)
        assert_is(self.a.kernels[y["kernel_id"]][0].is_alive(), True)
Ejemplo n.º 12
0
 def test_start_kernel_success(self):
     y = self.a.start_kernel()
     assert_is_instance(y, dict)
     assert_len(y, 2)
     assert_in("kernel_id", y)
     assert_uuid(y["kernel_id"])
     assert_in(y["kernel_id"], self.a._kernels)
     assert_in("connection", y)
     assert_len(y["connection"], 6)
     for s in ("stdin_port", "hb_port", "shell_port", "iopub_port"):
         assert_in(s, y["connection"])
         assert_len(str(y["connection"][s]), 5)
     assert_in("ip", y["connection"])
     assert_equal(y["connection"]["ip"], "127.0.0.1")
     assert_in("key", y["connection"])
     assert_uuid(y["connection"]["key"])
Ejemplo n.º 13
0
    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)
Ejemplo n.º 14
0
def test_init():
    fkm = forking_kernel_manager.ForkingKernelManager(
        "testing.log", '127.0.0.1', update_function=test_init)
    assert_len(fkm.kernels, 0)
    assert_equal(fkm.filename, "testing.log")
    assert_in("function test_init at ", repr(fkm.update_function))
Ejemplo n.º 15
0
 def test_setup_ssh_connection_success(self):
     x = self.a._setup_ssh_connection("localhost", username=None)
     assert_in("AutoAddPolicy", str(x._policy))
     assert_len(x.get_host_keys(), 1)
Ejemplo n.º 16
0
    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"])
Ejemplo n.º 17
0
 def test_setup_ssh_connection_success(self):
     x = self.a._setup_ssh_connection("localhost", username=None)
     assert_in("AutoAddPolicy", str(x._policy))
     assert_len(x.get_host_keys(), 1)
Ejemplo n.º 18
0
    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)