Beispiel #1
0
    def test_invalid_audio_parsing(self):
        """Test with a bad filename and ensure no result."""
        filename = '/ignore/this/audio.wav'
        result = matl.parse_matl_results('[AUDIO]' + filename)

        assert isinstance(result, list)
        assert len(result) == 0
Beispiel #2
0
    def test_invalid_image_parsing(self):
        """Test with a bad filename and ensure no result."""
        filename = '/ignore/this/filename.png'
        result = matl.parse_matl_results('[IMAGE]' + filename)

        assert isinstance(result, list)
        assert len(result) == 0
Beispiel #3
0
    def test_stdout_multi_line_parsing(self):
        """Multi-line output is also handled as STDOUT if not specified."""
        expected = 'standard\noutput'
        result = matl.parse_matl_results(expected)

        assert isinstance(result, list)
        assert len(result) == 1
        assert result[0]['type'] == 'stdout'
        assert result[0]['value'] == expected
Beispiel #4
0
    def test_stdout_single_line_parsing(self):
        """A single line of output is handled as STDOUT."""
        expected = 'standard output'
        result = matl.parse_matl_results(expected)

        assert isinstance(result, list)
        assert len(result) == 1
        assert result[0]['type'] == 'stdout'
        assert result[0]['value'] == expected
Beispiel #5
0
    def test_stdout2_parsing(self):
        """Test potential to have a second type of STDOUT."""
        expected = 'ouptut2'
        result = matl.parse_matl_results('[STDOUT]' + expected)

        assert isinstance(result, list)
        assert len(result) == 1
        assert result[0]['type'] == 'stdout2'
        assert result[0]['value'] == expected
Beispiel #6
0
    def test_error_parsing(self):
        """All errors are correctly classified."""
        msg = 'single error'
        result = matl.parse_matl_results('[STDERR]' + msg)

        assert isinstance(result, list)
        assert len(result) == 1
        assert result[0]['type'] == 'stderr'
        assert result[0]['value'] == msg
Beispiel #7
0
    def test_audio_parsing(self, tmpdir):
        """Test valid audio result."""
        fileobj = tmpdir.join('audio.wav')
        contents = b'AUDIO'
        fileobj.write(contents)

        # Parse the string
        result = matl.parse_matl_results('[AUDIO]' + fileobj.strpath)

        assert isinstance(result, list)
        assert len(result) == 1
        assert result[0]['type'] == 'audio'

        encoded = base64.b64encode(contents).decode()
        assert result[0]['value'] == 'data:audio/wav;base64,' + encoded

        # Make sure that the file was not removed
        assert os.path.isfile(fileobj.strpath)
Beispiel #8
0
    def test_image_parsing(self, tmpdir):
        """Test valid image result."""
        fileobj = tmpdir.join('image.png')
        contents = b'hello'
        fileobj.write(contents)

        # Parse the string
        result = matl.parse_matl_results('[IMAGE]' + fileobj.strpath)

        assert isinstance(result, list)
        assert len(result) == 1
        assert result[0]['type'] == 'image'

        # Since the file is empty it should just be the header portion
        encoded = base64.b64encode(contents).decode()
        assert result[0]['value'] == 'data:image/png;base64,' + encoded

        # Make sure the file was not removed
        assert os.path.isfile(fileobj.strpath)
Beispiel #9
0
 def send(self):
     """Send a message out to the specified rooms."""
     output = parse_matl_results(self.messages())
     result = {'data': output, 'session': self.task.session_id}
     socket.emit('status', result, room=self.task.session_id)
     return result
Beispiel #10
0
 def send(self):
     """Send a message out to the specified rooms."""
     output = parse_matl_results(self.messages())
     result = {'data': output, 'session': self.task.session_id}
     socket.emit('status', result, room=self.task.session_id)
     return result