Log monitor encoding fix (#729)

Fixed log monitor encoding bug.
main
SSpalding 5 years ago committed by GitHub
parent 50abafbab1
commit 67c3801d73
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -44,7 +44,7 @@ def check_exact_match(line, expected_line):
# Look for either start of line or whitespace, then the expected_line, then either end of the line or whitespace.
# This way we don't partial match inside of a string. So for example, 'foo' matches 'foo bar' but not 'foobar'
regex_pattern = re.compile("(^|\\s){}($|\\s)".format(re.escape(expected_line)))
regex_pattern = re.compile("(^|\\s){}($|\\s)".format(re.escape(expected_line)), re.UNICODE)
if regex_pattern.search(line) is not None:
return expected_line
@ -125,7 +125,7 @@ class LogMonitor(object):
self.py_log = ""
try:
logger.debug("Monitoring log file in '{}' ".format(self.log_file_path))
with open(self.log_file_path, mode='r') as log:
with open(self.log_file_path, mode='r', encoding='utf-8') as log:
logger.info(
"Monitoring log file '{}' for '{}' seconds".format(self.log_file_path, timeout))

@ -98,6 +98,16 @@ class TestLogMonitor(object):
under_test = ly_test_tools.log.log_monitor.check_exact_match(line, expected_line)
assert under_test == expected_line
@mock.patch('os.path.exists', mock.MagicMock(return_value=True))
def test_Monitor_UTF8StringsPresentAndExpected_Success(self):
mock_file = io.StringIO('gr\xc3\xb6\xc3\x9feren pr\xc3\xbcfung \xd1\x82\xd0\xb5\xd1\x81\xd1\x82\xd1\x83\xd0\xb2\xd0\xb0\xd0\xbd\xd0\xbd\xd1\x8f\n\xc3\x80\xc3\x88\xc3\x8c\xc3\x92\xc3\x99\n\xc3\x85lpha\xc3\x9fravo\xc3\xa7harlie\n')
mock_launcher.is_alive.side_effect = [True, True, True, False]
with mock.patch('ly_test_tools.log.log_monitor.open', return_value=mock_file, create=True):
mock_log_monitor().monitor_log_for_lines(['gr\xc3\xb6\xc3\x9feren pr\xc3\xbcfung \xd1\x82\xd0\xb5\xd1\x81\xd1\x82\xd1\x83\xd0\xb2\xd0\xb0\xd0\xbd\xd0\xbd\xd1\x8f',
'\xc3\x80\xc3\x88\xc3\x8c\xc3\x92\xc3\x99',
'\xc3\x85lpha\xc3\x9fravo\xc3\xa7harlie'])
@mock.patch('os.path.exists', mock.MagicMock(return_value=True))
def test_Monitor_AllLinesFound_Success(self):
mock_file = io.StringIO(u'a\nb\nc\n')

Loading…
Cancel
Save