41 Create useful objects for each test and the teardown
47 job1.working_dir = Path(test_dir, job1.name,
"working_dir").absolute().as_posix()
48 job1.output_dir = Path(test_dir, job1.name,
"output_dir").absolute().as_posix()
49 job1.cmd = [
"bash", test_script.name]
50 job1.input_sandbox_files = [test_script.as_posix()]
56 job_dict[
"name"] = name2
57 job_dict[
"working_dir"] = Path(test_dir, name2,
"working_dir").as_posix()
58 job_dict[
"output_dir"] = Path(test_dir, name2,
"output_dir").as_posix()
59 job_dict[
"output_patterns"] = []
60 job_dict[
"cmd"] = [
"bash", test_script.name]
62 job_dict[
"input_sandbox_files"] = [test_script.as_posix()]
63 job_dict[
"input_files"] = []
64 job_dict[
"setup_cmds"] = []
65 job_dict[
"backend_args"] = {}
66 job_dict[
"subjobs"] = [{
"id": i,
"input_files": [],
"args": [str(i)]}
for i
in range(4)]
70 self.
job2 = Job(name2, job_dict=job_dict)
73 test_dir.mkdir(parents=
True, exist_ok=
False)
114 Make sure that the two ways of setting up Job objects correctly converted attributes to be Paths instead of strings.
116 self.assertIsInstance(self.
job1.output_dir, Path)
117 self.assertIsInstance(self.
job1.working_dir, Path)
118 for path
in self.
job1.input_sandbox_files:
119 self.assertIsInstance(path, Path)
120 for path
in self.
job1.input_files:
121 self.assertIsInstance(path, Path)
123 self.assertIsInstance(self.
job2.output_dir, Path)
124 self.assertIsInstance(self.
job2.working_dir, Path)
125 for path
in self.
job2.input_sandbox_files:
126 self.assertIsInstance(path, Path)
127 for path
in self.
job2.input_files:
128 self.assertIsInstance(path, Path)
130 for subjob
in self.
job2.subjobs.values():
131 self.assertIsInstance(subjob.output_dir, Path)
132 self.assertIsInstance(subjob.working_dir, Path)
136 Test the creation of SubJobs and assignment of input data files via splitter classes.
138 self.assertIsNone(self.
job1.splitter)
139 self.assertIsNone(self.
job2.splitter)
141 self.
job1.max_files_per_subjob = 2
142 self.assertIsInstance(self.
job1.splitter, MaxFilesSplitter)
143 self.assertEqual(self.
job1.splitter.max_files_per_subjob, 2)
144 self.
job1.max_subjobs = 3
145 self.assertIsInstance(self.
job1.splitter, MaxSubjobsSplitter)
146 self.assertEqual(self.
job1.splitter.max_subjobs, 3)
150 input_file = Path(test_dir, f
"{i}.txt")
151 input_file.touch(exist_ok=
False)
152 self.
job1.input_files.append(input_file)
154 self.
job1.splitter = MaxFilesSplitter(max_files_per_subjob=2)
155 self.
job1.splitter.create_subjobs(self.
job1)
156 self.assertEqual(len(self.
job1.subjobs), 3)
157 for i, subjob
in self.
job1.subjobs.items():
158 self.assertTrue(len(subjob.input_files) == 2
or len(subjob.input_files) == 1)
160 self.
job1.subjobs = {}
161 self.
job1.splitter = MaxSubjobsSplitter(max_subjobs=4)
162 self.
job1.splitter.create_subjobs(self.
job1)
163 self.assertEqual(len(self.
job1.subjobs), 4)
164 for i, subjob
in self.
job1.subjobs.items():
165 self.assertTrue(len(subjob.input_files) == 2
or len(subjob.input_files) == 1)
168 self.
job1.subjobs = {}
169 arg_gen = ArgumentsGenerator(range_arguments, 3, stop=12, step=2)
170 self.
job1.splitter = ArgumentsSplitter(arguments_generator=arg_gen, max_subjobs=10)
171 self.
job1.splitter.create_subjobs(self.
job1)
172 self.assertEqual(len(self.
job1.subjobs), 5)
173 for (i, subjob), arg
in zip(self.
job1.subjobs.items(), range(3, 12, 2)):
175 self.assertEqual(self.
job1.input_files, subjob.input_files)
176 self.assertEqual(arg, subjob.args[0])
179 self.
job1.subjobs = {}
180 self.
job1.splitter = ArgumentsSplitter(arguments_generator=arg_gen, max_subjobs=2)
181 self.assertRaises(SplitterError, self.
job1.splitter.create_subjobs, self.
job1)
185 Does the copy of files/directories for the input sandbox work correctly?
188 input_sandbox_dir = Path(test_dir,
"test_input_sandbox_dir")
189 input_sandbox_dir.mkdir(parents=
True, exist_ok=
False)
191 input_file = Path(input_sandbox_dir, f
"{i}.txt")
192 input_file.touch(exist_ok=
False)
194 self.
job1.input_sandbox_files.append(input_sandbox_dir)
196 self.
job1.working_dir.mkdir(parents=
True, exist_ok=
False)
197 self.
job1.copy_input_sandbox_files_to_working_dir()
201 expected_paths.append(Path(self.
job1.working_dir, test_script.name))
202 expected_paths.append(Path(self.
job1.working_dir,
"test_input_sandbox_dir"))
204 path = Path(self.
job1.working_dir,
"test_input_sandbox_dir", f
"{i}.txt")
205 expected_paths.append(path)
208 for p
in self.
job1.working_dir.rglob(
"*"):
209 self.assertIn(p, expected_paths)