def test_cancel(self): m = ConsoleMonitor() with fetch_std_streams(): m.start('task A', total_work=10) self.assertFalse(m.is_cancelled()) m.cancel() self.assertTrue(m.is_cancelled())
def _test_main(self, args, expected_exit_code=0, expected_stdout=None, expected_stderr=None): with fetch_std_streams() as (stdout, stderr): exit_code = main.main(args=args, workspace_manager=self.manager, processor_factory=processor_factory) self.assertEqual(exit_code, expected_exit_code) self._test_iobuf('stdout', stdout, expected_stdout) self._test_iobuf('stderr', stderr, expected_stderr)
def test_console_monitor(self): m = ConsoleMonitor() with fetch_std_streams() as (stdout, stderr): m.start('task A', total_work=10) m.progress(work=1) m.progress(work=5, msg='phase 1') m.progress(msg='phase 2') m.progress(work=4) m.progress() m.done() actual_stdout = stdout.getvalue() expected_stdout = 'task A: started\n' + \ 'task A: 10%\n' + \ 'task A: 60% phase 1\n' + \ 'task A: phase 2\n' + \ 'task A: 100%\n' + \ 'task A: progress\n' + \ 'task A: done\n' self.assertEqual(actual_stdout, expected_stdout) self.assertEqual(stderr.getvalue(), '') self.assertTrue(True)
def _test_main(self, args, expected_exit_code=0, expected_stdout=None, expected_stderr=None): with fetch_std_streams() as (stdout, stderr): exit_code = cli.main(args=args, workspace_manager=self.manager, processor_factory=processor_factory) self.assertEqual(exit_code, expected_exit_code) self._test_iobuf('stdout', stdout, expected_stdout) self._test_iobuf('stderr', stderr, expected_stderr)
def test_label_req(self): monitor = ConsoleMonitor() with fetch_std_streams(): with self.assertRaises(ValueError): # "ValueError: label must be given" monitor.start('', total_work=10)