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

Side by Side Diff: recipe_engine/unittests/stream_logdog_test.py

Issue 2934583003: [step] Remove config indirection. (Closed)
Patch Set: comments Created 3 years, 6 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 unified diff | Download patch
« no previous file with comments | « recipe_engine/stream.py ('k') | recipe_engine/unittests/stream_test.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 collections 6 import collections
7 import contextlib 7 import contextlib
8 import datetime 8 import datetime
9 import json 9 import json
10 import os 10 import os
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 yield se 254 yield se
255 255
256 # Close the StreamEngine after we're done with it. 256 # Close the StreamEngine after we're done with it.
257 self._advance_time() 257 self._advance_time()
258 se.close() 258 se.close()
259 259
260 @contextlib.contextmanager 260 @contextlib.contextmanager
261 def _step_stream(self, se, **kwargs): 261 def _step_stream(self, se, **kwargs):
262 # Initialize and yield a new step stream. 262 # Initialize and yield a new step stream.
263 self._advance_time() 263 self._advance_time()
264 step_stream = se.new_step_stream(recipe_api.StepConfig.create(**kwargs)) 264 step_stream = se.new_step_stream(recipe_api.StepClient.StepConfig(**kwargs))
265 yield step_stream 265 yield step_stream
266 266
267 # Close the step stream when we're done with it. 267 # Close the step stream when we're done with it.
268 self._advance_time() 268 self._advance_time()
269 step_stream.close() 269 step_stream.close()
270 270
271 @contextlib.contextmanager 271 @contextlib.contextmanager
272 def _log_stream(self, step_stream, name): 272 def _log_stream(self, step_stream, name):
273 # Initialize and yield a new log stream. 273 # Initialize and yield a new log stream.
274 log_stream = step_stream.new_log_stream(name) 274 log_stream = step_stream.new_log_stream(name)
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 655
656 def testNestedStream(self): 656 def testNestedStream(self):
657 with self._new_stream_engine() as se: 657 with self._new_stream_engine() as se:
658 # parent 658 # parent
659 with self._step_stream(se, name='parent') as step: 659 with self._step_stream(se, name='parent') as step:
660 step.write_line('I am the parent.') 660 step.write_line('I am the parent.')
661 661
662 # parent."child 1" 662 # parent."child 1"
663 with self._step_stream(se, 663 with self._step_stream(se,
664 name='child 1', 664 name='child 1',
665 step_nest_level=1) as step: 665 nest_level=1) as step:
666 step.write_line('I am child #1.') 666 step.write_line('I am child #1.')
667 667
668 # parent."child 1"."grandchild" 668 # parent."child 1"."grandchild"
669 with self._step_stream(se, 669 with self._step_stream(se,
670 name='grandchild', 670 name='grandchild',
671 step_nest_level=2) as step: 671 nest_level=2) as step:
672 step.write_line("I am child #1's child.") 672 step.write_line("I am child #1's child.")
673 673
674 # parent."child 2". Mark this child as failed. This should not propagate 674 # parent."child 2". Mark this child as failed. This should not propagate
675 # to the parent, since it has an explicit status. 675 # to the parent, since it has an explicit status.
676 with self._step_stream(se, 676 with self._step_stream(se,
677 name='child 2', 677 name='child 2',
678 step_nest_level=1) as step: 678 nest_level=1) as step:
679 step.write_line('I am child #2.') 679 step.write_line('I am child #2.')
680 680
681 # parent."child 2". Mark this child as failed. This should not propagate 681 # parent."child 2". Mark this child as failed. This should not propagate
682 # to the parent, since it has an explicit status. 682 # to the parent, since it has an explicit status.
683 with self._step_stream(se, name='friend') as step: 683 with self._step_stream(se, name='friend') as step:
684 step.write_line("I am the parent's friend.") 684 step.write_line("I am the parent's friend.")
685 685
686 self.assertEqual(self.client.all_streams(), { 686 self.assertEqual(self.client.all_streams(), {
687 u'annotations': { 687 u'annotations': {
688 u'name': u'steps', 688 u'name': u'steps',
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
763 step.trigger('trigger spec') 763 step.trigger('trigger spec')
764 764
765 def testTriggersIgnored(self): 765 def testTriggersIgnored(self):
766 with self._new_stream_engine(ignore_triggers=True) as se: 766 with self._new_stream_engine(ignore_triggers=True) as se:
767 with self._step_stream(se, name='trigger') as step: 767 with self._step_stream(se, name='trigger') as step:
768 step.trigger('trigger spec') 768 step.trigger('trigger spec')
769 769
770 def testNoSubannotations(self): 770 def testNoSubannotations(self):
771 with self._new_stream_engine(ignore_triggers=True) as se: 771 with self._new_stream_engine(ignore_triggers=True) as se:
772 with self.assertRaises(NotImplementedError): 772 with self.assertRaises(NotImplementedError):
773 se.new_step_stream(recipe_api.StepConfig.create( 773 se.new_step_stream(recipe_api.StepClient.StepConfig(
774 name='uses subannotations', 774 name='uses subannotations',
775 allow_subannotations=True, 775 allow_subannotations=True,
776 )) 776 ))
777 777
778 def testInvalidStepStatusRaisesValueError(self): 778 def testInvalidStepStatusRaisesValueError(self):
779 with self._new_stream_engine() as se: 779 with self._new_stream_engine() as se:
780 with self._step_stream(se, name='trigger') as step: 780 with self._step_stream(se, name='trigger') as step:
781 with self.assertRaises(ValueError): 781 with self.assertRaises(ValueError):
782 step.set_step_status('OHAI') 782 step.set_step_status('OHAI')
783 783
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
956 956
957 def testFirstCheckReturnsData(self): 957 def testFirstCheckReturnsData(self):
958 # The first check should return data. 958 # The first check should return data.
959 self.assertIsNotNone(self.astate.check()) 959 self.assertIsNotNone(self.astate.check())
960 # The second will, since nothing has changed. 960 # The second will, since nothing has changed.
961 self.assertIsNone(self.astate.check()) 961 self.assertIsNone(self.astate.check())
962 962
963 def testCanCreateAndGetStep(self): 963 def testCanCreateAndGetStep(self):
964 # Root step. 964 # Root step.
965 base = self.astate.base 965 base = self.astate.base
966 self.astate.create_step(recipe_api.StepConfig.create(name='first')) 966 self.astate.create_step(recipe_api.StepClient.StepConfig(name='first'))
967 self.assertEqual(len(base.substep), 1) 967 self.assertEqual(len(base.substep), 1)
968 self.assertEqual(base.substep[0].step.name, 'first') 968 self.assertEqual(base.substep[0].step.name, 'first')
969 self.assertIsNotNone(self.astate.check()) 969 self.assertIsNotNone(self.astate.check())
970 970
971 # Child step. 971 # Child step.
972 self.astate.create_step(recipe_api.StepConfig.create( 972 self.astate.create_step(recipe_api.StepClient.StepConfig(
973 name='first child', 973 name='first child',
974 step_nest_level=1)) 974 nest_level=1))
975 self.assertEqual(len(base.substep), 1) 975 self.assertEqual(len(base.substep), 1)
976 self.assertEqual(len(base.substep[0].step.substep), 1) 976 self.assertEqual(len(base.substep[0].step.substep), 1)
977 self.assertEqual(base.substep[0].step.substep[0].step.name, 'first child') 977 self.assertEqual(base.substep[0].step.substep[0].step.name, 'first child')
978 self.assertIsNotNone(self.astate.check()) 978 self.assertIsNotNone(self.astate.check())
979 979
980 # Sibling step to 'first'. 980 # Sibling step to 'first'.
981 self.astate.create_step(recipe_api.StepConfig.create(name='second')) 981 self.astate.create_step(recipe_api.StepClient.StepConfig(name='second'))
982 self.assertEqual(len(base.substep), 2) 982 self.assertEqual(len(base.substep), 2)
983 self.assertEqual(base.substep[1].step.name, 'second') 983 self.assertEqual(base.substep[1].step.name, 'second')
984 self.assertIsNotNone(self.astate.check()) 984 self.assertIsNotNone(self.astate.check())
985 985
986 def testCanUpdateProperties(self): 986 def testCanUpdateProperties(self):
987 self.astate.update_properties(foo='baz', qux='quux') 987 self.astate.update_properties(foo='baz', qux='quux')
988 self.assertEqual(list(self.astate.base.property), [ 988 self.assertEqual(list(self.astate.base.property), [
989 pb.Step.Property(name='foo', value='baz'), 989 pb.Step.Property(name='foo', value='baz'),
990 pb.Step.Property(name='qux', value='quux'), 990 pb.Step.Property(name='qux', value='quux'),
991 ]) 991 ])
(...skipping 29 matching lines...) Expand all
1021 sn = sn.append('#!!! stream name !!!') 1021 sn = sn.append('#!!! stream name !!!')
1022 self.assertEqual(str(sn), 'base/s______stream_name____') 1022 self.assertEqual(str(sn), 'base/s______stream_name____')
1023 1023
1024 def testAugmentInvalidStreamNameNormalizes(self): 1024 def testAugmentInvalidStreamNameNormalizes(self):
1025 sn = stream_logdog._StreamName('base') 1025 sn = stream_logdog._StreamName('base')
1026 self.assertEqual(str(sn.augment(' !!! other !!! ')), 'base_____other_____') 1026 self.assertEqual(str(sn.augment(' !!! other !!! ')), 'base_____other_____')
1027 1027
1028 1028
1029 if __name__ == '__main__': 1029 if __name__ == '__main__':
1030 unittest.main() 1030 unittest.main()
OLDNEW
« no previous file with comments | « recipe_engine/stream.py ('k') | recipe_engine/unittests/stream_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698