Skip to content

Commit

Permalink
added test for multi level shortening
Browse files Browse the repository at this point in the history
  • Loading branch information
pawelsz-rb committed Apr 17, 2024
1 parent debe4dc commit e46e8e1
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions rollbar/test/test_shortener_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ def setUp(self):
'deque': deque([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], 15),
'other': TestClassWithAVeryVeryVeryVeryVeryVeryVeryLongName(),
'list_max_level': [1, [2, [3, [4, ["good_5", ["bad_6", ["bad_7"]]]]]]],
'dict_max_level': {1: 1, 2: {3: {4: {"level4": "good", "level5": {"toplevel": "ok", 6: {7: {}}}}}}}
'dict_max_level': {1: 1, 2: {3: {4: {"level4": "good", "level5": {"toplevel": "ok", 6: {7: {}}}}}}},
'list_multi_level': [1, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]]
}

def _assert_shortened(self, key, expected):
Expand All @@ -48,15 +49,15 @@ def _assert_shortened(self, key, expected):

if key == 'dict':
self.assertEqual(expected, len(result[key]))
elif key in ('list_max_level', 'dict_max_level'):
elif key in ('list_max_level', 'dict_max_level', 'list_multi_level'):
self.assertEqual(expected, result[key])
else:
# the repr output can vary between Python versions
stripped_result_key = result[key].strip("'\"u")

if key == 'other':
self.assertIn(expected, stripped_result_key)
elif key not in ('dict', 'list_max_level', 'dict_max_level'):
elif key not in ('dict', 'list_max_level', 'dict_max_level', 'list_multi_level'):
self.assertEqual(expected, stripped_result_key)

# make sure nothing else was shortened
Expand Down Expand Up @@ -90,6 +91,10 @@ def test_shorten_list_max_level(self):
expected = [1, [2, [3, [4, ['good_5']]]]]
self._assert_shortened('list_max_level', expected)

def test_shorten_list_multi_level(self):
expected = [1, '[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ...]']
self._assert_shortened('list_multi_level', expected)

def test_shorten_dict_max_level(self):
expected = {1: 1, 2: {3: {4: {'level4': 'good', 'level5': {'toplevel': 'ok'}}}}}
self._assert_shortened('dict_max_level', expected)
Expand Down

0 comments on commit e46e8e1

Please sign in to comment.