def test_22_stdout_output(self): """Use stdout output decorator with default options.""" wrapper_f = decor.stdout_output()(_func11) stdout = log.capture_output(wrapper_f) self.assertEqual(stdout, '123\n') stdout = log.capture_output(wrapper_f, args=(10, '20'), kwargs={'a': 30}) self.assertEqual(stdout, '123\n')
def test_20_stdout_input(self): """Use stdout input decorator with default options.""" wrapper_f = decor.stdout_input()(_func10) stdout = log.capture_output(wrapper_f) # \n is added by print statement. self.assertEqual(stdout, '_func10()\n') stdout = log.capture_output(wrapper_f, args=(10, '20'), kwargs={'a': 30}) # \n is added by print statement. self.assertEqual(stdout, "_func10(10, '20', a=30)\n")
def test_06_time_it(self): """Run decorator and capture its print output.""" d = decor.time_it(uom='h')(_dummy) res = log.capture_output(d) self.assertEqual(res, "'_dummy' took 0.00 hour(s)\n") d = decor.time_it( uom='h', msg_fmt="'{_f_name}' took {_dur:.2f} {_uom_name} {arg1} {c}")( _dummy2) res = log.capture_output(d, args=(0, 1), kwargs={'c': 2}) self.assertEqual(res, "'_dummy2' took 0.00 hour(s) 1 2\n")
def test_23_stdout_output(self): """Use stdout output decorator with custom options.""" wrapper_f = decor.stdout_output(options={ 'stdout_writer': print, 'prefix': 'custom ', })(_func11) stdout = log.capture_output(wrapper_f) self.assertEqual(stdout, 'custom 123\n') wrapper_f = decor.stdout_output( options={ 'stdout_getter': lambda *args, **kwargs: print, })(_func11) stdout = log.capture_output(wrapper_f, args=(10, '20'), kwargs={'a': 30}) self.assertEqual(stdout, "123\n")
def test_02_command(self): """Execute commands in lifo order.""" invoker = self.DequeInvoker() invoker.add_command(self.mc1) invoker.add_command(self.mc2) invoker.add_command(self.mc3) res = log.capture_output(invoker.run, kwargs={'priority': 'lifo'}) self.assertEqual(res, 'cba')
def test_01_command(self): """Execute commands in fifo order.""" invoker = self.DequeInvoker() invoker.add_command(self.mc1) invoker.add_command(self.mc2) invoker.add_command(self.mc3) res = log.capture_output(invoker.run) self.assertEqual(res, 'abc')
def test_21_stdout_input(self): """Use stdout input decorator with custom options.""" wrapper_f = decor.stdout_input(options={ 'stdout_writer': print, 'no_first_arg': True, 'prefix': 'custom ', })(_func10) stdout = log.capture_output(wrapper_f) self.assertEqual(stdout, 'custom _func10()\n') wrapper_f = decor.stdout_input( options={ 'stdout_getter': lambda *args, **kwargs: print, 'command': True })(_func10) stdout = log.capture_output(wrapper_f, args=(10, '20'), kwargs={'a': 30}) self.assertEqual(stdout, "_func10 10 20 a=30\n")
def test_capture_output_1(self): """Capture output from print.""" res = log.capture_output(print, args=('test', )) self.assertEqual(res, 'test\n')