Ejemplo n.º 1
0
    def testStderr(self):
        b = FakeWorkerForBuilder(self.basedir)
        s = runprocess.RunProcess(b, stderrCommand("hello"), self.basedir)

        yield s.start()

        self.failIf({'stderr': nl('hello\n')} not in b.updates, b.show())
        self.assertTrue({'rc': 0} in b.updates, b.show())
Ejemplo n.º 2
0
    def testStart(self):
        b = FakeWorkerForBuilder(self.basedir)
        s = runprocess.RunProcess(b, stdoutCommand('hello'), self.basedir)

        yield s.start()

        self.assertTrue({'stdout': nl('hello\n')} in b.updates, b.show())
        self.assertTrue({'rc': 0} in b.updates, b.show())
Ejemplo n.º 3
0
    def testStderr(self):
        b = FakeWorkerForBuilder(self.basedir)
        s = runprocess.RunProcess(b, stderrCommand("hello"), self.basedir)

        yield s.start()

        self.failIf({'stderr': nl('hello\n')} not in b.updates, b.show())
        self.assertTrue({'rc': 0} in b.updates, b.show())
Ejemplo n.º 4
0
    def testStart(self):
        b = FakeWorkerForBuilder(self.basedir)
        s = runprocess.RunProcess(b, stdoutCommand('hello'), self.basedir)

        yield s.start()

        self.assertTrue({'stdout': nl('hello\n')} in b.updates, b.show())
        self.assertTrue({'rc': 0} in b.updates, b.show())
Ejemplo n.º 5
0
    def testInitialStdinUnicode(self):
        b = FakeWorkerForBuilder(self.basedir)
        s = runprocess.RunProcess(
            b, catCommand(), self.basedir, initialStdin=u'hello')

        yield s.start()

        self.assertTrue({'stdout': nl('hello')} in b.updates, b.show())
        self.assertTrue({'rc': 0} in b.updates, b.show())
Ejemplo n.º 6
0
    def testStringCommand(self):
        b = FakeWorkerForBuilder(self.basedir)
        # careful!  This command must execute the same on windows and UNIX
        s = runprocess.RunProcess(b, 'echo hello', self.basedir)

        yield s.start()

        self.assertTrue({'stdout': nl('hello\n')} in b.updates, b.show())
        self.assertTrue({'rc': 0} in b.updates, b.show())
Ejemplo n.º 7
0
    def testStringCommand(self):
        b = FakeWorkerForBuilder(self.basedir)
        # careful!  This command must execute the same on windows and UNIX
        s = runprocess.RunProcess(b, 'echo hello', self.basedir)

        yield s.start()

        self.assertTrue({'stdout': nl('hello\n')} in b.updates, b.show())
        self.assertTrue({'rc': 0} in b.updates, b.show())
Ejemplo n.º 8
0
    def testKeepStderr(self):
        b = FakeWorkerForBuilder(self.basedir)
        s = runprocess.RunProcess(
            b, stderrCommand("hello"), self.basedir, keepStderr=True)

        yield s.start()

        self.assertTrue({'stderr': nl('hello\n')} in b.updates, b.show())
        self.assertTrue({'rc': 0} in b.updates, b.show())
        self.assertEqual(s.stderr, nl('hello\n'))
Ejemplo n.º 9
0
    def testPipeString(self):
        b = FakeWorkerForBuilder(self.basedir)
        # this is highly contrived, but it proves the point.
        cmd = sys.executable + \
            ' -c "import sys; sys.stdout.write(\'b\\na\\n\')" | sort'
        s = runprocess.RunProcess(b, cmd, self.basedir)

        yield s.start()

        self.assertTrue({'stdout': nl('a\nb\n')} in b.updates, b.show())
        self.assertTrue({'rc': 0} in b.updates, b.show())
Ejemplo n.º 10
0
    def testPipeString(self):
        b = FakeWorkerForBuilder(self.basedir)
        # this is highly contrived, but it proves the point.
        cmd = sys.executable + \
            ' -c "import sys; sys.stdout.write(\'b\\na\\n\')" | sort'
        s = runprocess.RunProcess(b, cmd, self.basedir)

        yield s.start()

        self.assertTrue({'stdout': nl('a\nb\n')} in b.updates, b.show())
        self.assertTrue({'rc': 0} in b.updates, b.show())
Ejemplo n.º 11
0
    def testMultiWordStringCommand(self):
        b = FakeWorkerForBuilder(self.basedir)
        # careful!  This command must execute the same on windows and UNIX
        s = runprocess.RunProcess(b, 'echo Happy Days and Jubilation',
                                  self.basedir)

        # no quoting occurs
        exp = nl('Happy Days and Jubilation\n')
        yield s.start()

        self.assertTrue({'stdout': exp} in b.updates, b.show())
        self.assertTrue({'rc': 0} in b.updates, b.show())
Ejemplo n.º 12
0
    def testMultiWordStringCommand(self):
        b = FakeWorkerForBuilder(self.basedir)
        # careful!  This command must execute the same on windows and UNIX
        s = runprocess.RunProcess(b, 'echo Happy Days and Jubilation',
                                  self.basedir)

        # no quoting occurs
        exp = nl('Happy Days and Jubilation\n')
        yield s.start()

        self.assertTrue({'stdout': exp} in b.updates, b.show())
        self.assertTrue({'rc': 0} in b.updates, b.show())
Ejemplo n.º 13
0
    def testCommandMaxTime(self):
        b = FakeWorkerForBuilder(self.basedir)
        s = runprocess.RunProcess(b, sleepCommand(10), self.basedir, maxTime=5)
        clock = task.Clock()
        s._reactor = clock

        d = s.start()
        clock.advance(6)  # should knock out maxTime
        yield d

        self.assertTrue({'stdout': nl('hello\n')} not in b.updates, b.show())
        self.assertTrue({'rc': FATAL_RC} in b.updates, b.show())
Ejemplo n.º 14
0
    def testCommandMaxTime(self):
        b = FakeWorkerForBuilder(self.basedir)
        s = runprocess.RunProcess(b, sleepCommand(10), self.basedir, maxTime=5)
        clock = task.Clock()
        s._reactor = clock

        d = s.start()
        clock.advance(6)  # should knock out maxTime
        yield d

        self.assertTrue(
            {'stdout': nl('hello\n')} not in b.updates, b.show())
        self.assertTrue({'rc': FATAL_RC} in b.updates, b.show())
Ejemplo n.º 15
0
 def testSendBuffered(self):
     b = FakeWorkerForBuilder(self.basedir)
     s = runprocess.RunProcess(b, stdoutCommand('hello'), self.basedir)
     s._addToBuffers('stdout', 'hello ')
     s._addToBuffers('stdout', 'world')
     s._sendBuffers()
     self.assertEqual(b.updates, [{'stdout': 'hello world'}], b.show())
Ejemplo n.º 16
0
    def testMultiWordStringCommandQuotes(self):
        b = FakeWorkerForBuilder(self.basedir)
        # careful!  This command must execute the same on windows and UNIX
        s = runprocess.RunProcess(b, 'echo "Happy Days and Jubilation"',
                                  self.basedir)

        if runtime.platformType == "win32":
            # echo doesn't parse out the quotes, so they come through in the
            # output
            exp = nl('"Happy Days and Jubilation"\n')
        else:
            exp = nl('Happy Days and Jubilation\n')
        yield s.start()

        self.assertTrue({'stdout': exp} in b.updates, b.show())
        self.assertTrue({'rc': 0} in b.updates, b.show())
Ejemplo n.º 17
0
 def testSendBuffered(self):
     b = FakeWorkerForBuilder(self.basedir)
     s = runprocess.RunProcess(b, stdoutCommand('hello'), self.basedir)
     s._addToBuffers('stdout', 'hello ')
     s._addToBuffers('stdout', 'world')
     s._sendBuffers()
     self.assertEqual(b.updates, [{'stdout': 'hello world'}], b.show())
Ejemplo n.º 18
0
    def testMultiWordStringCommandQuotes(self):
        b = FakeWorkerForBuilder(self.basedir)
        # careful!  This command must execute the same on windows and UNIX
        s = runprocess.RunProcess(b, 'echo "Happy Days and Jubilation"',
                                  self.basedir)

        if runtime.platformType == "win32":
            # echo doesn't parse out the quotes, so they come through in the
            # output
            exp = nl('"Happy Days and Jubilation"\n')
        else:
            exp = nl('Happy Days and Jubilation\n')
        yield s.start()

        self.assertTrue({'stdout': exp} in b.updates, b.show())
        self.assertTrue({'rc': 0} in b.updates, b.show())
Ejemplo n.º 19
0
    def testTrickyArguments(self):
        # make sure non-trivial arguments are passed verbatim
        b = FakeWorkerForBuilder(self.basedir)

        args = [
            'Happy Days and Jubilation',  # spaces
            r'''!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~''',  # special characters
            '%PATH%',  # Windows variable expansions
            # Expansions get an argument of their own, because the Windows
            # shell doesn't treat % as special unless it surrounds a
            # variable name.
        ]

        s = runprocess.RunProcess(b, printArgsCommand() + args, self.basedir)
        yield s.start()

        self.assertTrue({'stdout': nl(repr(args))} in b.updates, b.show())
        self.assertTrue({'rc': 0} in b.updates, b.show())
Ejemplo n.º 20
0
    def testTrickyArguments(self):
        # make sure non-trivial arguments are passed verbatim
        b = FakeWorkerForBuilder(self.basedir)

        args = [
            'Happy Days and Jubilation',  # spaces
            r'''!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~''',  # special characters
            '%PATH%',  # Windows variable expansions
            # Expansions get an argument of their own, because the Windows
            # shell doesn't treat % as special unless it surrounds a
            # variable name.
        ]

        s = runprocess.RunProcess(b, printArgsCommand() + args, self.basedir)
        yield s.start()

        self.assertTrue({'stdout': nl(repr(args))} in b.updates, b.show())
        self.assertTrue({'rc': 0} in b.updates, b.show())
Ejemplo n.º 21
0
    def test_stdin_closed(self):
        b = FakeWorkerForBuilder(self.basedir)
        s = runprocess.RunProcess(b,
                                  scriptCommand('assert_stdin_closed'),
                                  self.basedir,
                                  # if usePTY=True, stdin is never closed
                                  usePTY=False,
                                  logEnviron=False)
        yield s.start()

        self.assertTrue({'rc': 0} in b.updates, b.show())
Ejemplo n.º 22
0
 def testInvalidUTF8(self):
     b = FakeWorkerForBuilder(self.basedir)
     b.unicode_encoding = "utf-8"
     s = runprocess.RunProcess(
         b, stderrCommand("hello"), self.basedir, sendStderr=True)
     pp = runprocess.RunProcessPP(s)
     INVALID_UTF8 = b"\xff"
     with self.assertRaises(UnicodeDecodeError):
         INVALID_UTF8.decode('utf-8')
     pp.outReceived(INVALID_UTF8)
     yield s.start()
     stdout = [up['stdout'] for up in b.updates if 'stdout' in up][0]
     # On Python < 2.7 bytes is used, on Python >= 2.7 unicode
     self.assertIn(stdout, (b'\xef\xbf\xbd', u'\ufffd'))
     self.assertTrue({'rc': 0} in b.updates, b.show())
Ejemplo n.º 23
0
    def test_incrementalDecoder(self):
        b = FakeWorkerForBuilder(self.basedir)
        b.unicode_encoding = "utf-8"
        s = runprocess.RunProcess(
            b, stderrCommand("hello"), self.basedir, sendStderr=True)
        pp = runprocess.RunProcessPP(s)
        # u"\N{SNOWMAN} when encoded to utf-8 bytes is b"\xe2\x98\x83"
        pp.outReceived(b"\xe2")
        pp.outReceived(b"\x98\x83")
        pp.errReceived(b"\xe2")
        pp.errReceived(b"\x98\x83")
        yield s.start()

        self.assertTrue({'stderr': u"\N{SNOWMAN}"} in b.updates)
        self.assertTrue({'stdout': u"\N{SNOWMAN}"} in b.updates)
        self.assertTrue({'rc': 0} in b.updates, b.show())
Ejemplo n.º 24
0
 def testSendStatus(self):
     b = FakeWorkerForBuilder(self.basedir)
     s = runprocess.RunProcess(b, stdoutCommand('hello'), self.basedir)
     s.sendStatus({'stdout': nl('hello\n')})
     self.assertEqual(b.updates, [{'stdout': nl('hello\n')}], b.show())
Ejemplo n.º 25
0
 def testSendStatus(self):
     b = FakeWorkerForBuilder(self.basedir)
     s = runprocess.RunProcess(b, stdoutCommand('hello'), self.basedir)
     s.sendStatus({'stdout': nl('hello\n')})
     self.assertEqual(b.updates, [{'stdout': nl('hello\n')}], b.show())