-
Notifications
You must be signed in to change notification settings - Fork 18
Handle resources error gracefully. (#155) #167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
072dce6
f6ab791
d9c4e9c
4a0d63d
9f63771
cc07bc6
4d76f5a
1b7ffbb
90c4f4d
fba5bf3
5d99e79
7e357d8
c33292b
a83e500
94f58d0
7eb4b84
cec39e6
3b27597
71af7a3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,29 +9,7 @@ | |
| from nose.tools import assert_true, assert_equal | ||
| from smartdispatch import smartdispatch_script | ||
| import six | ||
| import sys | ||
| import traceback | ||
|
|
||
| def rethrow_exception(exception, new_message): | ||
|
|
||
| def func_wraper(func): | ||
|
|
||
| def test_func(*args, **kwargs): | ||
| try: | ||
| return func(*args, **kwargs) | ||
| except exception as e: | ||
|
|
||
| orig_exc_type, orig_exc_value, orig_exc_traceback = sys.exc_info() | ||
| new_exc = Exception(new_message) | ||
| new_exc.reraised = True | ||
| new_exc.__cause__ = orig_exc_value | ||
|
|
||
| new_traceback = orig_exc_traceback | ||
| six.reraise(type(new_exc), new_exc, new_traceback) | ||
|
|
||
|
|
||
| return test_func | ||
| return func_wraper | ||
| from smartdispatch import utils | ||
|
|
||
| class TestSmartdispatcher(unittest.TestCase): | ||
|
|
||
|
|
@@ -135,7 +113,7 @@ def test_main_launch_with_gpus_command(self): | |
| assert_equal(exit_status_100, 2) | ||
| assert_true(os.path.isdir(self.logs_dir)) | ||
|
|
||
| @rethrow_exception(SystemExit, "smartdispatch_script.main() raised SystemExit unexpectedly.") | ||
| @utils.rethrow_exception(SystemExit, "smartdispatch_script.main() raised SystemExit unexpectedly.") | ||
| def test_gpu_check(self): | ||
|
|
||
| argv = ['-x', '-g', '2', '-G', '1', '-C', '1', '-q', 'random', '-t', '00:00:10' ,'launch', 'echo', 'testing123'] | ||
|
|
@@ -150,7 +128,22 @@ def test_gpu_check(self): | |
| argv[2] = '1' | ||
| smartdispatch_script.main(argv=argv) | ||
|
|
||
| @rethrow_exception(SystemExit, "smartdispatch_script.main() raised SystemExit unexpectedly.") | ||
| # Test if we don't have gpus. (and spicified in script). | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. spicified 😝
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like you should do
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In my defence, it's the same line/mistake as the other one 😜
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Coherence is important indeed
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wait, it's the same file? hahaha! 😊 |
||
| argv[2] = '0' | ||
| argv[4] = '0' | ||
| smartdispatch_script.main(argv=argv) | ||
|
|
||
| # Don't have gpus, but the user specofy 1 anyway. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A variant! Specofy! 🙃 |
||
| argv[2] = '1' | ||
| with self.assertRaises(SystemExit) as context: | ||
| smartdispatch_script.main(argv=argv) | ||
| self.assertTrue(context.exception.code, 2) | ||
|
|
||
| # Test if the user didn't specified anything. | ||
| argv = ['-x', '-C', '1', '-q', 'random', '-t', '00:00:10' ,'launch', 'echo', 'testing123'] | ||
| smartdispatch_script.main(argv=argv) | ||
|
|
||
| @utils.rethrow_exception(SystemExit, "smartdispatch_script.main() raised SystemExit unexpectedly.") | ||
| def test_cpu_check(self): | ||
|
|
||
| argv = ['-x', '-c', '2', '-C', '1', '-G', '1', '-t', '00:00:10', '-q', 'random', 'launch', 'echo', 'testing123'] | ||
|
|
@@ -165,7 +158,7 @@ def test_cpu_check(self): | |
| argv[2] = '1' | ||
| smartdispatch_script.main(argv=argv) | ||
|
|
||
| @rethrow_exception(subprocess.CalledProcessError, "smartdispatch_script.main() raised subprocess.CalledProcessError unexpectedly") | ||
| @utils.rethrow_exception(subprocess.CalledProcessError, "smartdispatch_script.main() raised subprocess.CalledProcessError unexpectedly") | ||
| @patch('subprocess.check_output') | ||
| def test_launch_job_check(self, mock_check_output): | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't be better to use @functools.wraps(func) here for the stacktrace? I mean
I just had a problem with stack trace because of decorators while implementing tests for Slurm clusters. I wonder if the same thing is happening here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just tried, it didn't change the stack trace.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, well you can leave it there anyway.