def test_run_with_timeout_kills_on_terminate_timeout(self, mock_popen): mock_popen.return_value = make_mock_popen(communicate_raise=True, terminate_raise=True) with self.assertRaises(DcRPMException): run_with_timeout("/bin/true", 5) mock_popen.return_value.terminate.assert_called() mock_popen.return_value.kill.assert_called()
def test_run_with_timeout_raise_on_nonzero(self): # type: () -> None (self.mock_callable(subprocess, "Popen").for_call( ["/bin/true"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True, ).to_return_value( make_mock_popen(returncode=1)).and_assert_called_once()) with self.assertRaises(DcRPMException): run_with_timeout(["/bin/true"], 5)
def test_run_with_timeout_timeout(self): # type: () -> None mock_popen = make_mock_popen(communicate_raise=True) (self.mock_callable(subprocess, "Popen").for_call( ["/bin/true"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True, ).to_return_value(mock_popen).and_assert_called_once()) with self.assertRaises(DcRPMException): run_with_timeout(["/bin/true"], 5) mock_popen.kill.assert_not_called()
def test_run_with_timeout_no_raise_on_timeout(self, mock_popen): mock_popen.return_value = make_mock_popen(returncode=1, communicate_raise=True) result = run_with_timeout("/bin/true", 5, raise_on_timeout=False) self.assertNotEqual(result.returncode, 1) self.assertEqual(result.stdout, None) self.assertEqual(result.stderr, None)
def test_run_with_timeout_success(self, mock_popen): result = run_with_timeout('/bin/true', 5) self.assertEqual(result.returncode, 0) mock_popen.assert_called_once_with( '/bin/true', shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, )
def test_run_with_timeout_success(self, mock_popen): result = run_with_timeout("/bin/true", 5) self.assertEqual(result.returncode, 0) mock_popen.assert_called_once_with( "/bin/true", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True, )
def test_run_with_timeout_success(self): # type: () -> None (self.mock_callable(subprocess, "Popen").for_call( ["/bin/true"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True, ).to_return_value(make_mock_popen()).and_assert_called_once()) result = run_with_timeout(["/bin/true"], 5) self.assertEqual(result.returncode, 0)
def test_run_with_timeout_no_raise_on_nonzero(self): # type: () -> None (self.mock_constructor(subprocess, "Popen").for_call( ["/bin/true"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True, ).to_return_value( make_mock_popen(returncode=1)).and_assert_called_once()) result = run_with_timeout(["/bin/true"], 5, raise_on_nonzero=False) self.assertEqual(result.returncode, 1)
def test_run_with_timeout_no_raise_on_timeout(self): # type: () -> None mock_popen = make_mock_popen(returncode=1, communicate_raise=True) (self.mock_callable(subprocess, "Popen").for_call( ["/bin/true"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True, ).to_return_value(mock_popen).and_assert_called_once()) result = run_with_timeout(["/bin/true"], 5, raise_on_timeout=False) self.assertNotEqual(result.returncode, 1) self.assertEqual(result.stdout, "") self.assertEqual(result.stderr, "")
def test_run_with_timeout_no_raise_on_nonzero(self, mock_popen): result = run_with_timeout("/bin/true", 5, raise_on_nonzero=False) self.assertEqual(result.returncode, 1)
def test_run_with_timeout_raise_on_nonzero(self, mock_popen): with self.assertRaises(DcRPMException): run_with_timeout("/bin/true", 5)
def test_run_with_timeout_timeout(self, mock_popen): mock_popen.return_value = make_mock_popen(communicate_raise=True) with self.assertRaises(DcRPMException): run_with_timeout('/bin/true', 5) mock_popen.return_value.kill.assert_not_called()
def test_run_with_timeout_timeout(self, mock_popen, mock_call): with self.assertRaises(DcRPMException): run_with_timeout('/bin/true', 5)