Ejemplo n.º 1
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_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.º 3
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"])
 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.º 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')
Ejemplo n.º 6
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)
    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",
        )