Completed
Pull Request — master (#98)
by Marc-Alexandre
55s
created

tests.TestSmartdispatcher.test_main_resume()   B

Complexity

Conditions 1

Size

Total Lines 24

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 1
dl 0
loc 24
rs 8.9713
1
import os
2
import unittest
3
import tempfile
4
import shutil
5
6
from subprocess import call
7
8
from nose.tools import assert_true, assert_equal
9
10
11
class TestSmartdispatcher(unittest.TestCase):
12
13
    def setUp(self):
14
        self.testing_dir = tempfile.mkdtemp()
15
        self.logs_dir = os.path.join(self.testing_dir, 'SMART_DISPATCH_LOGS')
16
17
        base_command = 'smart_dispatch.py --pool 10 -C 42 -q test -t 5:00 -x {0}'
18
        self.launch_command = base_command.format('launch echo "1 2 3 4" "6 7 8" "9 0"')
19
        self.resume_command = base_command.format('resume {0}')
20
21
        self._cwd = os.getcwd()
22
        os.chdir(self.testing_dir)
23
24
    def tearDown(self):
25
        os.chdir(self._cwd)
26
        shutil.rmtree(self.testing_dir)
27
28
    def test_main_launch(self):
29
        # Actual test
30
        exit_status = call(self.launch_command, shell=True)
31
32
        # Test validation
33
        assert_equal(exit_status, 0)
34
        assert_true(os.path.isdir(self.logs_dir))
35
        assert_equal(len(os.listdir(self.logs_dir)), 1)
36
37
    def test_main_resume(self):
38
        # SetUp
39
        call(self.launch_command, shell=True)
40
        batch_uid = os.listdir(self.logs_dir)[0]
41
42
        # Actual test
43
        exit_status = call(self.resume_command.format(batch_uid), shell=True)
44
45
        # Test validation
46
        assert_equal(exit_status, 0)
47
        assert_true(os.path.isdir(self.logs_dir))
48
        assert_equal(len(os.listdir(self.logs_dir)), 1)
49
50
        # Test when batch_uid is a path instead of a jobname.
51
        call(self.launch_command, shell=True)
52
        batch_uid = os.path.join(self.logs_dir, os.listdir(self.logs_dir)[0])
53
54
        # Actual test
55
        exit_status = call(self.resume_command.format(batch_uid), shell=True)
56
57
        # Test validation
58
        assert_equal(exit_status, 0)
59
        assert_true(os.path.isdir(self.logs_dir))
60
        assert_equal(len(os.listdir(self.logs_dir)), 1)
61