Skip to content

Commit 1b7ffbb

Browse files
committed
Puttig all the tests on the script in the same file.
1 parent 4d76f5a commit 1b7ffbb

File tree

1 file changed

+37
-6
lines changed

1 file changed

+37
-6
lines changed

tests/test_smart_dispatch.py

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
import tempfile
44
import shutil
55
from os.path import join as pjoin, abspath
6-
6+
from mock import patch
77
from subprocess import call
8-
8+
import subprocess
99
from nose.tools import assert_true, assert_equal
10-
10+
from smartdispatch import smartdispatch_script
1111

1212
class TestSmartdispatcher(unittest.TestCase):
1313

@@ -23,17 +23,23 @@ def setUp(self):
2323
self.nb_commands = len(self.commands)
2424

2525
scripts_path = abspath(pjoin(os.path.dirname(__file__), os.pardir, "scripts"))
26-
self.smart_dispatch_command = '{} -C 1 -q test -t 5:00 -x'.format(pjoin(scripts_path, 'smart-dispatch'))
26+
self.smart_dispatch_command = '{} -C 1 -G 1 -q test -t 5:00 -x'.format(pjoin(scripts_path, 'smart-dispatch'))
2727
self.launch_command = "{0} launch {1}".format(self.smart_dispatch_command, self.folded_commands)
2828
self.resume_command = "{0} resume {{0}}".format(self.smart_dispatch_command)
2929

30-
smart_dispatch_command_with_pool = '{} --pool 10 -C 1 -q test -t 5:00 -x {{0}}'.format(pjoin(scripts_path, 'smart-dispatch'))
30+
self.smart_dispatch_launcher_command = '{} -C 1 -G 1 -q test -t 5:00'.format(pjoin(scripts_path, 'smart-dispatch'))
31+
self.launcher_command = "{0} launch {1}".format(self.smart_dispatch_launcher_command, self.folded_commands)
32+
33+
smart_dispatch_command_with_pool = '{} --pool 10 -C 1 -G 1 -q test -t 5:00 -x {{0}}'.format(pjoin(scripts_path, 'smart-dispatch'))
3134
self.launch_command_with_pool = smart_dispatch_command_with_pool.format('launch ' + self.folded_commands)
3235
self.nb_workers = 10
3336

34-
smart_dispatch_command_with_cores = '{} -C 1 -c {{cores}} -q test -t 5:00 -x {{0}}'.format(pjoin(scripts_path, 'smart-dispatch'))
37+
smart_dispatch_command_with_cores = '{} -C 1 -G 1 -c {{cores}} -q test -t 5:00 -x {{0}}'.format(pjoin(scripts_path, 'smart-dispatch'))
3538
self.launch_command_with_cores = smart_dispatch_command_with_cores.format('launch ' + self.folded_commands, cores='{cores}')
3639

40+
smart_dispatch_command_with_gpus = '{} -C 1 -G 1 -g {{gpus}} -q test -t 5:00 -x {{0}}'.format(pjoin(scripts_path, 'smart-dispatch'))
41+
self.launch_command_with_gpus = smart_dispatch_command_with_gpus.format('launch ' + self.folded_commands, gpus='{gpus}')
42+
3743
self._cwd = os.getcwd()
3844
os.chdir(self.testing_dir)
3945

@@ -95,6 +101,31 @@ def test_main_launch_with_cores_command(self):
95101
assert_equal(exit_status_100, 2)
96102
assert_true(os.path.isdir(self.logs_dir))
97103

104+
def test_main_launch_with_gpus_command(self):
105+
# Actual test
106+
exit_status_100 = call(self.launch_command_with_gpus.format(gpus=100), shell=True)
107+
108+
# Test validation
109+
assert_equal(exit_status_100, 2)
110+
assert_true(os.path.isdir(self.logs_dir))
111+
112+
@patch('subprocess.check_output')
113+
def test_launch_job_check(self, mock_check_output):
114+
115+
#For this test, we won't call the script directly, since we want to mock subprocess.check_output
116+
mock_check_output.side_effect = subprocess.CalledProcessError(1, 1, "A wild error appeared!")
117+
argv = ['-t', '0:0:1', '-G', '1', '-C', '1', '-q', 'random', 'launch', 'echo', 'testing123']
118+
119+
try:
120+
with self.assertRaises(SystemExit) as context:
121+
smartdispatch_script.main(argv=argv)
122+
123+
self.assertTrue(context.exception.code, 2)
124+
125+
except subprocess.CalledProcessError:
126+
self.fail("smartdispatch_script.main() raised CalledProcessError unexpectedly!")
127+
128+
98129
def test_main_resume(self):
99130
# Setup
100131
call(self.launch_command, shell=True)

0 commit comments

Comments
 (0)