예제 #1
0
 def get_any_session(self):
     number_of_sessions = len(self._sessions)
     if number_of_sessions == 1:
         key = self.get_sessions_list()[0]
         return self._sessions[key]
     elif number_of_sessions == 0:
         raise SessionManagementException(u"You need to have at least 1 client created to execute commands.")
     else:
         raise SessionManagementException(u"Please specify the client to use. Possible sessions are {}".format(
             self.get_sessions_list()))
예제 #2
0
 def _remove_session(self, name):
     if name in self.get_sessions_list():
         self._sessions[name].delete()
         del self._sessions[name]
     else:
         raise SessionManagementException(u"Could not find '{}' session in list of saved sessions. Possible sessions are {}"
                                          .format(name, self.get_sessions_list()))
예제 #3
0
def test_spark_expected_exception():
    line = ""
    cell = "some spark code"
    spark_controller.run_command = MagicMock(side_effect=SessionManagementException('oups'))

    magic.spark(line, cell)
    spark_controller.run_command.assert_called_once_with(Command(cell), None)
    ipython_display.send_error.assert_called_once_with(constants.EXPECTED_ERROR_MSG
                                                       .format(spark_controller.run_command.side_effect))
예제 #4
0
 def get_any_session(self):
     number_of_sessions = len(self._sessions)
     if number_of_sessions == 1:
         key = self.get_sessions_list()[0]
         return self._sessions[key]
     elif number_of_sessions == 0:
         raise SessionManagementException(
             u"You need to have at least 1 client created to execute commands."
         )
     else:
         import random
         session_list = list(self._sessions.values())
         random.shuffle(session_list)
         for session in session_list:
             if session.status == constants.IDLE_SESSION_STATUS:
                 return session
         else:
             raise SessionManagementException(u"Not session available")
예제 #5
0
def test_spark_expected_exception_in_storing():
    line = "-o var_name"
    cell = "some spark code"
    side_effect = [(True,'ok',constants.MIMETYPE_TEXT_PLAIN), SessionManagementException('oups')]
    spark_controller.run_command = MagicMock(side_effect=side_effect)

    magic.spark(line, cell)
    assert spark_controller.run_command.call_count == 2
    spark_controller.run_command.assert_any_call(Command(cell), None)
    ipython_display.send_error.assert_called_with(constants.EXPECTED_ERROR_MSG
                                                  .format(side_effect[1]))
def test_get_logs_error():
    chosen_client = MagicMock()
    controller.get_session_by_name_or_default = MagicMock(
        side_effect=SessionManagementException('THERE WAS A SPOOKY GHOST'))

    result = controller.get_logs()
예제 #7
0
 def get_session(self, name):
     if name in self._sessions:
         return self._sessions[name]
     raise SessionManagementException(u"Could not find '{}' session in list of saved sessions. Possible sessions are {}".format(
         name, self.get_sessions_list()))
예제 #8
0
    def add_session(self, name, session):
        if name in self._sessions:
            raise SessionManagementException(u"Session with name '{}' already exists. Please delete the session"
                                             u" first if you intend to replace it.".format(name))

        self._sessions[name] = session