Code Duplication    Length = 33-34 lines in 2 locations

tests/test_smart_dispatch.py 2 locations

@@ 231-264 (lines=34) @@
228
            pending_commands.write("\n".join(commands[1::2]) + "\n")
229
230
        # Actual test (should move running commands back to pending).
231
        exit_status = call(self.resume_command.format(batch_uid), shell=True)
232
233
        # Test validation
234
        assert_equal(exit_status, 0)
235
        assert_true(os.path.isdir(self.logs_dir))
236
        assert_equal(len(os.listdir(self.logs_dir)), 1)
237
        assert_equal(len(open(running_commands_file).readlines()), 0)
238
        assert_equal(len(open(pending_commands_file).readlines()), len(commands))
239
240
    def test_main_resume_by_expanding_pool_default(self):
241
        # Create SMART_DISPATCH_LOGS structure.
242
        call(self.launch_command, shell=True)
243
        batch_uid = os.listdir(self.logs_dir)[0]
244
245
        # Simulate that some commands are in the running state.
246
        nb_commands_files = 2  # 'commands.txt' and 'running_commands.txt'
247
        path_job_commands = os.path.join(self.logs_dir, batch_uid, "commands")
248
        pending_commands_file = pjoin(path_job_commands, "commands.txt")
249
        running_commands_file = pjoin(path_job_commands, "running_commands.txt")
250
        commands = open(pending_commands_file).read().strip().split("\n")
251
        with open(running_commands_file, 'w') as running_commands:
252
            running_commands.write("\n".join(commands[::2]) + "\n")
253
        with open(pending_commands_file, 'w') as pending_commands:
254
            pending_commands.write("\n".join(commands[1::2]) + "\n")
255
256
        # Remove PBS files so we can check that new ones are going to be created.
257
        for f in os.listdir(path_job_commands):
258
            if f.startswith('job_commands_') and f.endswith('.sh'):
259
                os.remove(pjoin(path_job_commands, f))
260
261
        # Should NOT move running commands back to pending but should add new workers.
262
        command_line = self.resume_command.format(batch_uid)
263
        command_line += " --expandPool"
264
        exit_status = call(command_line, shell=True)
265
266
        # Test validation
267
        assert_equal(exit_status, 0)
@@ 197-229 (lines=33) @@
194
        batch_uid = os.listdir(self.logs_dir)[0]
195
196
        # Simulate that some commands are in the running state.
197
        path_job_commands = os.path.join(self.logs_dir, batch_uid, "commands")
198
        pending_commands_file = pjoin(path_job_commands, "commands.txt")
199
        running_commands_file = pjoin(path_job_commands, "running_commands.txt")
200
        commands = open(pending_commands_file).read().strip().split("\n")
201
        with open(running_commands_file, 'w') as running_commands:
202
            running_commands.write("\n".join(commands[::2]) + "\n")
203
        with open(pending_commands_file, 'w') as pending_commands:
204
            pending_commands.write("\n".join(commands[1::2]) + "\n")
205
206
        # Actual test (should move running commands back to pending).
207
        exit_status = call(self.resume_command.format(batch_uid), shell=True)
208
209
        # Test validation
210
        assert_equal(exit_status, 0)
211
        assert_true(os.path.isdir(self.logs_dir))
212
        assert_equal(len(os.listdir(self.logs_dir)), 1)
213
        assert_equal(len(open(running_commands_file).readlines()), 0)
214
        assert_equal(len(open(pending_commands_file).readlines()), len(commands))
215
216
        # Test when batch_uid is a path instead of a jobname.
217
        # Setup
218
        batch_uid = os.path.join(self.logs_dir, os.listdir(self.logs_dir)[0])
219
220
        # Simulate that some commands are in the running state.
221
        path_job_commands = os.path.join(self.logs_dir, batch_uid, "commands")
222
        pending_commands_file = pjoin(path_job_commands, "commands.txt")
223
        running_commands_file = pjoin(path_job_commands, "running_commands.txt")
224
        commands = open(pending_commands_file).read().strip().split("\n")
225
        with open(running_commands_file, 'w') as running_commands:
226
            running_commands.write("\n".join(commands[::2]) + "\n")
227
        with open(pending_commands_file, 'w') as pending_commands:
228
            pending_commands.write("\n".join(commands[1::2]) + "\n")
229
230
        # Actual test (should move running commands back to pending).
231
        exit_status = call(self.resume_command.format(batch_uid), shell=True)
232