| 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 cStringIO | 6 import cStringIO |
| 7 import os | 7 import os |
| 8 import sys | 8 import sys |
| 9 import unittest | 9 import unittest |
| 10 | 10 |
| 11 import test_env | 11 import test_env |
| 12 | 12 |
| 13 from recipe_engine import recipe_api |
| 13 from recipe_engine import stream | 14 from recipe_engine import stream |
| 14 | 15 |
| 15 class StreamTest(unittest.TestCase): | 16 class StreamTest(unittest.TestCase): |
| 16 def _example(self, engine): | 17 def _example(self, engine): |
| 17 foo = engine.new_step_stream('foo') | 18 foo = engine.make_step_stream('foo') |
| 18 foo.write_line('foo says hello to xyrself') | 19 foo.write_line('foo says hello to xyrself') |
| 19 | 20 |
| 20 bar = engine.new_step_stream('bar') | 21 bar = engine.make_step_stream('bar') |
| 21 foo.write_split('foo says hello to bar:\n hi bar') | 22 foo.write_split('foo says hello to bar:\n hi bar') |
| 22 bar.write_line('bar says hi, shyly') | 23 bar.write_line('bar says hi, shyly') |
| 23 | 24 |
| 24 foo.write_line('foo begins to read a poem') | 25 foo.write_line('foo begins to read a poem') |
| 25 with foo.new_log_stream('poem/proposition') as poem: | 26 with foo.new_log_stream('poem/proposition') as poem: |
| 26 poem.write_line('bar, thoust art soest beautiful') | 27 poem.write_line('bar, thoust art soest beautiful') |
| 27 bar.add_step_text('*blushing*') | 28 bar.add_step_text('*blushing*') |
| 28 poem.write_line('thoust makest mine heartst goest thumpitypump..est') | 29 poem.write_line('thoust makest mine heartst goest thumpitypump..est') |
| 29 | 30 |
| 30 foo.add_step_link('read it online!', 'https://foospoemtobar.com/') | 31 foo.add_step_link('read it online!', 'https://foospoemtobar.com/') |
| 31 foo.add_step_summary_text('read a killer poem and took a bow') | 32 foo.add_step_summary_text('read a killer poem and took a bow') |
| 32 foo.trigger('{"builderName":["bar\'s fantasies"]}') | 33 foo.trigger('{"builderName":["bar\'s fantasies"]}') |
| 33 foo.close() | 34 foo.close() |
| 34 | 35 |
| 35 # TODO(luqui): N.B. stream interleaving is not really possible with | 36 # TODO(luqui): N.B. stream interleaving is not really possible with |
| 36 # subannotations, since the subannotator stream could have changed the | 37 # subannotations, since the subannotator stream could have changed the |
| 37 # active step. To do this right we would need to parse and re-emit | 38 # active step. To do this right we would need to parse and re-emit |
| 38 # subannotations. | 39 # subannotations. |
| 39 bars_baby = engine.new_step_stream( | 40 bars_baby = engine.make_step_stream( |
| 40 'bar\'s baby', | 41 'bar\'s baby', |
| 41 allow_subannotations=True, | 42 allow_subannotations=True, |
| 42 nest_level=1) | 43 step_nest_level=1) |
| 43 bars_baby.write_line('I\'m in bar\'s imagination!!') | 44 bars_baby.write_line('I\'m in bar\'s imagination!!') |
| 44 bars_baby.write_line('@@@STEP_WARNINGS@@@') | 45 bars_baby.write_line('@@@STEP_WARNINGS@@@') |
| 45 bars_baby.reset_subannotation_state() | 46 bars_baby.reset_subannotation_state() |
| 46 bars_baby.close() | 47 bars_baby.close() |
| 47 | 48 |
| 48 bar.set_build_property('is_babycrazy', 'true') | 49 bar.set_build_property('is_babycrazy', 'true') |
| 49 bar.write_line('bar tries to kiss foo, but foo already left') | 50 bar.write_line('bar tries to kiss foo, but foo already left') |
| 50 bar.write_line('@@@KISS@foo@@@') | 51 bar.write_line('@@@KISS@foo@@@') |
| 51 bar.set_step_status('EXCEPTION') | 52 bar.set_step_status('EXCEPTION') |
| 52 bar.close() | 53 bar.close() |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 with engine: | 127 with engine: |
| 127 self._example(engine) | 128 self._example(engine) |
| 128 self.assertEqual(stringio.getvalue(), self._example_annotations()) | 129 self.assertEqual(stringio.getvalue(), self._example_annotations()) |
| 129 | 130 |
| 130 def test_noop(self): | 131 def test_noop(self): |
| 131 with stream.NoopStreamEngine() as engine: | 132 with stream.NoopStreamEngine() as engine: |
| 132 self._example(engine) | 133 self._example(engine) |
| 133 | 134 |
| 134 def test_write_after_close(self): | 135 def test_write_after_close(self): |
| 135 with stream.StreamEngineInvariants() as engine: | 136 with stream.StreamEngineInvariants() as engine: |
| 136 foo = engine.new_step_stream('foo') | 137 foo = engine.make_step_stream('foo') |
| 137 foo.close() | 138 foo.close() |
| 138 with self.assertRaises(AssertionError): | 139 with self.assertRaises(AssertionError): |
| 139 foo.write_line('no') | 140 foo.write_line('no') |
| 140 | 141 |
| 141 def test_log_still_open(self): | 142 def test_log_still_open(self): |
| 142 with stream.StreamEngineInvariants() as engine: | 143 with stream.StreamEngineInvariants() as engine: |
| 143 foo = engine.new_step_stream('foo') | 144 foo = engine.make_step_stream('foo') |
| 144 log = foo.new_log_stream('log') | 145 log = foo.new_log_stream('log') |
| 145 with self.assertRaises(AssertionError): | 146 with self.assertRaises(AssertionError): |
| 146 foo.close() | 147 foo.close() |
| 147 | 148 |
| 148 def test_no_write_multiple_lines(self): | 149 def test_no_write_multiple_lines(self): |
| 149 with stream.StreamEngineInvariants() as engine: | 150 with stream.StreamEngineInvariants() as engine: |
| 150 foo = engine.new_step_stream('foo') | 151 foo = engine.make_step_stream('foo') |
| 151 with self.assertRaises(AssertionError): | 152 with self.assertRaises(AssertionError): |
| 152 foo.write_line('one thing\nand another!') | 153 foo.write_line('one thing\nand another!') |
| 153 | 154 |
| 154 def test_invalid_status(self): | 155 def test_invalid_status(self): |
| 155 with stream.StreamEngineInvariants() as engine: | 156 with stream.StreamEngineInvariants() as engine: |
| 156 foo = engine.new_step_stream('foo') | 157 foo = engine.make_step_stream('foo') |
| 157 with self.assertRaises(AssertionError): | 158 with self.assertRaises(AssertionError): |
| 158 foo.set_step_status('SINGLE') | 159 foo.set_step_status('SINGLE') |
| 159 | 160 |
| 160 def test_buildbot_status_constraint(self): | 161 def test_buildbot_status_constraint(self): |
| 161 with stream.StreamEngineInvariants() as engine: | 162 with stream.StreamEngineInvariants() as engine: |
| 162 foo = engine.new_step_stream('foo') | 163 foo = engine.make_step_stream('foo') |
| 163 foo.set_step_status('FAILURE') | 164 foo.set_step_status('FAILURE') |
| 164 with self.assertRaises(AssertionError): | 165 with self.assertRaises(AssertionError): |
| 165 foo.set_step_status('SUCCESS') | 166 foo.set_step_status('SUCCESS') |
| 166 | 167 |
| 167 if __name__ == '__main__': | 168 if __name__ == '__main__': |
| 168 unittest.main() | 169 unittest.main() |
| OLD | NEW |