| 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 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 bars_baby.reset_subannotation_state() | 44 bars_baby.reset_subannotation_state() |
| 45 bars_baby.close() | 45 bars_baby.close() |
| 46 | 46 |
| 47 bar.set_build_property('is_babycrazy', 'true') | 47 bar.set_build_property('is_babycrazy', 'true') |
| 48 bar.write_line('bar tries to kiss foo, but foo already left') | 48 bar.write_line('bar tries to kiss foo, but foo already left') |
| 49 bar.write_line('@@@KISS@foo@@@') | 49 bar.write_line('@@@KISS@foo@@@') |
| 50 bar.set_step_status('EXCEPTION') | 50 bar.set_step_status('EXCEPTION') |
| 51 bar.close() | 51 bar.close() |
| 52 | 52 |
| 53 def _example_annotations(self): | 53 def _example_annotations(self): |
| 54 return """@@@HONOR_ZERO_RETURN_CODE@@@ | 54 return """@@@CURRENT_TIMESTAMP@123@@@ |
| 55 @@@HONOR_ZERO_RETURN_CODE@@@ |
| 55 @@@SEED_STEP@foo@@@ | 56 @@@SEED_STEP@foo@@@ |
| 56 @@@STEP_CURSOR@foo@@@ | 57 @@@STEP_CURSOR@foo@@@ |
| 58 @@@CURRENT_TIMESTAMP@123@@@ |
| 57 @@@STEP_STARTED@@@ | 59 @@@STEP_STARTED@@@ |
| 58 foo says hello to xyrself | 60 foo says hello to xyrself |
| 59 @@@SEED_STEP@bar@@@ | 61 @@@SEED_STEP@bar@@@ |
| 60 foo says hello to bar: | 62 foo says hello to bar: |
| 61 hi bar | 63 hi bar |
| 62 @@@STEP_CURSOR@bar@@@ | 64 @@@STEP_CURSOR@bar@@@ |
| 65 @@@CURRENT_TIMESTAMP@123@@@ |
| 63 @@@STEP_STARTED@@@ | 66 @@@STEP_STARTED@@@ |
| 64 bar says hi, shyly | 67 bar says hi, shyly |
| 65 @@@STEP_CURSOR@foo@@@ | 68 @@@STEP_CURSOR@foo@@@ |
| 66 foo begins to read a poem | 69 foo begins to read a poem |
| 67 @@@STEP_LOG_LINE@poem/proposition@bar, thoust art soest beautiful@@@ | 70 @@@STEP_LOG_LINE@poem/proposition@bar, thoust art soest beautiful@@@ |
| 68 @@@STEP_CURSOR@bar@@@ | 71 @@@STEP_CURSOR@bar@@@ |
| 69 @@@STEP_TEXT@*blushing*@@@ | 72 @@@STEP_TEXT@*blushing*@@@ |
| 70 @@@STEP_CURSOR@foo@@@ | 73 @@@STEP_CURSOR@foo@@@ |
| 71 @@@STEP_LOG_LINE@poem/proposition@thoust makest mine heartst goest thumpity
pump..est@@@ | 74 @@@STEP_LOG_LINE@poem/proposition@thoust makest mine heartst goest thumpity
pump..est@@@ |
| 72 @@@STEP_LOG_END@poem/proposition@@@ | 75 @@@STEP_LOG_END@poem/proposition@@@ |
| 73 @@@STEP_LINK@read it online!@https://foospoemtobar.com/@@@ | 76 @@@STEP_LINK@read it online!@https://foospoemtobar.com/@@@ |
| 74 @@@STEP_SUMMARY_TEXT@read a killer poem and took a bow@@@ | 77 @@@STEP_SUMMARY_TEXT@read a killer poem and took a bow@@@ |
| 75 @@@STEP_TRIGGER@{"builderName":["bar's fantasies"]}@@@ | 78 @@@STEP_TRIGGER@{"builderName":["bar's fantasies"]}@@@ |
| 79 @@@CURRENT_TIMESTAMP@123@@@ |
| 76 @@@STEP_CLOSED@@@ | 80 @@@STEP_CLOSED@@@ |
| 77 @@@SEED_STEP@bar's baby@@@ | 81 @@@SEED_STEP@bar's baby@@@ |
| 78 @@@STEP_CURSOR@bar's baby@@@ | 82 @@@STEP_CURSOR@bar's baby@@@ |
| 83 @@@CURRENT_TIMESTAMP@123@@@ |
| 79 @@@STEP_STARTED@@@ | 84 @@@STEP_STARTED@@@ |
| 80 @@@STEP_NEST_LEVEL@1@@@ | 85 @@@STEP_NEST_LEVEL@1@@@ |
| 81 I'm in bar's imagination!! | 86 I'm in bar's imagination!! |
| 82 @@@STEP_WARNINGS@@@ | 87 @@@STEP_WARNINGS@@@ |
| 83 @@@STEP_CURSOR@bar's baby@@@ | 88 @@@STEP_CURSOR@bar's baby@@@ |
| 89 @@@CURRENT_TIMESTAMP@123@@@ |
| 84 @@@STEP_CLOSED@@@ | 90 @@@STEP_CLOSED@@@ |
| 85 @@@STEP_CURSOR@bar@@@ | 91 @@@STEP_CURSOR@bar@@@ |
| 86 @@@SET_BUILD_PROPERTY@is_babycrazy@true@@@ | 92 @@@SET_BUILD_PROPERTY@is_babycrazy@true@@@ |
| 87 bar tries to kiss foo, but foo already left | 93 bar tries to kiss foo, but foo already left |
| 88 !@@@KISS@foo@@@ | 94 !@@@KISS@foo@@@ |
| 89 @@@STEP_EXCEPTION@@@ | 95 @@@STEP_EXCEPTION@@@ |
| 96 @@@CURRENT_TIMESTAMP@123@@@ |
| 90 @@@STEP_CLOSED@@@ | 97 @@@STEP_CLOSED@@@ |
| 98 @@@CURRENT_TIMESTAMP@123@@@ |
| 91 """ | 99 """ |
| 92 | 100 |
| 101 def fake_time(self): |
| 102 return 123 |
| 103 |
| 93 def test_example(self): | 104 def test_example(self): |
| 94 stringio = cStringIO.StringIO() | 105 stringio = cStringIO.StringIO() |
| 95 engine = stream.AnnotatorStreamEngine(stringio) | 106 engine = stream.AnnotatorStreamEngine( |
| 96 self._example(engine) | 107 stringio, emit_timestamps=True, time_fn=self.fake_time) |
| 97 # Split lines for good diffs. | 108 with engine: |
| 109 self._example(engine) |
| 110 # Split lines for good diffs. |
| 98 self.assertEqual( | 111 self.assertEqual( |
| 99 stringio.getvalue().splitlines(), | 112 stringio.getvalue().splitlines(), |
| 100 self._example_annotations().splitlines()) | 113 self._example_annotations().splitlines()) |
| 101 | 114 |
| 102 def test_example_wellformed(self): | 115 def test_example_wellformed(self): |
| 103 self._example(stream.StreamEngineInvariants()) | 116 with stream.StreamEngineInvariants() as engine: |
| 117 self._example(engine) |
| 104 | 118 |
| 105 def test_product_with_invariants_on_example(self): | 119 def test_product_with_invariants_on_example(self): |
| 106 stringio = cStringIO.StringIO() | 120 stringio = cStringIO.StringIO() |
| 107 engine = stream.ProductStreamEngine( | 121 engine = stream.ProductStreamEngine( |
| 108 stream.StreamEngineInvariants(), | 122 stream.StreamEngineInvariants(), |
| 109 stream.AnnotatorStreamEngine(stringio)) | 123 stream.AnnotatorStreamEngine( |
| 110 self._example(engine) | 124 stringio, emit_timestamps=True, time_fn=self.fake_time)) |
| 125 with engine: |
| 126 self._example(engine) |
| 111 self.assertEqual(stringio.getvalue(), self._example_annotations()) | 127 self.assertEqual(stringio.getvalue(), self._example_annotations()) |
| 112 | 128 |
| 113 def test_noop(self): | 129 def test_noop(self): |
| 114 self._example(stream.NoopStreamEngine()) | 130 with stream.NoopStreamEngine() as engine: |
| 131 self._example(engine) |
| 115 | 132 |
| 116 def test_write_after_close(self): | 133 def test_write_after_close(self): |
| 117 engine = stream.StreamEngineInvariants() | 134 with stream.StreamEngineInvariants() as engine: |
| 118 foo = engine.new_step_stream('foo') | 135 foo = engine.new_step_stream('foo') |
| 119 foo.close() | 136 foo.close() |
| 120 with self.assertRaises(AssertionError): | 137 with self.assertRaises(AssertionError): |
| 121 foo.write_line('no') | 138 foo.write_line('no') |
| 122 | 139 |
| 123 def test_log_still_open(self): | 140 def test_log_still_open(self): |
| 124 engine = stream.StreamEngineInvariants() | 141 with stream.StreamEngineInvariants() as engine: |
| 125 foo = engine.new_step_stream('foo') | 142 foo = engine.new_step_stream('foo') |
| 126 log = foo.new_log_stream('log') | 143 log = foo.new_log_stream('log') |
| 127 with self.assertRaises(AssertionError): | 144 with self.assertRaises(AssertionError): |
| 128 foo.close() | 145 foo.close() |
| 129 | 146 |
| 130 def test_no_write_multiple_lines(self): | 147 def test_no_write_multiple_lines(self): |
| 131 engine = stream.StreamEngineInvariants() | 148 with stream.StreamEngineInvariants() as engine: |
| 132 foo = engine.new_step_stream('foo') | 149 foo = engine.new_step_stream('foo') |
| 133 with self.assertRaises(AssertionError): | 150 with self.assertRaises(AssertionError): |
| 134 foo.write_line('one thing\nand another!') | 151 foo.write_line('one thing\nand another!') |
| 135 | 152 |
| 136 def test_invalid_status(self): | 153 def test_invalid_status(self): |
| 137 engine = stream.StreamEngineInvariants() | 154 with stream.StreamEngineInvariants() as engine: |
| 138 foo = engine.new_step_stream('foo') | 155 foo = engine.new_step_stream('foo') |
| 139 with self.assertRaises(AssertionError): | 156 with self.assertRaises(AssertionError): |
| 140 foo.set_step_status('SINGLE') | 157 foo.set_step_status('SINGLE') |
| 141 | 158 |
| 142 def test_buildbot_status_constraint(self): | 159 def test_buildbot_status_constraint(self): |
| 143 engine = stream.StreamEngineInvariants() | 160 with stream.StreamEngineInvariants() as engine: |
| 144 foo = engine.new_step_stream('foo') | 161 foo = engine.new_step_stream('foo') |
| 145 foo.set_step_status('FAILURE') | 162 foo.set_step_status('FAILURE') |
| 146 with self.assertRaises(AssertionError): | 163 with self.assertRaises(AssertionError): |
| 147 foo.set_step_status('SUCCESS') | 164 foo.set_step_status('SUCCESS') |
| 148 | 165 |
| 149 if __name__ == '__main__': | 166 if __name__ == '__main__': |
| 150 unittest.main() | 167 unittest.main() |
| OLD | NEW |