예제 #1
0
파일: tasks.py 프로젝트: suever/MATL-Online
def matl_task(self, *args, **kwargs):
    """Celery task for processing a MATL command and returning the result."""
    self.session_id = kwargs.pop('session', '')
    self.handler.clear()

    is_test = config.ENV == 'test'

    try:
        matl(self.octave, *args, folder=self.folder,
             line_handler=self.handler.process_message, **kwargs)
        result = self.send_results()

    # In the case of an interrupt (either through a time limit or a
    # revoke() event, we will still clean things up
    except (KeyboardInterrupt, SystemExit):
        self.handler.process_message('[STDERR]Job cancelled')
        self.on_kill()
        raise
    except SoftTimeLimitExceeded:
        # Propagate the term event up the chain to actually kill the worker
        self.handler.process_message('[STDERR]Operation timed out')
        self.on_term()

        if is_test:
            self.on_failure()
            self.after_return()

        raise

    if is_test:
        self.on_success()
        self.after_return()

    return result
예제 #2
0
파일: tasks.py 프로젝트: suever/MATL-Online
def matl_task(self, *args, **kwargs):
    """Celery task for processing a MATL command and returning the result."""
    self.session_id = kwargs.pop('session', '')
    self.handler.clear()

    is_test = config.ENV == 'test'

    try:
        matl(self.octave, *args, folder=self.folder,
             stream_handler=self.handler.process_message, **kwargs)
        result = self.send_results()

    # In the case of an interrupt (either through a time limit or a
    # revoke() event, we will still clean things up
    except (KeyboardInterrupt, SystemExit):
        self.handler.process_message('[STDERR]Job cancelled')
        self.on_kill()
        raise
    except SoftTimeLimitExceeded:
        # Propagate the term event up the chain to actually kill the worker
        self.handler.process_message('[STDERR]Operation timed out')
        self.on_term()

        if is_test:
            self.on_failure()
            self.after_return()

        raise

    if is_test:
        self.on_success()
        self.after_return()

    return result
예제 #3
0
    def test_string_escape(self, mocker, app, moctave):
        """All single quotes need to be escaped properly."""
        get_matl_folder = mocker.patch('matl_online.matl.get_matl_folder')
        get_matl_folder.return_value = ''

        matl.matl(moctave, '-ro', code="'abc'")

        # Find the call to matl_runner
        call = [x for x in moctave.evals if x.startswith('matl_runner')]

        assert len(call) == 1
        assert call[0].rstrip() == "matl_runner('-ro', {'''abc'''});"
예제 #4
0
    def test_multiple_inputs(self, mocker, app, moctave):
        """Multiple input parameters should be send to matl_runner."""
        get_matl_folder = mocker.patch('matl_online.matl.get_matl_folder')
        get_matl_folder.return_value = ''

        matl.matl(moctave, '-ro', code='D', inputs='12\n13')

        # Find the call to matl_runner
        call = [x for x in moctave.evals if x.startswith('matl_runner')]

        assert len(call) == 1
        assert call[0].rstrip() == "matl_runner('-ro', {'D'}, '12','13');"
예제 #5
0
    def test_empty_inputs(self, mocker, app, moctave):
        """If no inputs are provided, MATL shouldn't receive any."""
        get_matl_folder = mocker.patch('matl_online.matl.get_matl_folder')
        foldername = 'folder'
        get_matl_folder.return_value = foldername

        matl.matl(moctave, '-ro')

        # Make sure we only had eval calls (faster)
        assert len(moctave.method_calls) == 0

        # Make sure we move to the temp directory at the beginning
        assert moctave.evals[0].startswith('cd(')

        # Ensure the MATL code gets added to the path
        assert moctave.evals[1] == "addpath('%s')" % foldername

        # Make sure we cleanup at the end
        assert moctave.evals[-1].startswith('cd(')