예제 #1
0
def test_proctree_getallpaths_single():
    p1 = Proc()
    ProcTree.register(p1)
    pt = ProcTree()

    pt.setStarts([p1])
    assert list(pt.getAllPaths()) == [[p1]]
예제 #2
0
def test_proctree_check():
    p4 = Proc()
    p5 = Proc(id='p4')
    ProcTree.register(p4)
    ProcTree.register(p5)
    with pytest.raises(ProcTreeProcExists):
        ProcTree.check(p4)
예제 #3
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)
예제 #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 testGetPrevNextStr(self, procs, proc, which, out):
     for p in procs:
         ProcTree.register(p)
     ProcTree()
     if which == 'prev':
         self.assertEqual(ProcTree.getPrevStr(proc), out)
     else:
         self.assertEqual(ProcTree.getNextStr(proc), out)
예제 #6
0
def test_proctree_getnextstr():
    p8 = Proc()
    p9 = Proc()
    p9.depends = p8
    ProcTree.register(p8)
    ProcTree().init()
    assert ProcTree.getNextStr(p8) == '[p9]'
    assert ProcTree.getNextStr(p9) == 'END'
예제 #7
0
def test_proctree_getprevstr():
    p6 = Proc()
    p7 = Proc()
    p7.depends = p6
    ProcTree.register(p6)
    ProcTree().init()
    assert ProcTree.getPrevStr(p6) == 'START'
    assert ProcTree.getPrevStr(p7) == '[p6]'
예제 #8
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)
예제 #9
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)
예제 #10
0
 def testGetPaths(self, procs, proc, paths, exception=None):
     for p in procs:
         ProcTree.register(p)
     pt = ProcTree()
     if exception:
         self.assertRaises(ProcTreeParseError, pt.getPaths, proc)
     else:
         ps = pt.getPaths(proc)
         self.assertListEqual(ps, paths)
예제 #11
0
 def testReset(self, procs):
     for p in procs:
         ProcTree.register(p)
     ProcTree()
     ProcTree.reset()
     for node in ProcTree.NODES.values():
         self.assertListEqual(node.prev, [])
         self.assertListEqual(node.next, [])
         self.assertFalse(node.ran)
         self.assertFalse(node.start)
예제 #12
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)
예제 #13
0
 def testInit(self, procs):
     for p in procs:
         ProcTree.register(p)
     pt = ProcTree()
     self.assertEqual(pt.starts, [])
     self.assertEqual(pt.ends, [])
     for proc in procs:
         depends = proc.depends
         for depend in depends:
             nproc = ProcTree.NODES[proc]
             ndepend = ProcTree.NODES[depend]
             self.assertIn(nproc, ndepend.next)
             self.assertIn(ndepend, nproc.prev)
예제 #14
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)
예제 #15
0
def set1():
    p15 = Proc()
    p16 = Proc()
    p17 = Proc()
    p18 = Proc()
    p19 = Proc()
    p20 = Proc()
    #        hide
    # p15 -> p16  ->  p17 -> 19
    #         \_ p18_/  \_ p20
    #p16.hide = True
    p20.depends = p17
    p19.depends = p17
    p17.depends = p16, p18
    p18.depends = p16
    p16.depends = p15
    ProcTree.register(p15)
    return Box(p15=p15, p16=p16, p17=p17, p18=p18, p19=p19, p20=p20)
예제 #16
0
def test_proctree_getnext_and_reset():
    p10 = Proc()
    p11 = Proc()
    p11.depends = p10
    ProcTree.register(p10)
    ProcTree().init()
    assert ProcTree.getNext(p10) == [p11]
    assert ProcTree.getNext(p11) == []

    ProcTree.reset()
    ProcTree.NODES[p10].prev == []
    ProcTree.NODES[p10].next == []
    ProcTree.NODES[p11].prev == []
    ProcTree.NODES[p11].next == []
    ProcTree.NODES[p10].ran == False
    ProcTree.NODES[p10].start == False
    ProcTree.NODES[p11].ran == False
    ProcTree.NODES[p11].start == False
예제 #17
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()
예제 #18
0
def set2():
    p14 = Proc()
    p15 = Proc()
    p16 = Proc()
    p17 = Proc()
    p18 = Proc()
    p19 = Proc()
    p20 = Proc()
    # p15 -> p16  ->  p17 -> 19
    # p14 _/  \_ p18_/  \_ p20
    #           hide
    #p18.hide = True
    p20.depends = p17
    p19.depends = p17
    p17.depends = p16, p18
    p18.depends = p16
    p16.depends = p14, p15
    ProcTree.register(p14, p15)
    return Diot(p15=p15, p16=p16, p17=p17, p18=p18, p19=p19, p20=p20, p14=p14)
예제 #19
0
def test_proctree_init():
    p21 = Proc()
    p22 = Proc()
    p23 = Proc()
    p24 = Proc()
    p25 = Proc()
    p23.depends = p21, p22
    #p23.hide    = True
    p24.depends = p23
    p25.depends = p23
    ProcTree.register(p21)
    ProcTree.register(p22)

    pt = ProcTree()
    pt.init()
    # with pytest.raises(ProcHideError):
    # 	pt.init()
    assert p21 in ProcTree.NODES
    assert p22 in ProcTree.NODES
    assert p23 in ProcTree.NODES
    assert p24 in ProcTree.NODES
    assert p25 in ProcTree.NODES
    assert ProcTree.NODES[p21].prev == []
    assert ProcTree.NODES[p22].prev == []
    assert ProcTree.NODES[p23].prev == [
        ProcTree.NODES[p21], ProcTree.NODES[p22]
    ]
    assert ProcTree.NODES[p24].prev == [ProcTree.NODES[p23]]
    assert ProcTree.NODES[p25].prev == [ProcTree.NODES[p23]]
    assert ProcTree.NODES[p21].next == [ProcTree.NODES[p23]]
    assert ProcTree.NODES[p22].next == [ProcTree.NODES[p23]]
    assert ProcTree.NODES[p23].next == [
        ProcTree.NODES[p24], ProcTree.NODES[p25]
    ]
    assert ProcTree.NODES[p24].next == []
    assert ProcTree.NODES[p25].next == []
예제 #20
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]
예제 #21
0
def defprocs():
    ProcTree.NODES.clear()
    ret = Box(
        pAny2Procs1=Proc(),
        pAny2Procs2=Proc(),
        pAny2Procs3=Proc(),
        pAny2Procs4=Proc(),
        pAny2Procs51=Proc(tag='51', id='pAny2Procs5'),
        pAny2Procs52=Proc(tag='52', id='pAny2Procs5'),
        pAny2Procs6=Proc(),
        pAny2Procs7=Proc(),
    )
    ret.aAggr = ProcSet(ret.pAny2Procs6, ret.pAny2Procs7)
    ret.aAggr.starts = [ret.aAggr.pAny2Procs6, ret.aAggr.pAny2Procs7]
    ProcTree.register(ret.pAny2Procs1)
    ProcTree.register(ret.pAny2Procs2)
    ProcTree.register(ret.pAny2Procs3)
    ProcTree.register(ret.pAny2Procs4)
    ProcTree.register(ret.pAny2Procs51)
    ProcTree.register(ret.pAny2Procs52)
    return ret
예제 #22
0
 def testCheck(self, proc, r):
     ProcTree.register(proc)
     if r:
         self.assertRaises(ProcTreeProcExists, ProcTree.check, proc)
     else:
         ProcTree.check(proc)
예제 #23
0
 def testGetNext(self, procs, proc, outs):
     for p in procs:
         ProcTree.register(p)
     ProcTree()
     nexts = ProcTree.getNext(proc)
     self.assertCountEqual(nexts, outs)
예제 #24
0
 def testRegister(self, proc, l):
     ProcTree.register(proc)
     self.assertIs(ProcTree.NODES[proc].proc, proc)
     self.assertEqual(len(ProcTree.NODES), l)
예제 #25
0
 def testGetAllPaths(self, procs, starts, paths):
     for p in procs:
         ProcTree.register(p)
     pt = ProcTree()
     pt.setStarts(starts)
     self.assertCountEqual(pt.getAllPaths(), paths)
예제 #26
0
def test_proctree_register():
    p3 = Proc()
    ProcTree.register(p3)
    del ProcTree.NODES[p3]
    ProcTree.register(p3)
    assert ProcTree.NODES[p3].proc is p3