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
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
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
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
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
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
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)
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)
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