|
1
|
|
|
import unittest |
|
2
|
|
|
from smartdispatch import smartdispatch_script |
|
3
|
|
|
import subprocess |
|
4
|
|
|
from mock import patch |
|
5
|
|
|
import tempfile as tmp |
|
6
|
|
|
import shutil |
|
7
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
class TestSmartScript(unittest.TestCase): |
|
10
|
|
|
|
|
11
|
|
|
def setUp(self): |
|
12
|
|
|
self._base_dir = tmp.mkdtemp() |
|
13
|
|
|
smartdispatch_script.LOGS_FOLDERNAME = self._base_dir |
|
14
|
|
|
|
|
15
|
|
|
def tearDown(self): |
|
16
|
|
|
shutil.rmtree(self._base_dir) |
|
17
|
|
|
|
|
18
|
|
|
def test_gpu_check(self): |
|
19
|
|
|
|
|
20
|
|
|
argv = ['-x', '-g', '2', '-G', '1', '-C', '1', '-q', 'random', '-t', '10' ,'launch', 'echo', 'testing123'] |
|
21
|
|
|
|
|
22
|
|
|
with self.assertRaises(SystemExit) as context: |
|
23
|
|
|
smartdispatch_script.main(argv=argv) |
|
24
|
|
|
|
|
25
|
|
|
self.assertTrue(context.exception.code, 2) |
|
26
|
|
|
|
|
27
|
|
|
def test_cpu_check(self): |
|
28
|
|
|
|
|
29
|
|
|
argv = ['-x', '-c', '2', '-C', '1', '-G', '1', '-t', '10', '-q', 'random', 'launch', 'echo', 'testing123'] |
|
30
|
|
|
|
|
31
|
|
|
with self.assertRaises(SystemExit) as context: |
|
32
|
|
|
smartdispatch_script.main(argv=argv) |
|
33
|
|
|
|
|
34
|
|
|
self.assertTrue(context.exception.code, 2) |
|
35
|
|
|
|
|
36
|
|
|
@patch('subprocess.check_output') |
|
37
|
|
|
def test_launch_job_check(self, mock_check_output): |
|
38
|
|
|
|
|
39
|
|
|
mock_check_output.side_effect = subprocess.CalledProcessError(1, 1, "A wild error appeared!") |
|
40
|
|
|
argv = ['-t', '0:0:1', '-G', '1', '-C', '1', '-q', 'random', 'launch', 'echo', 'testing123'] |
|
41
|
|
|
|
|
42
|
|
|
try: |
|
43
|
|
|
with self.assertRaises(SystemExit) as context: |
|
44
|
|
|
smartdispatch_script.main(argv=argv) |
|
45
|
|
|
|
|
46
|
|
|
self.assertTrue(context.exception.code, 2) |
|
47
|
|
|
|
|
48
|
|
|
except subprocess.CalledProcessError: |
|
49
|
|
|
self.fail("smartdispatch_script.main() raised CalledProcessError unexpectedly!") |
|
50
|
|
|
|