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