| @@ 116-146 (lines=31) @@ | ||
| 113 | assert_equal(exit_status_100, 2) |
|
| 114 | assert_true(os.path.isdir(self.logs_dir)) |
|
| 115 | ||
| 116 | @patch('subprocess.check_output') |
|
| 117 | def test_launch_job_check(self, mock_check_output): |
|
| 118 | ||
| 119 | #For this test, we won't call the script directly, since we want to mock subprocess.check_output |
|
| 120 | argv = ['-t', '0:0:1', '-G', '1', '-C', '1', '-q', 'random', 'launch', 'echo', 'testing123'] |
|
| 121 | ||
| 122 | # Test if the test pass (i.e the script run normaly) |
|
| 123 | mock_check_output.side_effect = None |
|
| 124 | mock_check_output.return_value = "" |
|
| 125 | ||
| 126 | try: |
|
| 127 | smartdispatch_script.main(argv=argv) |
|
| 128 | except SystemExit as e: |
|
| 129 | self.fail("The launcher had no problem, but the script failed nonetheless.") |
|
| 130 | ||
| 131 | # Test if the check fail |
|
| 132 | mock_check_output.side_effect = subprocess.CalledProcessError(1, 1, "A wild error appeared!") |
|
| 133 | ||
| 134 | try: |
|
| 135 | with self.assertRaises(SystemExit) as context: |
|
| 136 | smartdispatch_script.main(argv=argv) |
|
| 137 | ||
| 138 | self.assertTrue(context.exception.code, 2) |
|
| 139 | ||
| 140 | except subprocess.CalledProcessError: |
|
| 141 | # Rerasing the exception |
|
| 142 | orig_exc_type, orig_exc_value, orig_exc_traceback = sys.exc_info() |
|
| 143 | ||
| 144 | new_exc = Exception("smartdispatch_script.main() raised subprocess.CalledProcessError unexpectedly") |
|
| 145 | new_exc.reraised = True |
|
| 146 | six.reraise(type(new_exc), new_exc, orig_exc_traceback) |
|
| 147 | ||
| 148 | def test_main_resume(self): |
|
| 149 | # Setup |
|
| @@ 58-87 (lines=30) @@ | ||
| 55 | ||
| 56 | ||
| 57 | ||
| 58 | @patch('subprocess.check_output') |
|
| 59 | def test_launch_job_check(self, mock_check_output): |
|
| 60 | ||
| 61 | argv = ['-t', '0:0:1', '-G', '1', '-C', '1', '-q', 'random', 'launch', 'echo', 'testing123'] |
|
| 62 | ||
| 63 | # Test if the test pass (i.e the script run normaly) |
|
| 64 | mock_check_output.side_effect = None |
|
| 65 | mock_check_output.return_value = "" |
|
| 66 | ||
| 67 | try: |
|
| 68 | smartdispatch_script.main(argv=argv) |
|
| 69 | except SystemExit as e: |
|
| 70 | self.fail("The launcher had no problem, but the script failed nonetheless.") |
|
| 71 | ||
| 72 | mock_check_output.side_effect = subprocess.CalledProcessError(1, "echo blabla", "A wild error appeared!") |
|
| 73 | ||
| 74 | # Test if the test fail. |
|
| 75 | try: |
|
| 76 | with self.assertRaises(SystemExit) as context: |
|
| 77 | smartdispatch_script.main(argv=argv) |
|
| 78 | ||
| 79 | self.assertTrue(context.exception.code, 2) |
|
| 80 | ||
| 81 | except subprocess.CalledProcessError as e: |
|
| 82 | # Rerasing the exception |
|
| 83 | orig_exc_type, orig_exc_value, orig_exc_traceback = sys.exc_info() |
|
| 84 | ||
| 85 | new_exc = Exception("smartdispatch_script.main() raised subprocess.CalledProcessError unexpectedly") |
|
| 86 | new_exc.reraised = True |
|
| 87 | six.reraise(type(new_exc), new_exc, orig_exc_traceback) |
|
| 88 | ||