class MyTaskB(SimpleTask): outputs = File(TEST_DIR, 'out_B.txt') inputs = File(TEST_DIR, 'in_B.txt') def run(self): self.inputs.open('r').read() self.outputs.open('w').write('yo')
class MyTask(SimpleTask): outputs = { 'A': File(TEST_DIR, 'a.txt'), 'B': File(TEST_DIR, 'b.txt') } def run(self): self.outputs['A'].open('w').write('yes') self.outputs['B'].open('w').write('yes')
class MyTask(SimpleTask): outputs = { 'A': File(TEST_DIR, 'out_A.txt', static=True), 'B': File(TEST_DIR, 'out_B.txt'), } inputs = { 'A': File(TEST_DIR, 'in_A.txt', static=True), 'B': File(TEST_DIR, 'in_B.txt') } def run(self): self.inputs['A'].open('r').read() self.inputs['B'].open('r').read() self.outputs['A'].open('w').write('yo') self.outputs['B'].open('w').write('yo')
def test_resource_inheritance(self): # a Resource's clobber flag is set by get_ready my_file = File('.', 'file.txt') my_file.get_ready(lot='my_lot', pilot=False, name='name', clobber=True) self.assertTrue(my_file.get_clobber()) # it's overriden by instantiation keyword argument self.assertTrue(File('.', 'file.txt', clobber=True).get_clobber()) # instantiation gets the last word my_file = File('.', 'file.txt', clobber=True) my_file.get_ready(lot='my_lot', pilot=False, name='name', clobber=False) self.assertTrue(my_file.get_clobber()) # instantiation gets the last word my_file = File('.', 'file.txt', clobber=False) my_file.get_ready(lot='my_lot', pilot=False, name='name', clobber=True) self.assertFalse(my_file.get_clobber()) class MyFile(File): clobber = True # this resource clobbers by default self.assertTrue(MyFile('.', 'file.txt').get_clobber()) # that behavior is overriden by instantiation keyword argument self.assertFalse(MyFile('.', 'file.txt', clobber=False).get_clobber()) # it's not overridden by argument passed to get_ready my_file = MyFile('.', 'file.txt') my_file.get_ready(lot='my_lot', pilot=False, name='name', clobber=False) self.assertTrue(my_file.get_clobber()) class MyFile(File): clobber = False # this resource does not clobber by default self.assertFalse(MyFile('.', 'file.txt').get_clobber()) # that behavior is overriden by instantiation keyword argument self.assertTrue(MyFile('.', 'file.txt', clobber=True).get_clobber()) # it's not overridden by argument passed to get_ready my_file = MyFile('.', 'file.txt') my_file.get_ready(lot='my_lot', pilot=False, name='name', clobber=True) self.assertFalse(my_file.get_clobber())
def _outputs(self): fname = 'test%d.txt' % self.parameters['file_num'] return File(TEST_DIR, fname)