From 4f88206178e37205ac13220f4d38b8132839acd9 Mon Sep 17 00:00:00 2001 From: Raman Tenneti Date: Tue, 28 Sep 2021 17:15:14 -0700 Subject: trace2_event: Add remove_prefix to fix failing tests on Linux & macOS. removeprefix is available i python 3.9. Mac and Linux are running in a version below 3.9. Thus tests are failing with the following error: "AttributeError: 'str' object has no attribute 'removeprefix' " Replaced the removeprefix with custom function which we will delete once Linux and macOS versions are updated. Tested: $ ./run_tests Bug: [google internal] b/201453085 Change-Id: I9b4d564ff1176e1b4471805ef05472c1914cd9f9 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/319375 Tested-by: Raman Tenneti Reviewed-by: Mike Frysinger --- tests/test_git_trace2_event_log.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'tests/test_git_trace2_event_log.py') diff --git a/tests/test_git_trace2_event_log.py b/tests/test_git_trace2_event_log.py index 7bd21e21..89dcfb92 100644 --- a/tests/test_git_trace2_event_log.py +++ b/tests/test_git_trace2_event_log.py @@ -66,6 +66,13 @@ class EventLogTestCase(unittest.TestCase): log_data.append(json.loads(line)) return log_data + def remove_prefix(self, s, prefix): + """Return a copy string after removing |prefix| from |s|, if present or the original string.""" + if s.startswith(prefix): + return s[len(prefix):] + else: + return s + def test_initial_state_with_parent_sid(self): """Test initial state when 'GIT_TRACE2_PARENT_SID' is set by parent.""" self.assertRegex(self._event_log_module.full_sid, self.FULL_SID_REGEX) @@ -265,7 +272,8 @@ class EventLogTestCase(unittest.TestCase): # Check for 'data' event specific fields. self.assertIn('key', event) self.assertIn('value', event) - key = event['key'].removeprefix(f'{prefix_value}/') + key = event['key'] + key = self.remove_prefix(key, f'{prefix_value}/') value = event['value'] self.assertEqual(self._event_log_module.GetDataEventName(value), event['event']) self.assertTrue(key in config and value == config[key]) -- cgit v1.2.3-54-g00ecf