def test_runcmd(self, mock_call): mock_call.return_value = 0 args = MagicMock() args.longer_than = 0 args.command = ['true'] self.assertEqual('"true" succeeded in 0:00 minutes', run_cmd(args))
def test_longerthan(self, mock_Popen): mock_Popen.return_value = process_mock() args = MagicMock() args.longer_than = 1 args.command = ['true'] args.pid = None args.unfocused_only = False self.assertEqual((None, None), run_cmd(args))
def test_longerthan(self, mock_call): mock_call.return_value = 0 args = MagicMock() args.longer_than = 1 args.command = ['true'] args.pid = None args.unfocused_only = False self.assertEqual(None, run_cmd(args))
def test_default(self, mock_call): mock_call.return_value = 0 args = MagicMock() args.longer_than = -1 args.command = ['true'] args.pid = None args.unfocused_only = False self.assertEqual('"true" succeeded in 0:00 minutes', run_cmd(args))
def test_failure(self, mock_Popen): mock_Popen.return_value = process_mock(42) args = MagicMock() args.longer_than = -1 args.command = ['false'] args.pid = None args.unfocused_only = False self.assertEqual(('"false" failed (code 42) in 0:00 minutes', 42), run_cmd(args))
def test_watch_pid(self, mock_process): mock_process.return_value.pid = 1 mock_process.return_value.create_time.return_value = time() mock_process.return_value.cmdline.return_value = ['cmd'] args = MagicMock() args.pid = 1 args.unfocused_only = False self.assertEqual('PID[1]: "cmd" finished in 0:00 minutes', run_cmd(args)[0])
def test_formatter_failure(self): args = MagicMock() args.pid = None args.command = None args.formatter = ("false", 1, 10) args.longer_than = -1 args.unfocused_only = False self.assertEqual(('"false" failed (code 1) in 0:10 minutes', 1), run_cmd(args))
def test_formatter(self): args = MagicMock() args.pid = None args.command = None args.formatter = ("true", 0, 65) args.longer_than = -1 args.unfocused_only = False self.assertEqual(('"true" succeeded in 1:05 minutes', 0), run_cmd(args))
def test_watch_pid(self, mock_process): mock_process.return_value.pid = 1 mock_process.return_value.create_time.return_value = time() mock_process.return_value.cmdline.return_value = ['cmd'] args = MagicMock() args.pid = 1 args.unfocused_only = False self.assertEqual('PID[1]: "cmd" finished in 0:00 minutes', run_cmd(args))
def test_default(self, mock_Popen): mock_Popen.return_value = process_mock() args = MagicMock() args.longer_than = -1 args.command = ['true'] args.pid = None args.unfocused_only = False args.hide_command = False self.assertEqual(('"true" succeeded in 0:00 minutes', 0), run_cmd(args))
def test_emoji(self, mock_call): mock_call.return_value = 0 args = MagicMock() args.longer_than = -1 args.command = ['true'] args.pid = None args.no_emoji = False args.unfocused_only = False self.assertEqual((':white_check_mark: "true" succeeded in 0:00 minutes', 0), run_cmd(args))
def test_stderr(self, mock_Popen): mock_Popen.return_value = process_mock(stderr='error') args = MagicMock() args.longer_than = -1 args.command = ['true'] args.pid = None args.unfocused_only = False # not actually used args.stdout = False args.stderr = True self.assertEqual(('"true" succeeded in 0:00 minutes:\nerror', 0), run_cmd(args))
def test_failure_stdout_and_stderr(self, mock_Popen): mock_Popen.return_value = process_mock(1, stdout='output', stderr='error') args = MagicMock() args.longer_than = -1 args.command = ['true'] args.pid = None args.unfocused_only = False # not actually used args.stdout = True args.stderr = True self.assertEqual( ('"true" failed (code 1) in 0:00 minutes:\noutputerror', 1), run_cmd(args))