Code Duplication    Length = 33-34 lines in 2 locations

tests/test_smart_dispatch.py 2 locations

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