示例#1
0
 def test_CondExecEnv1(self):
     import cStringIO
     test_stream = cStringIO.StringIO()
     logger = StreamLogger(level=DEBUG, stream=test_stream)
     exp_cfg = {
         'logger': Logger(),
     }
     env_cfg = {'logger': logger}
     env = LoggedExecutionEnvironment(exp_cfg, env_cfg)
     env.addCallable(TestEnv._b1,
                     action_kwargs=None,
                     action_input=None,
                     action_output=('source1', ))
     env.addCallable(TestEnv._b2,
                     action_kwargs=None,
                     action_input=None,
                     action_output=('source2', ))
     env.addCallable(TestEnv._b3,
                     action_kwargs=None,
                     action_input=('source1', 'source2'),
                     action_output=('product', ))
     env.execute()
     self.assertIn('product', env.varkeys())
     self.assertEqual('val1__val2', env.var('product'))
     nls = count_lines(test_stream)
     self.assertEqual(nls, 5)
示例#2
0
 def test_StreamLogger1(self):
     import cStringIO
     test_stream = cStringIO.StringIO()
     logger = StreamLogger(level=DEBUG, stream=test_stream)
     for l in self.loglines2:
         logger.info(l)
     ref_lines = test_stream.getvalue().splitlines()
     self.assertEqual(2, len(ref_lines))
     ref_lines_len = [len(l) for l in ref_lines]
     self.assertEqual(1, len(set(ref_lines_len)))
     ref_lines_msg = [
         l.endswith(m) for l, m in zip(ref_lines, self.loglines2)
     ]
     self.assertTrue(all(ref_lines_msg))
示例#3
0
 def test_LoggedExecEnv1(self):
     import cStringIO
     test_stream = cStringIO.StringIO()
     logger = StreamLogger(level=DEBUG, stream=test_stream)
     exp_cfg = {
         'logger': Logger(),
     }
     env_cfg = {'logger': logger}
     env = LoggedExecutionEnvironment(exp_cfg, env_cfg)
     env.addCallable(TestEnv._a2, {'a': 'a', 'b': 'b', 'c': 'c', 'd': -1})
     env.addCallable(TestEnv._a3)
     env.execute()
     nls = count_lines(test_stream)
     self.assertEqual(nls, 4)
示例#4
0
 def test_postActionCb2(self):
     import cStringIO
     test_stream = cStringIO.StringIO()
     logger = StreamLogger(level=DEBUG, stream=test_stream)
     exp_cfg = {
         'logger': Logger(),
     }
     env_cfg = {'logger': logger}
     env = LoggedExecutionEnvironment(exp_cfg, env_cfg)
     env.addCallable(TestEnv._a2, {'a': 'a', 'b': 'b', 'c': 'c', 'd': -1})
     env.addCallable(TestEnv._a3)
     # add custom post action callback
     env.postActionCallback = TestEnv._postActionCb2
     # and execute
     env.execute()
     nls = count_lines(test_stream)
     self.assertEqual(nls, 15)
示例#5
0
 def test_CondExecEnv2(self):
     import cStringIO
     test_stream = cStringIO.StringIO()
     logger = StreamLogger(level=DEBUG, stream=test_stream)
     exp_cfg = {
         'logger': Logger(),
     }
     env_cfg = {'logger': logger}
     env = LoggedExecutionEnvironment(exp_cfg, env_cfg)
     env.addCallable(TestEnv._b1,
                     action_kwargs=None,
                     action_input=None,
                     action_output=('source1', ))
     env.addCallable(TestEnv._b2,
                     action_kwargs=None,
                     action_input=None,
                     action_output=('source2', ))
     env.addCallable(TestEnv._b3,
                     action_kwargs=None,
                     action_input=('source1', 'source2'),
                     action_output=('some_strange_var', ))
     with self.assertRaises(ValueError):
         env.execute()