def test_clean_error_no_stack_trace(): """ Sometimes stderr may not conform to the expected stacktrace structure. In which case, just return a string version of the message. """ msg = b'This does not conform!' assert microfs.clean_error(msg) == 'This does not conform!'
def test_clean_error(): """ Check that given some bytes (derived from stderr) are turned into a readable error message: we're only interested in getting the error message from the exception, so it's important to strip away all the potentially confusing stack trace if it exists. """ msg = (b'Traceback (most recent call last):\r\n ' b'File "<stdin>", line 2, in <module>\r\n' b'File "<stdin>", line 2, in <module>\r\n' b'File "<stdin>", line 2, in <module>\r\n' b'OSError: file not found\r\n') result = microfs.clean_error(msg) assert result == "OSError: file not found"
def test_clean_error_but_no_error(): """ Worst case, the function has been called with empty bytes so return a vague message. """ assert microfs.clean_error(b'') == 'There was an error.'