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