def testGetPathsToStarts(self, procs, starts, proc, paths): for p in procs: ProcTree.register(p) pt = ProcTree() pt.setStarts(starts) ps = pt.getPathsToStarts(proc) self.assertListEqual(ps, paths)
def test_proctree_getnexttorun(set2): # p15 -> p16 -> p17 -> 19 # p14 _/ \_ p18_/ \_ p20 # hide p1 = Proc() #ProcTree.register(p1) p2 = Proc() p2.depends = p1 pt = ProcTree() pt.init() pt.setStarts([set2.p14, set2.p15]) pt.NODES[set2.p14].ran = True assert pt.getNextToRun() is set2.p15 pt.NODES[set2.p15].ran = True assert pt.getNextToRun() is set2.p16 pt.NODES[set2.p16].ran = True assert pt.getNextToRun() is set2.p18 pt.NODES[set2.p18].ran = True assert pt.getNextToRun() is set2.p17 pt.NODES[set2.p17].ran = True assert pt.getNextToRun() is set2.p20 pt.NODES[set2.p20].ran = True assert pt.getNextToRun() is set2.p19 pt.NODES[set2.p19].ran = True assert pt.getNextToRun() is None
def test_proctree_getallpaths_single(): p1 = Proc() ProcTree.register(p1) pt = ProcTree() pt.setStarts([p1]) assert list(pt.getAllPaths()) == [[p1]]
def testGetNextToRun(self, procs, starts, haveran, out): for p in procs: ProcTree.register(p) pt = ProcTree() pt.setStarts(starts) for hr in haveran: ProcTree.NODES[hr].ran = True self.assertIs(pt.getNextToRun(), out)
def testGetEnds(self, procs, starts, ends, exception=None, msg=None): for p in procs: ProcTree.register(p) pt = ProcTree() pt.setStarts(starts) if exception: self.assertRaisesRegex(ProcTreeParseError, msg, pt.getEnds) else: self.assertCountEqual(pt.getEnds(), ends)
def testCheckPath(self, procs, starts, proc, passed): for p in procs: ProcTree.register(p) pt = ProcTree() pt.setStarts(starts) if isinstance(passed, bool): self.assertEqual(pt.checkPath(proc), passed) else: self.assertListEqual(pt.checkPath(proc), passed)
def testUnranProcs(self, procs, starts, outs): for p in procs: ProcTree.register(p) pt = ProcTree() pt.setStarts(starts) # run the pipeline p = pt.getNextToRun() while p: ProcTree.NODES[p].ran = True p = pt.getNextToRun() self.assertDictEqual(pt.unranProcs(), outs)
def test_proctree_chechpath(set2): # p15 -> p16 -> p17 -> 19 # p14 _/ \_ p18_/ \_ p20 # hide pt = ProcTree() pt.init() assert pt.checkPath(set2.p16) == [set2.p14] pt.setStarts([set2.p14]) assert pt.checkPath(set2.p16) == [set2.p15] pt.setStarts([set2.p14, set2.p15]) assert pt.checkPath(set2.p16) is True
def testSetGetStarts(self, procs, starts): for p in procs: ProcTree.register(p) pt = ProcTree() pt.setStarts(starts) for proc in procs: if proc in starts: self.assertTrue(ProcTree.NODES[proc].start) else: self.assertFalse(ProcTree.NODES[proc].start) s = pt.getStarts() self.assertCountEqual(s, starts) self.assertCountEqual(pt.starts, starts)
def test_proctree_getends(set2): # p15 -> p16 -> p17 -> 19 # p14 _/ \_ p18_/ \_ p20 # hide pt = ProcTree() pt.init() pt.setStarts([set2.p14, set2.p15]) assert set(pt.getEnds()) == {set2.p19, set2.p20} assert set(pt.ends) == {set2.p19, set2.p20} assert set(pt.getEnds()) == {set2.p19, set2.p20} #set2.p19.hide = True pt.ends = []
def test_proctree_getallpaths(set2): # p15 -> p16 -> p17 -> 19 # p14 _/ \_ p18_/ \_ p20 # ##hide moved to plugin pt = ProcTree() pt.init() pt.setStarts([set2.p14, set2.p15]) allpath = list(pt.getAllPaths()) assert len(allpath) == 8 assert [set2.p19, set2.p17, set2.p16, set2.p14] in allpath assert [set2.p19, set2.p17, set2.p16, set2.p15] in allpath assert [set2.p20, set2.p17, set2.p16, set2.p14] in allpath assert [set2.p20, set2.p17, set2.p16, set2.p15] in allpath assert [set2.p19, set2.p17, set2.p18, set2.p16, set2.p14] in allpath assert [set2.p19, set2.p17, set2.p18, set2.p16, set2.p15] in allpath assert [set2.p20, set2.p17, set2.p18, set2.p16, set2.p14] in allpath assert [set2.p20, set2.p17, set2.p18, set2.p16, set2.p15] in allpath
def test_proctree_getends_failed(): p1 = Proc() p2 = Proc() p2.depends = p1 ProcTree.register(p1) pt = ProcTree() pt.init() with pytest.raises(ProcTreeParseError): #Failed to determine end processes by start processes pt.getEnds() p3 = Proc() p3.depends = p2 pt = ProcTree() pt.init() pt.setStarts([p3]) with pytest.raises(ProcTreeParseError): # Failed to determine end processes, one of the paths cannot go through: 'p3 <- p2 <- p1' pt.getEnds()
def test_proctree_getpathstostarts(set2): # p15 -> p16 -> p17 -> 19 # p14 _/ \_ p18_/ \_ p20 # hide pt = ProcTree() pt.init() pt.setStarts([set2.p15]) assert pt.getPathsToStarts(set2.p15) == [] assert pt.getPathsToStarts( set2.p19) == [[set2.p17, set2.p16, set2.p15], [set2.p17, set2.p18, set2.p16, set2.p15]] assert pt.getPathsToStarts( set2.p20) == [[set2.p17, set2.p16, set2.p15], [set2.p17, set2.p18, set2.p16, set2.p15]] # assert pt.getPathsToStarts(set2.p19, check_hide = True) == [[set2.p17, set2.p16, set2.p15]] # assert pt.getPathsToStarts(set2.p20, check_hide = True) == [[set2.p17, set2.p16, set2.p15]] pt.setStarts([set2.p14, set2.p15]) assert pt.getPathsToStarts(set2.p14) == [] assert pt.getPathsToStarts(set2.p15) == [] assert pt.getPathsToStarts(set2.p16) == [[set2.p14], [set2.p15]] assert pt.getPathsToStarts(set2.p18) == [[set2.p16, set2.p14], [set2.p16, set2.p15]] assert pt.getPathsToStarts(set2.p17) == [ [set2.p16, set2.p14], [set2.p16, set2.p15], [set2.p18, set2.p16, set2.p14], [set2.p18, set2.p16, set2.p15], ] assert pt.getPathsToStarts(set2.p19) == [ [set2.p17, set2.p16, set2.p14], [set2.p17, set2.p16, set2.p15], [set2.p17, set2.p18, set2.p16, set2.p14], [set2.p17, set2.p18, set2.p16, set2.p15], ] assert pt.getPathsToStarts(set2.p20) == [ [set2.p17, set2.p16, set2.p14], [set2.p17, set2.p16, set2.p15], [set2.p17, set2.p18, set2.p16, set2.p14], [set2.p17, set2.p18, set2.p16, set2.p15], ]
def test_proctree_setgetstarts(): p12 = Proc() p13 = Proc() p14 = Proc() #p14.hide = True p12.depends = p13 ProcTree.register(p13) ProcTree.register(p14) pt = ProcTree() pt.init() # with pytest.raises(ProcHideError): # pt.setStarts([p14]) pt.ends = [1, 2, 3] pt.setStarts([p13]) assert ProcTree.NODES[p12].start == False assert ProcTree.NODES[p13].start == True assert ProcTree.NODES[p14].start == False assert pt.starts == [p13] assert pt.ends == [] pt.starts = [] assert pt.getStarts() == [p13] assert pt.starts == [p13] assert pt.getStarts() == [p13]
def testGetAllPaths(self, procs, starts, paths): for p in procs: ProcTree.register(p) pt = ProcTree() pt.setStarts(starts) self.assertCountEqual(pt.getAllPaths(), paths)