def test_find_bdp(self): project = admit.Project() # add one task task = admit.File_AT(touch=True) name = "File.dat" task.setkey("file", name) project.addtask(task) # add task # now add an output bdp obdp = admit.File_BDP('Test') task.addoutput(obdp) self.p.addtask(task) # find_bdp() will search Admit output data directory for *.bdp files # should return an empty list since no *.bdp file created by this test ret = self.p.find_bdp() outdir = self.p.dir() if (self.verbose): if len(ret): print "Found BDPs in", outdir else: print "No BDPs Found in", outdir self.assertTrue(len(ret) == 0)
def test_flow2(self): # Construct a flow: File_AT -> Flow11_AT -> Flow1N_AT # add first task task1 = admit.File_AT(touch=True) tid1 = self.fm.add(task1) bdp = admit.File_BDP() task1.addoutput(bdp) # add second task task2 = admit.Flow11_AT() task2.setkey("file", "Flow11.dat") tid2 = self.fm.add(task2, [(tid1, 0)]) # add third task task3 = admit.Flow1N_AT() task3.setkey("file", "Flow1N.dat") tid3 = self.fm.add(task3, [(tid2, 0)]) task4 = admit.FlowMN_AT() # test inFlow() found = self.fm.inFlow(task1) self.assertTrue(found) # should be true # test downstream of tid2 (including tid2) dstream = self.fm.downstream(tid2) self.assertEquals(dstream, set([tid2, tid3])) # test stale() for ds in dstream: isStale = self.fm._tasks[ds].isstale() # check before mark if isStale: self.fm._tasks[ds].markUpToDate() isStale = self.fm._tasks[ds].isstale() # check after mark self.assertFalse(isStale) # should not be stale self.fm.stale(tid2) # call stale() # after calling stale() for ds in dstream: isStale = self.fm._tasks[ds].isstale() self.assertTrue( isStale) # all ATs in downstream should be stale now # clone from tid2 (Flow11_AT) in the flow cloned = self.fm.clone(tid2) if (self.verbose): self.fm.show()
def test_FM_getsetdelitem(self): """ test FM __getitem__, __setitem__, __delitem__ """ # test add(), connectInputs(), verify(), and show() #__getitem__(), __delitem__(), __setitem__() fm = admit.Flow() # add first task task1 = admit.File_AT(touch=True) tid1 = fm.add(task1) bdp = admit.File_BDP() task1.addoutput(bdp) # add another task task2 = admit.Flow11_AT() task2.setkey("file", "Flow11.dat") tid2 = fm.add(task2, [(tid1, 0)]) # test connectInputs fm.connectInputs() # check the number of tasks self.assertEqual(len(fm), 2) # first task (File_AT) # fm[tid1] # call __getitem__ self.assertIsInstance(fm[tid1], admit.File_AT) # second task (Flow11_AT) # fm[tid2] # call __getitem__ self.assertIsInstance(fm[tid2], admit.Flow11_AT) # test __setitem__ newtask = admit.FlowMN_AT() newtask.setkey("file", "FlowMN.txt") fm[tid2] = newtask # call __setitem__ # check to see if task2 got overwritten self.assertIsInstance(fm[tid2], admit.FlowMN_AT) # now restore Flow11_AT fm[tid2] = task2 # call __setitem__ self.assertIsInstance(fm[tid2], admit.Flow11_AT) # test __delitem__ (delete Flow11) at = fm[tid2] del fm[tid2] # call __delitem__ self.assertEqual(len(fm), 1) # Add task back. fm[tid2] = at # call __setitem__ # test verify() self.assertTrue(fm.verify())
def test_Project_find_bdp(self): """ test find_bdp() """ project = Project() # add one task task = admit.File_AT(touch=True) name = "File.dat" task.setkey("file", name) project.addtask(task) # add task # now add an output bdp obdp = admit.File_BDP('Test') task.addoutput(obdp) self.project.addtask(task) # find_bdp() will search Admit output data directory for *.bdp files # should return an empty list since no *.bdp file created by this test ret = self.project.find_bdp() self.assertTrue(len(ret) == 0)
def test_FM_inFlow_downstream(self): """ test FM inFlow(), downstream(), stale(), clone() """ fm = admit.Flow() # Construct a flow: File_AT -> Flow11_AT -> Flow1N_AT # add first task task1 = admit.File_AT(touch=True) tid1 = fm.add(task1) bdp = admit.File_BDP() task1.addoutput(bdp) # add second task task2 = admit.Flow11_AT() tid2 = fm.add(task2, [(tid1, 0)]) task2.setkey("file", "Flow11.dat") # add third task task3 = admit.Flow1N_AT() tid3 = fm.add(task3, [(tid2, 0)]) task3.setkey("file", "Flow1N.dat") # test inFlow() self.assertTrue(fm.inFlow(task1)) # test downstream of tid2 (including tid2) dstream = fm.downstream(tid2) self.assertEquals(dstream, set([tid2, tid3])) # test stale() for ds in dstream: isStale = fm._tasks[ds].isstale() # check before mark if isStale: fm._tasks[ds].markUpToDate() isStale = fm._tasks[ds].isstale() # check after mark self.assertFalse(isStale) # should not be stale fm.stale(tid2) # all ATs in downstream should be stale now for ds in dstream: self.assertTrue(fm._tasks[ds].isstale()) # clone from tid2 (Flow11_AT) in the flow cloned_tid = fm.clone(tid2) self.assertEqual(cloned_tid, 3)
def test_task2(self): # add first task task1 = admit.File_AT(touch=True) tid1 = self.fm.add(task1) bdp = admit.File_BDP() task1.addoutput(bdp) # add another task task2 = admit.Flow11_AT() task2.setkey("file", "Flow11.dat") tid2 = self.fm.add(task2, [(tid1, 0)]) # test connectInputs self.fm.connectInputs() num = len(self.fm) # should be 2 self.assertTrue(num == 2) if (self.verbose): print "The number of tasks in flow:", num print "The task IDs:", tid1, tid2 # first task (File_AT) t1 = self.fm[tid1] # call __getitem__ type = isinstance(t1, admit.File_AT) if (self.verbose): print "After call __getitem__", t1.id() self.assertTrue(type) # second task (Flow11_AT) t2 = self.fm[tid2] # call __getitem__ type = isinstance(t2, admit.Flow11_AT) if (self.verbose): print "After call __getitem__", t2.id() self.assertTrue(type) # test __setitem__ newtask = admit.FlowMN_AT() newtask.setkey("file", "FlowMN.txt") self.fm[tid2] = newtask # call __setitem__ if (self.verbose): self.fm.show() # check to see if task2 got overwritten t2 = self.fm[tid2] type = isinstance(t2, admit.FlowMN_AT) self.assertTrue(type) # now restore Flow11_AT self.fm[tid2] = task2 # call __setitem__ if (self.verbose): self.fm.show() # check it again t2 = self.fm[tid2] type = isinstance(t2, admit.Flow11_AT) self.assertTrue(type) # test __delitem__ (delete Flow11) at = self.fm[tid2] del self.fm[tid2] # call __delitem__ num = len(self.fm) # should be 1 now self.assertTrue(num == 1) # Add task back. self.fm[tid2] = at # call __setitem__ # test verify() check = self.fm.verify() self.assertTrue(check)