示例#1
0
 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)
示例#2
0
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
示例#3
0
def test_proctree_getallpaths_single():
    p1 = Proc()
    ProcTree.register(p1)
    pt = ProcTree()

    pt.setStarts([p1])
    assert list(pt.getAllPaths()) == [[p1]]
示例#4
0
 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)
示例#5
0
 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)
示例#6
0
 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)
示例#7
0
 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)
示例#8
0
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
示例#9
0
 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)
示例#10
0
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 = []
示例#11
0
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
示例#12
0
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()
示例#13
0
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],
    ]
示例#14
0
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]
示例#15
0
 def testGetAllPaths(self, procs, starts, paths):
     for p in procs:
         ProcTree.register(p)
     pt = ProcTree()
     pt.setStarts(starts)
     self.assertCountEqual(pt.getAllPaths(), paths)