Esempio n. 1
0
 def testSplitPipe2(self):
     "tee into two pipeline of two sorts each "
     nopen = self.numOpenFiles()
     pd = ProcDag()
     inf = self.getInputFile("simple1.txt")
     outFwd = self.getOutputFile(".fwd.out")
     outRev = self.getOutputFile(".rev.out")
     fwd1 = Pipe()
     fwd2 = Pipe()
     rev1 = Pipe()
     rev2 = Pipe()
     # sort wrong direction, then sort again into final orders
     pd.create(("tee", POut(rev1)), stdin=inf, stdout=POut(fwd1))
     pd.create(("sort", "-r"), stdin=fwd1, stdout=fwd2)
     pd.create(("sort",), stdin=fwd2, stdout=outFwd)
     pd.create(("sort",), stdin=rev1, stdout=rev2)
     pd.create(("sort", "-r"), stdin=rev2, stdout=outRev)
     pd.wait()
     self.diffExpected(".fwd.out")
     self.diffExpected(".rev.out")
     self.commonChecks(
         nopen,
         pd,
         "^tee >\\(sort \\| sort -r >.+/output/procDagTests\\.ProcDagTests\\.testSplitPipe2\\.rev\\.out\\) <.+/input/simple1\\.txt \\| sort -r \\| sort >.+/output/procDagTests\\.ProcDagTests\\.testSplitPipe2\\.fwd\\.out$",
         isRe=True,
     )
Esempio n. 2
0
 def testTrivialFail(self):
     nopen = self.numOpenFiles()
     pd = ProcDag()
     pd.create(("false",))
     with self.assertRaises(ProcException) as cm:
         pd.wait()
     self.commonChecks(nopen, pd, "false")
Esempio n. 3
0
 def testJoinPipe2Uniq(self):
     "cat from two pipeline of two sorts each, results pipe to sort -u"
     if self.brokenOnOSX():
         return
     nopen = self.numOpenFiles()
     pd = ProcDag()
     inf = self.getInputFile("simple1.txt")
     outf = self.getOutputFile(".out")
     fwd1 = Pipe()
     fwd2 = Pipe()
     rev1 = Pipe()
     rev2 = Pipe()
     sortu = Pipe()
     # sort reverse direction, then sort again into final orders
     pd.create(("sort", "-r"), stdin=inf, stdout=fwd1)
     pd.create(("sort",), stdin=fwd1, stdout=fwd2)
     pd.create(("sort",), stdin=inf, stdout=rev1)
     pd.create(("sort", "-r"), stdin=rev1, stdout=rev2)
     pd.create(("cat", PIn(fwd2), PIn(rev2)), stdout=sortu)
     pd.create(("sort", "-u"), stdin=sortu, stdout=outf)
     pd.wait()
     self.diffExpected(".out")
     self.commonChecks(
         nopen,
         pd,
         "^cat <\\(sort -r <.+/input/simple1.txt \\| sort\\) <\\(sort <.+/input/simple1.txt \\| sort -r\\) \\| sort -u >.+/output/procDagTests\\.ProcDagTests\\.testJoinPipe2Uniq\\.out$",
         isRe=True,
     )
Esempio n. 4
0
 def testSimplePipe(self):
     nopen = self.numOpenFiles()
     pd = ProcDag()
     p = Pipe()
     pd.create(("true",), stdout=p)
     pd.create(("true",), stdin=p)
     pd.wait()
     self.commonChecks(nopen, pd, "true | true")
Esempio n. 5
0
 def testInArgNoOpen(self):
     "read from a pipe argument that doesn't get open"
     nopen = self.numOpenFiles()
     pd = ProcDag()
     dw = DataWriter("one\ntwo\nthree\n")
     pr = pd.create(("true", PIn(dw)), stdin="/dev/null")
     pd.wait()
     self.commonChecks(nopen, pd, "true [DataWriter] </dev/null")
Esempio n. 6
0
 def testOutArgNoOpen(self):
     "write to a pipe argument that doesn't get open"
     nopen = self.numOpenFiles()
     pd = ProcDag()
     dr = DataReader()
     pr = pd.create(("true", POut(dr)), stdin="/dev/null")
     pd.wait()
     self.commonChecks(nopen, pd, "true [DataWriter] </dev/null")
Esempio n. 7
0
 def testSimplePipeFail(self):
     nopen = self.numOpenFiles()
     pd = ProcDag()
     p = Pipe()
     pd.create(("false",), stdout=p)
     pd.create(("true",), stdin=p)
     with self.assertRaises(ProcException) as cm:
         pd.wait()
     self.commonChecks(nopen, pd, "false | true")
Esempio n. 8
0
 def testStdoutMem(self):
     "read from stdout into memory"
     nopen = self.numOpenFiles()
     pd = ProcDag()
     inf = self.getInputFile("simple1.txt")
     dr = DataReader()
     pd.create(("sort", "-r"), stdin=inf, stdout=dr)
     pd.wait()
     self.assertEqual(dr.get(), "two\nthree\nsix\none\nfour\nfive\n")
     self.commonChecks(nopen, pd, "^sort -r <.+/input/simple1\\.txt >\\[DataWriter\\]", isRe=True)
Esempio n. 9
0
 def testOutArgMem(self):
     "read from a pipe argument into memory"
     nopen = self.numOpenFiles()
     pd = ProcDag()
     inf = self.getInputFile("simple1.txt")
     dr = DataReader()
     pr = pd.create(("tee", POut(dr)), stdin=inf, stdout="/dev/null")
     pd.wait()
     self.assertEqual(dr.get(), "one\ntwo\nthree\nfour\nfive\nsix\n")
     self.commonChecks(nopen, pd, "^tee \\[DataWriter\\] <.+/input/simple1.txt >/dev/null$", isRe=True)
Esempio n. 10
0
 def testExecFail(self):
     "invalid executable"
     nopen = self.numOpenFiles()
     pd = ProcDag()
     dw = DataWriter("one\ntwo\nthree\n")
     pd.create(("procDoesNotExist", "-r"), stdin=dw)
     with self.assertRaises(ProcException) as cm:
         pd.wait()
     expect = "exec failed: procDoesNotExist -r,\n    caused by: OSError: [Errno 2] No such file or directory"
     msg = str(cm.exception)
     if not msg.startswith(expect):
         self.fail("'" + msg + "' does not start with '" + expect + "', cause: " + str(getattr(ex, "cause", None)))
     self.commonChecks(nopen, pd, "procDoesNotExist -r <[DataWriter]")
Esempio n. 11
0
 def testStdinMem(self):
     "write from memory to stdin"
     nopen = self.numOpenFiles()
     pd = ProcDag()
     dw = DataWriter("one\ntwo\nthree\n")
     outf = self.getOutputFile(".out")
     pd.create(("sort", "-r"), stdin=dw, stdout=outf)
     pd.wait()
     self.diffExpected(".out")
     self.commonChecks(
         nopen,
         pd,
         "^sort -r <\\[DataWriter\\] >.+/output/procDagTests\\.ProcDagTests\\.testStdinMem\\.out$",
         isRe=True,
     )
Esempio n. 12
0
 def testInArgMem(self):
     "write from memory to a pipe argument"
     if self.brokenOnOSX():
         return
     nopen = self.numOpenFiles()
     pd = ProcDag()
     dw = DataWriter("one\ntwo\nthree\n")
     outf = self.getOutputFile(".out")
     pr = pd.create(("sort", "-r", PIn(dw)), stdin="/dev/null", stdout=outf)
     pd.wait()
     self.diffExpected(".out")
     self.commonChecks(
         nopen,
         pd,
         "^sort -r \\[DataWriter\\] </dev/null >.+/output/procDagTests\\.ProcDagTests\\.testInArgMem\\.out$",
         isRe=True,
     )
Esempio n. 13
0
 def testArgToStdout(self):
     "pipe argument to stdout"
     nopen = self.numOpenFiles()
     pd = ProcDag()
     inf = self.getInputFile("simple1.txt")
     outf = self.getOutputFile(".out")
     io = Pipe()
     pd.create(("tee", POut(io)), stdin=inf, stdout="/dev/null")
     pd.create(("sort", "-r"), stdin=io, stdout=outf)
     pd.wait()
     self.diffExpected(".out")
     self.commonChecks(
         nopen,
         pd,
         "^tee >\\(sort -r >.+/output/procDagTests\\.ProcDagTests\\.testArgToStdout\\.out\\) <.+/input/simple1\\.txt >/dev/null$",
         isRe=True,
     )
Esempio n. 14
0
 def testStdoutToArg(self):
     "stdout to a pipe argument"
     if self.brokenOnOSX():
         return
     nopen = self.numOpenFiles()
     pd = ProcDag()
     inf = self.getInputFile("simple1.txt")
     outf = self.getOutputFile(".out")
     io = Pipe()
     pd.create(("cat", inf), stdout=io)
     pd.create(("sort", "-r", PIn(io)), stdin="/dev/null", stdout=outf)
     pd.wait()
     self.diffExpected(".out")
     self.commonChecks(
         nopen,
         pd,
         "^sort -r <\\(cat .+/input/simple1.txt\\) </dev/null >.+/output/procDagTests\\.ProcDagTests\\.testStdoutToArg\\.out$",
         isRe=True,
     )
Esempio n. 15
0
 def testStdioCycleDetect(self):
     "stdio cycle detection"
     nopen = self.numOpenFiles()
     pd = ProcDag()
     inf = self.getInputFile("simple1.txt")
     p1 = Pipe()
     p2 = Pipe()
     p3 = Pipe()
     p4 = Pipe()
     pd.create(("cat",), stdin=inf, stdout=p1)
     pd.create(("cat", "/dev/stdin", PIn(p4)), stdin=p1, stdout=p3)
     pd.create(("cat",), stdin=p3, stdout=p4)
     with self.assertRaises(ProcDagException) as cm:
         pd.wait()
     msg = str(cm.exception)
     expect = "cycle detected: entering: cat /dev/stdin <([Pipe])"
     if msg != expect:
         self.fail("'" + msg + "' != '" + expect + "'")
     self.commonChecks(nopen, pd, "{CYCLE}: cat ; cat ; cat /dev/stdin <([Pipe])")
Esempio n. 16
0
 def testSplitPipe(self):
     "tee into two sorts"
     nopen = self.numOpenFiles()
     pd = ProcDag()
     inf = self.getInputFile("simple1.txt")
     outFwd = self.getOutputFile(".fwd.out")
     outRev = self.getOutputFile(".rev.out")
     fwd = Pipe()
     rev = Pipe()
     pd.create(("tee", POut(rev)), stdin=inf, stdout=POut(fwd))
     pd.create(("sort",), stdin=fwd, stdout=outFwd)
     pd.create(("sort", "-r"), stdin=rev, stdout=outRev)
     pd.wait()
     self.diffExpected(".fwd.out")
     self.diffExpected(".rev.out")
     self.commonChecks(
         nopen,
         pd,
         "^tee >\\(sort -r >.+/output/procDagTests\\.ProcDagTests\\.testSplitPipe\\.rev\\.out\\) <.+/input/simple1\\.txt \\| sort >.+/output/procDagTests\\.ProcDagTests\\.testSplitPipe\\.fwd\\.out$",
         isRe=True,
     )
Esempio n. 17
0
 def testArgToArg(self):
     "pipe argument to argument of another process"
     if self.brokenOnOSX():
         return
     nopen = self.numOpenFiles()
     pd = ProcDag()
     inf = self.getInputFile("simple1.txt")
     outf = self.getOutputFile(".out")
     io = Pipe()
     pd.create(("tee", POut(io)), stdin=inf, stdout="/dev/null")
     pd.create(("cat", PIn(io)), stdin="/dev/null", stdout=outf)
     pd.wait()
     self.diffExpected(".out")
     # formatting fails here: (FIXME: improve??), FIXME: doesn't always produce same result,
     # so we check multiple posibilities
     self.commonChecks(
         nopen,
         pd,
         "(^tee >\\(cat <\\(tee \\.\\.\\.\\) </dev/null >.+/output/procDagTests\\.ProcDagTests\\.testArgToArg\\.out\\) <.+/input/simple1\\.txt >/dev/null ; cat \\.\\.\\.$)"
         + "|(^tee >\\(cat <\\(tee \\.\\.\\.\\) </dev/null >.+/output/procDagTests\\.ProcDagTests\\.testArgToArg\\.out\\) <.+/input/simple1\\.txt >/dev/null ; cat \\.\\.\\.$)"
         + "|(^cat <\\(tee >\\(cat \\.\\.\\.\\) <.+/input/simple1\\.txt >/dev/null\\) </dev/null >.+/output/procDagTests\\.ProcDagTests\\.testArgToArg\\.out ; tee \\.\\.\\.)",
         isRe=True,
     )
Esempio n. 18
0
 def testTrivial(self):
     nopen = self.numOpenFiles()
     pd = ProcDag()
     pd.create(("true",))
     pd.wait()
     self.commonChecks(nopen, pd, "true")