Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(480)

Unified Diff: recipe_engine/unittests/util_test.py

Issue 2768883004: json: Improve error handling and adding ability to limit log output.
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | recipe_engine/util.py » ('j') | recipe_modules/json/api.py » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: recipe_engine/unittests/util_test.py
diff --git a/recipe_engine/unittests/util_test.py b/recipe_engine/unittests/util_test.py
index 37932d65fbf4bb7f4ed19bd87f356b970b7184a7..f4fa6dc762ac76e237eb2842841dec0fc160f699 100755
--- a/recipe_engine/unittests/util_test.py
+++ b/recipe_engine/unittests/util_test.py
@@ -87,5 +87,47 @@ class TestMapDeferExceptions(unittest.TestCase):
self.assertRaises(ValueError, util.map_defer_exceptions, fn, [1], KeyError)
+class TestSnipOutputLines(unittest.TestCase):
+
+ def testIdempotentOnSmallData(self):
+ small_data = [
+ [''],
+ ['', ''],
+ [' '],
+ [' ', ' '],
+ ['hello world'],
+ ['hello world', ''],
+ ['hello', 'world'],
+ ['', 'hello world'],
+ ]
+
+ for d in small_data:
+ self.assertEqual(d, util.snip_output_lines(d, max_bytes=100))
+
+ def testSnipWithNoLines(self):
+ lines = ['---------']
+ expected = ['--- ...', '<snip>', '... ---']
+ self.assertEqual(
+ expected, util.snip_output_lines(lines, max_bytes=6))
+
+ def testSnipWithLines(self):
+ lines = ['-', '--', '--', '---', '-', '--']
+ expected = ['-', '--', '<snip>', '-' '--']
+ self.assertEqual(
+ expected, util.snip_output_lines(lines, max_bytes=6))
+
+ def testSnipWithLines(self):
+ lines = ['----', '----', '----']
+ expected = ['--- ...', '<snip>', '... ---']
+ self.assertEqual(
+ expected, util.snip_output_lines(lines, max_bytes=6))
+
+ def testExactlyEqual(self):
+ lines = ['---', '---']
+ expected = ['---', '---']
+ self.assertEqual(
+ expected, util.snip_output_lines(lines, max_bytes=6))
+
+
if __name__ == '__main__':
unittest.main()
« no previous file with comments | « no previous file | recipe_engine/util.py » ('j') | recipe_modules/json/api.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698