예제 #1
0
 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()
예제 #2
0
 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)
예제 #3
0
 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()
예제 #4
0
 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)
예제 #5
0
 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,
     )
예제 #6
0
 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,
     )
예제 #7
0
 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)
예제 #8
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)
예제 #9
0
 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, "")
예제 #10
0
 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)
예제 #11
0
 def test_run_with_timeout_raise_on_nonzero(self, mock_popen):
     with self.assertRaises(DcRPMException):
         run_with_timeout("/bin/true", 5)
예제 #12
0
 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()
예제 #13
0
 def test_run_with_timeout_timeout(self, mock_popen, mock_call):
     with self.assertRaises(DcRPMException):
         run_with_timeout('/bin/true', 5)