Show More
@@ -1,185 +1,193 b'' | |||||
1 | """Tests for launchers |
|
1 | """Tests for launchers | |
2 |
|
2 | |||
3 | Doesn't actually start any subprocesses, but goes through the motions of constructing |
|
3 | Doesn't actually start any subprocesses, but goes through the motions of constructing | |
4 | objects, which should test basic config. |
|
4 | objects, which should test basic config. | |
5 |
|
5 | |||
6 | Authors: |
|
6 | Authors: | |
7 |
|
7 | |||
8 | * Min RK |
|
8 | * Min RK | |
9 | """ |
|
9 | """ | |
10 |
|
10 | |||
11 | #------------------------------------------------------------------------------- |
|
11 | #------------------------------------------------------------------------------- | |
12 | # Copyright (C) 2013 The IPython Development Team |
|
12 | # Copyright (C) 2013 The IPython Development Team | |
13 | # |
|
13 | # | |
14 | # Distributed under the terms of the BSD License. The full license is in |
|
14 | # Distributed under the terms of the BSD License. The full license is in | |
15 | # the file COPYING, distributed as part of this software. |
|
15 | # the file COPYING, distributed as part of this software. | |
16 | #------------------------------------------------------------------------------- |
|
16 | #------------------------------------------------------------------------------- | |
17 |
|
17 | |||
18 | #------------------------------------------------------------------------------- |
|
18 | #------------------------------------------------------------------------------- | |
19 | # Imports |
|
19 | # Imports | |
20 | #------------------------------------------------------------------------------- |
|
20 | #------------------------------------------------------------------------------- | |
21 |
|
21 | |||
22 | import logging |
|
22 | import logging | |
23 | import os |
|
23 | import os | |
24 | import shutil |
|
24 | import shutil | |
25 | import sys |
|
25 | import sys | |
26 | import tempfile |
|
26 | import tempfile | |
27 |
|
27 | |||
28 | from unittest import TestCase |
|
28 | from unittest import TestCase | |
29 |
|
29 | |||
30 | from nose import SkipTest |
|
30 | from nose import SkipTest | |
31 |
|
31 | |||
32 | from IPython.config import Config |
|
32 | from IPython.config import Config | |
33 |
|
33 | |||
34 | from IPython.parallel.apps import launcher |
|
34 | from IPython.parallel.apps import launcher | |
35 |
|
35 | |||
36 | from IPython.testing import decorators as dec |
|
36 | from IPython.testing import decorators as dec | |
37 |
|
37 | |||
38 |
|
38 | |||
39 | #------------------------------------------------------------------------------- |
|
39 | #------------------------------------------------------------------------------- | |
40 | # TestCase Mixins |
|
40 | # TestCase Mixins | |
41 | #------------------------------------------------------------------------------- |
|
41 | #------------------------------------------------------------------------------- | |
42 |
|
42 | |||
43 | class LauncherTest: |
|
43 | class LauncherTest: | |
44 | """Mixin for generic launcher tests""" |
|
44 | """Mixin for generic launcher tests""" | |
45 | def setUp(self): |
|
45 | def setUp(self): | |
46 | self.profile_dir = tempfile.mkdtemp(prefix="profile_") |
|
46 | self.profile_dir = tempfile.mkdtemp(prefix="profile_") | |
47 |
|
47 | |||
48 | def tearDown(self): |
|
48 | def tearDown(self): | |
49 | shutil.rmtree(self.profile_dir) |
|
49 | shutil.rmtree(self.profile_dir) | |
50 |
|
50 | |||
51 | @property |
|
51 | @property | |
52 | def config(self): |
|
52 | def config(self): | |
53 | return Config() |
|
53 | return Config() | |
54 |
|
54 | |||
55 | def build_launcher(self, **kwargs): |
|
55 | def build_launcher(self, **kwargs): | |
56 | kw = dict( |
|
56 | kw = dict( | |
57 | work_dir=self.profile_dir, |
|
57 | work_dir=self.profile_dir, | |
58 | profile_dir=self.profile_dir, |
|
58 | profile_dir=self.profile_dir, | |
59 | config=self.config, |
|
59 | config=self.config, | |
60 | cluster_id='', |
|
60 | cluster_id='', | |
61 | log=logging.getLogger(), |
|
61 | log=logging.getLogger(), | |
62 | ) |
|
62 | ) | |
63 | kw.update(kwargs) |
|
63 | kw.update(kwargs) | |
64 | return self.launcher_class(**kw) |
|
64 | return self.launcher_class(**kw) | |
65 |
|
65 | |||
66 | def test_profile_dir_arg(self): |
|
66 | def test_profile_dir_arg(self): | |
67 | launcher = self.build_launcher() |
|
67 | launcher = self.build_launcher() | |
68 | self.assertTrue("--profile-dir" in launcher.cluster_args) |
|
68 | self.assertTrue("--profile-dir" in launcher.cluster_args) | |
69 | self.assertTrue(self.profile_dir in launcher.cluster_args) |
|
69 | self.assertTrue(self.profile_dir in launcher.cluster_args) | |
70 |
|
70 | |||
71 | def test_cluster_id_arg(self): |
|
71 | def test_cluster_id_arg(self): | |
72 | launcher = self.build_launcher() |
|
72 | launcher = self.build_launcher() | |
73 | self.assertTrue("--cluster-id" in launcher.cluster_args) |
|
73 | self.assertTrue("--cluster-id" in launcher.cluster_args) | |
74 | idx = launcher.cluster_args.index("--cluster-id") |
|
74 | idx = launcher.cluster_args.index("--cluster-id") | |
75 | self.assertEqual(launcher.cluster_args[idx+1], '') |
|
75 | self.assertEqual(launcher.cluster_args[idx+1], '') | |
76 | launcher.cluster_id = 'foo' |
|
76 | launcher.cluster_id = 'foo' | |
77 | self.assertEqual(launcher.cluster_args[idx+1], 'foo') |
|
77 | self.assertEqual(launcher.cluster_args[idx+1], 'foo') | |
78 |
|
78 | |||
79 | def test_args(self): |
|
79 | def test_args(self): | |
80 | launcher = self.build_launcher() |
|
80 | launcher = self.build_launcher() | |
81 | for arg in launcher.args: |
|
81 | for arg in launcher.args: | |
82 | self.assertTrue(isinstance(arg, basestring), str(arg)) |
|
82 | self.assertTrue(isinstance(arg, basestring), str(arg)) | |
83 |
|
83 | |||
84 | class BatchTest: |
|
84 | class BatchTest: | |
85 | """Tests for batch-system launchers (LSF, SGE, PBS)""" |
|
85 | """Tests for batch-system launchers (LSF, SGE, PBS)""" | |
86 | def test_batch_template(self): |
|
86 | def test_batch_template(self): | |
87 | launcher = self.build_launcher() |
|
87 | launcher = self.build_launcher() | |
88 | batch_file = os.path.join(self.profile_dir, launcher.batch_file_name) |
|
88 | batch_file = os.path.join(self.profile_dir, launcher.batch_file_name) | |
89 | self.assertEqual(launcher.batch_file, batch_file) |
|
89 | self.assertEqual(launcher.batch_file, batch_file) | |
90 | launcher.write_batch_script(1) |
|
90 | launcher.write_batch_script(1) | |
91 | self.assertTrue(os.path.isfile(batch_file)) |
|
91 | self.assertTrue(os.path.isfile(batch_file)) | |
92 |
|
92 | |||
93 | class SSHTest: |
|
93 | class SSHTest: | |
94 | """Tests for SSH launchers""" |
|
94 | """Tests for SSH launchers""" | |
95 | def test_cluster_id_arg(self): |
|
95 | def test_cluster_id_arg(self): | |
96 | raise SkipTest("SSH Launchers don't support cluster ID") |
|
96 | raise SkipTest("SSH Launchers don't support cluster ID") | |
97 |
|
97 | |||
98 | def test_remote_profile_dir(self): |
|
98 | def test_remote_profile_dir(self): | |
99 | cfg = Config() |
|
99 | cfg = Config() | |
100 | launcher_cfg = getattr(cfg, self.launcher_class.__name__) |
|
100 | launcher_cfg = getattr(cfg, self.launcher_class.__name__) | |
101 | launcher_cfg.remote_profile_dir = "foo" |
|
101 | launcher_cfg.remote_profile_dir = "foo" | |
102 | launcher = self.build_launcher(config=cfg) |
|
102 | launcher = self.build_launcher(config=cfg) | |
103 | self.assertEqual(launcher.remote_profile_dir, "foo") |
|
103 | self.assertEqual(launcher.remote_profile_dir, "foo") | |
104 |
|
104 | |||
105 | def test_remote_profile_dir_default(self): |
|
105 | def test_remote_profile_dir_default(self): | |
106 | launcher = self.build_launcher() |
|
106 | launcher = self.build_launcher() | |
107 | self.assertEqual(launcher.remote_profile_dir, self.profile_dir) |
|
107 | self.assertEqual(launcher.remote_profile_dir, self.profile_dir) | |
108 |
|
108 | |||
109 | #------------------------------------------------------------------------------- |
|
109 | #------------------------------------------------------------------------------- | |
110 | # Controller Launcher Tests |
|
110 | # Controller Launcher Tests | |
111 | #------------------------------------------------------------------------------- |
|
111 | #------------------------------------------------------------------------------- | |
112 |
|
112 | |||
113 | class ControllerLauncherTest(LauncherTest): |
|
113 | class ControllerLauncherTest(LauncherTest): | |
114 | """Tests for Controller Launchers""" |
|
114 | """Tests for Controller Launchers""" | |
115 | pass |
|
115 | pass | |
116 |
|
116 | |||
117 | class TestLocalControllerLauncher(ControllerLauncherTest, TestCase): |
|
117 | class TestLocalControllerLauncher(ControllerLauncherTest, TestCase): | |
118 | launcher_class = launcher.LocalControllerLauncher |
|
118 | launcher_class = launcher.LocalControllerLauncher | |
119 |
|
119 | |||
120 | class TestMPIControllerLauncher(ControllerLauncherTest, TestCase): |
|
120 | class TestMPIControllerLauncher(ControllerLauncherTest, TestCase): | |
121 | launcher_class = launcher.MPIControllerLauncher |
|
121 | launcher_class = launcher.MPIControllerLauncher | |
122 |
|
122 | |||
123 | class TestPBSControllerLauncher(BatchTest, ControllerLauncherTest, TestCase): |
|
123 | class TestPBSControllerLauncher(BatchTest, ControllerLauncherTest, TestCase): | |
124 | launcher_class = launcher.PBSControllerLauncher |
|
124 | launcher_class = launcher.PBSControllerLauncher | |
125 |
|
125 | |||
126 | class TestSGEControllerLauncher(BatchTest, ControllerLauncherTest, TestCase): |
|
126 | class TestSGEControllerLauncher(BatchTest, ControllerLauncherTest, TestCase): | |
127 | launcher_class = launcher.SGEControllerLauncher |
|
127 | launcher_class = launcher.SGEControllerLauncher | |
128 |
|
128 | |||
129 | class TestLSFControllerLauncher(BatchTest, ControllerLauncherTest, TestCase): |
|
129 | class TestLSFControllerLauncher(BatchTest, ControllerLauncherTest, TestCase): | |
130 | launcher_class = launcher.LSFControllerLauncher |
|
130 | launcher_class = launcher.LSFControllerLauncher | |
131 |
|
131 | |||
132 | class TestHTCondorControllerLauncher(BatchTest, ControllerLauncherTest, TestCase): |
|
132 | class TestHTCondorControllerLauncher(BatchTest, ControllerLauncherTest, TestCase): | |
133 | launcher_class = launcher.HTCondorControllerLauncher |
|
133 | launcher_class = launcher.HTCondorControllerLauncher | |
134 |
|
134 | |||
135 | class TestSSHControllerLauncher(SSHTest, ControllerLauncherTest, TestCase): |
|
135 | class TestSSHControllerLauncher(SSHTest, ControllerLauncherTest, TestCase): | |
136 | launcher_class = launcher.SSHControllerLauncher |
|
136 | launcher_class = launcher.SSHControllerLauncher | |
137 |
|
137 | |||
138 | #------------------------------------------------------------------------------- |
|
138 | #------------------------------------------------------------------------------- | |
139 | # Engine Set Launcher Tests |
|
139 | # Engine Set Launcher Tests | |
140 | #------------------------------------------------------------------------------- |
|
140 | #------------------------------------------------------------------------------- | |
141 |
|
141 | |||
142 | class EngineSetLauncherTest(LauncherTest): |
|
142 | class EngineSetLauncherTest(LauncherTest): | |
143 | """Tests for EngineSet launchers""" |
|
143 | """Tests for EngineSet launchers""" | |
144 | pass |
|
144 | pass | |
145 |
|
145 | |||
146 | class TestLocalEngineSetLauncher(EngineSetLauncherTest, TestCase): |
|
146 | class TestLocalEngineSetLauncher(EngineSetLauncherTest, TestCase): | |
147 | launcher_class = launcher.LocalEngineSetLauncher |
|
147 | launcher_class = launcher.LocalEngineSetLauncher | |
148 |
|
148 | |||
149 | class TestMPIEngineSetLauncher(EngineSetLauncherTest, TestCase): |
|
149 | class TestMPIEngineSetLauncher(EngineSetLauncherTest, TestCase): | |
150 | launcher_class = launcher.MPIEngineSetLauncher |
|
150 | launcher_class = launcher.MPIEngineSetLauncher | |
151 |
|
151 | |||
152 | class TestPBSEngineSetLauncher(BatchTest, EngineSetLauncherTest, TestCase): |
|
152 | class TestPBSEngineSetLauncher(BatchTest, EngineSetLauncherTest, TestCase): | |
153 | launcher_class = launcher.PBSEngineSetLauncher |
|
153 | launcher_class = launcher.PBSEngineSetLauncher | |
154 |
|
154 | |||
155 | class TestSGEEngineSetLauncher(BatchTest, EngineSetLauncherTest, TestCase): |
|
155 | class TestSGEEngineSetLauncher(BatchTest, EngineSetLauncherTest, TestCase): | |
156 | launcher_class = launcher.SGEEngineSetLauncher |
|
156 | launcher_class = launcher.SGEEngineSetLauncher | |
157 |
|
157 | |||
158 | class TestLSFEngineSetLauncher(BatchTest, EngineSetLauncherTest, TestCase): |
|
158 | class TestLSFEngineSetLauncher(BatchTest, EngineSetLauncherTest, TestCase): | |
159 | launcher_class = launcher.LSFEngineSetLauncher |
|
159 | launcher_class = launcher.LSFEngineSetLauncher | |
160 |
|
160 | |||
161 | class TestHTCondorEngineSetLauncher(BatchTest, EngineSetLauncherTest, TestCase): |
|
161 | class TestHTCondorEngineSetLauncher(BatchTest, EngineSetLauncherTest, TestCase): | |
162 | launcher_class = launcher.HTCondorEngineSetLauncher |
|
162 | launcher_class = launcher.HTCondorEngineSetLauncher | |
163 |
|
163 | |||
164 | class TestSSHEngineSetLauncher(EngineSetLauncherTest, TestCase): |
|
164 | class TestSSHEngineSetLauncher(EngineSetLauncherTest, TestCase): | |
165 | launcher_class = launcher.SSHEngineSetLauncher |
|
165 | launcher_class = launcher.SSHEngineSetLauncher | |
166 |
|
166 | |||
167 | def test_cluster_id_arg(self): |
|
167 | def test_cluster_id_arg(self): | |
168 | raise SkipTest("SSH Launchers don't support cluster ID") |
|
168 | raise SkipTest("SSH Launchers don't support cluster ID") | |
169 |
|
169 | |||
170 | class TestSSHProxyEngineSetLauncher(SSHTest, LauncherTest, TestCase): |
|
170 | class TestSSHProxyEngineSetLauncher(SSHTest, LauncherTest, TestCase): | |
171 | launcher_class = launcher.SSHProxyEngineSetLauncher |
|
171 | launcher_class = launcher.SSHProxyEngineSetLauncher | |
172 |
|
172 | |||
173 | class TestSSHEngineLauncher(SSHTest, LauncherTest, TestCase): |
|
173 | class TestSSHEngineLauncher(SSHTest, LauncherTest, TestCase): | |
174 | launcher_class = launcher.SSHEngineLauncher |
|
174 | launcher_class = launcher.SSHEngineLauncher | |
175 |
|
175 | |||
176 | #------------------------------------------------------------------------------- |
|
176 | #------------------------------------------------------------------------------- | |
177 | # Windows Launcher Tests |
|
177 | # Windows Launcher Tests | |
178 | #------------------------------------------------------------------------------- |
|
178 | #------------------------------------------------------------------------------- | |
179 |
|
179 | |||
180 | if sys.platform.startswith("win"): |
|
180 | class WinHPCTest: | |
181 | class TestWinHPCControllerLauncher(ControllerLauncherTest, TestCase): |
|
181 | """Tests for WinHPC Launchers""" | |
182 | launcher_class = launcher.WindowsHPCControllerLauncher |
|
182 | def test_batch_template(self): | |
|
183 | launcher = self.build_launcher() | |||
|
184 | job_file = os.path.join(self.profile_dir, launcher.job_file_name) | |||
|
185 | self.assertEqual(launcher.job_file, job_file) | |||
|
186 | launcher.write_job_file(1) | |||
|
187 | self.assertTrue(os.path.isfile(job_file)) | |||
|
188 | ||||
|
189 | class TestWinHPCControllerLauncher(WinHPCTest, ControllerLauncherTest, TestCase): | |||
|
190 | launcher_class = launcher.WindowsHPCControllerLauncher | |||
183 |
|
191 | |||
184 |
|
|
192 | class TestWinHPCEngineSetLauncher(WinHPCTest, EngineSetLauncherTest, TestCase): | |
185 |
|
|
193 | launcher_class = launcher.WindowsHPCEngineSetLauncher |
General Comments 0
You need to be logged in to leave comments.
Login now