Skip to content

Commit 9f63771

Browse files
committed
Adding test to test the well behaviour of the script
1 parent 4a0d63d commit 9f63771

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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', '-q', 'gpu_1', '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', '-q', 'gpu_1', '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 = ['-q', 'gpu_1', '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!")

0 commit comments

Comments
 (0)