Code Duplication    Length = 33-34 lines in 2 locations

tests/test_smart_dispatch.py 2 locations

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