| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2015 The LUCI Authors. All rights reserved. | 2 # Copyright 2015 The LUCI Authors. All rights reserved. |
| 3 # Use of this source code is governed under the Apache License, Version 2.0 | 3 # Use of this source code is governed under the Apache License, Version 2.0 |
| 4 # that can be found in the LICENSE file. | 4 # that can be found in the LICENSE file. |
| 5 | 5 |
| 6 import unittest | 6 import unittest |
| 7 | 7 |
| 8 import test_env | 8 import test_env |
| 9 | 9 |
| 10 from recipe_engine import util | 10 from recipe_engine import util |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 self.assertEqual(v, [1, 2, 3]) | 80 self.assertEqual(v, [1, 2, 3]) |
| 81 self.assertIsNotNone(mexc) | 81 self.assertIsNotNone(mexc) |
| 82 self.assertEqual(len(mexc), 5) | 82 self.assertEqual(len(mexc), 5) |
| 83 | 83 |
| 84 def testCatchesSpecificExceptions(self): | 84 def testCatchesSpecificExceptions(self): |
| 85 def fn(e): | 85 def fn(e): |
| 86 raise ValueError('Zero') | 86 raise ValueError('Zero') |
| 87 self.assertRaises(ValueError, util.map_defer_exceptions, fn, [1], KeyError) | 87 self.assertRaises(ValueError, util.map_defer_exceptions, fn, [1], KeyError) |
| 88 | 88 |
| 89 | 89 |
| 90 class TestSnipOutputLines(unittest.TestCase): |
| 91 |
| 92 def testIdempotentOnSmallData(self): |
| 93 small_data = [ |
| 94 [''], |
| 95 ['', ''], |
| 96 [' '], |
| 97 [' ', ' '], |
| 98 ['hello world'], |
| 99 ['hello world', ''], |
| 100 ['hello', 'world'], |
| 101 ['', 'hello world'], |
| 102 ] |
| 103 |
| 104 for d in small_data: |
| 105 self.assertEqual(d, util.snip_output_lines(d, max_bytes=100)) |
| 106 |
| 107 def testSnipWithNoLines(self): |
| 108 lines = ['---------'] |
| 109 expected = ['--- ...', '<snip>', '... ---'] |
| 110 self.assertEqual( |
| 111 expected, util.snip_output_lines(lines, max_bytes=6)) |
| 112 |
| 113 def testSnipWithLines(self): |
| 114 lines = ['-', '--', '--', '---', '-', '--'] |
| 115 expected = ['-', '--', '<snip>', '-' '--'] |
| 116 self.assertEqual( |
| 117 expected, util.snip_output_lines(lines, max_bytes=6)) |
| 118 |
| 119 def testSnipWithLines(self): |
| 120 lines = ['----', '----', '----'] |
| 121 expected = ['--- ...', '<snip>', '... ---'] |
| 122 self.assertEqual( |
| 123 expected, util.snip_output_lines(lines, max_bytes=6)) |
| 124 |
| 125 def testExactlyEqual(self): |
| 126 lines = ['---', '---'] |
| 127 expected = ['---', '---'] |
| 128 self.assertEqual( |
| 129 expected, util.snip_output_lines(lines, max_bytes=6)) |
| 130 |
| 131 |
| 90 if __name__ == '__main__': | 132 if __name__ == '__main__': |
| 91 unittest.main() | 133 unittest.main() |
| OLD | NEW |