diff --git a/Tools/LyTestTools/ly_test_tools/log/log_monitor.py b/Tools/LyTestTools/ly_test_tools/log/log_monitor.py index ca3cd24303..ea3991342a 100755 --- a/Tools/LyTestTools/ly_test_tools/log/log_monitor.py +++ b/Tools/LyTestTools/ly_test_tools/log/log_monitor.py @@ -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)) diff --git a/Tools/LyTestTools/tests/unit/test_log_monitor.py b/Tools/LyTestTools/tests/unit/test_log_monitor.py index 5be2b48d8b..2dd588f9ff 100755 --- a/Tools/LyTestTools/tests/unit/test_log_monitor.py +++ b/Tools/LyTestTools/tests/unit/test_log_monitor.py @@ -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')