Code Duplication    Length = 33-34 lines in 2 locations

tests/test_smart_dispatch.py 2 locations

@@ 168-201 (lines=34) @@
165
            if f.startswith('job_commands_') and f.endswith('.sh'):
166
                os.remove(pjoin(path_job_commands, f))
167
168
        # Should NOT move running commands back to pending but should add new workers.
169
        command_line = self.resume_command.format(batch_uid)
170
        command_line += " --expandPool"
171
        exit_status = call(command_line, shell=True)
172
173
        # Test validation
174
        assert_equal(exit_status, 0)
175
        assert_equal(len(open(running_commands_file).readlines()), len(commands[::2]))
176
        assert_equal(len(open(pending_commands_file).readlines()), len(commands[1::2]))
177
178
        nb_job_commands_files = len(os.listdir(path_job_commands))
179
        assert_equal(nb_job_commands_files-nb_commands_files, len(commands[1::2]))
180
181
    def test_main_resume_by_expanding_pool(self):
182
        # Create SMART_DISPATCH_LOGS structure.
183
        call(self.launch_command, shell=True)
184
        batch_uid = os.listdir(self.logs_dir)[0]
185
186
        # Simulate that some commands are in the running state.
187
        nb_commands_files = 2  # 'commands.txt' and 'running_commands.txt'
188
        path_job_commands = os.path.join(self.logs_dir, batch_uid, "commands")
189
        pending_commands_file = pjoin(path_job_commands, "commands.txt")
190
        running_commands_file = pjoin(path_job_commands, "running_commands.txt")
191
        commands = open(pending_commands_file).read().strip().split("\n")
192
        with open(running_commands_file, 'w') as running_commands:
193
            running_commands.write("\n".join(commands[::2]) + "\n")
194
        with open(pending_commands_file, 'w') as pending_commands:
195
            pending_commands.write("\n".join(commands[1::2]) + "\n")
196
197
        # Remove PBS files so we can check that new ones are going to be created.
198
        for f in os.listdir(path_job_commands):
199
            if f.startswith('job_commands_') and f.endswith('.sh'):
200
                os.remove(pjoin(path_job_commands, f))
201
202
        # Should NOT move running commands back to pending but should add new workers.
203
        nb_workers_to_add = 3
204
        command_line = self.resume_command.format(batch_uid)
@@ 134-166 (lines=33) @@
131
        commands = open(pending_commands_file).read().strip().split("\n")
132
        with open(running_commands_file, 'w') as running_commands:
133
            running_commands.write("\n".join(commands[::2]) + "\n")
134
        with open(pending_commands_file, 'w') as pending_commands:
135
            pending_commands.write("\n".join(commands[1::2]) + "\n")
136
137
        # Actual test (should move running commands back to pending).
138
        exit_status = call(self.resume_command.format(batch_uid), shell=True)
139
140
        # Test validation
141
        assert_equal(exit_status, 0)
142
        assert_true(os.path.isdir(self.logs_dir))
143
        assert_equal(len(os.listdir(self.logs_dir)), 1)
144
        assert_equal(len(open(running_commands_file).readlines()), 0)
145
        assert_equal(len(open(pending_commands_file).readlines()), len(commands))
146
147
    def test_main_resume_by_expanding_pool_default(self):
148
        # Create SMART_DISPATCH_LOGS structure.
149
        call(self.launch_command, shell=True)
150
        batch_uid = os.listdir(self.logs_dir)[0]
151
152
        # Simulate that some commands are in the running state.
153
        nb_commands_files = 2  # 'commands.txt' and 'running_commands.txt'
154
        path_job_commands = os.path.join(self.logs_dir, batch_uid, "commands")
155
        pending_commands_file = pjoin(path_job_commands, "commands.txt")
156
        running_commands_file = pjoin(path_job_commands, "running_commands.txt")
157
        commands = open(pending_commands_file).read().strip().split("\n")
158
        with open(running_commands_file, 'w') as running_commands:
159
            running_commands.write("\n".join(commands[::2]) + "\n")
160
        with open(pending_commands_file, 'w') as pending_commands:
161
            pending_commands.write("\n".join(commands[1::2]) + "\n")
162
163
        # Remove PBS files so we can check that new ones are going to be created.
164
        for f in os.listdir(path_job_commands):
165
            if f.startswith('job_commands_') and f.endswith('.sh'):
166
                os.remove(pjoin(path_job_commands, f))
167
168
        # Should NOT move running commands back to pending but should add new workers.
169
        command_line = self.resume_command.format(batch_uid)