Exemple #1
0
    def testCapture(self):
        stdoutValue = "stdout"
        stderrValue = "stderr"

        def func():
            print(stdoutValue, file=sys.stdout, end="")
            print(stderrValue, file=sys.stderr, end="")

        stdout, stderr = utils.captureOutput(func)
        self.assertEqual(stdout, stdoutValue)
        self.assertEqual(stderr, stderrValue)

        # Empty stdout
        def func():
            print(stderrValue, file=sys.stderr, end="")

        stdout, stderr = utils.captureOutput(func)
        self.assertEqual(stdout, "")
        self.assertEqual(stderr, stderrValue)

        # Empty stderr
        def func():
            print(stdoutValue, file=sys.stdout, end="")

        stdout, stderr = utils.captureOutput(func)
        self.assertEqual(stdout, stdoutValue)
        self.assertEqual(stderr, "")
Exemple #2
0
 def testArgs(self):
     def func(one, two, three, keywordOne=None, keywordTwo=None):
         print(one, two, three, keywordOne, keywordTwo, file=sys.stdout)
     stdout, stderr = utils.captureOutput(
         func, "1", "2", "3", keywordTwo="5", keywordOne="4")
     self.assertEqual(stdout, "1 2 3 4 5\n")
     self.assertEqual(stderr, "")
Exemple #3
0
 def captureCliOutput(self, command, arguments, outputFormat):
     clientCommand = "{} {} {} -O {}".format(command, self._dataUrl,
                                             arguments, outputFormat)
     stdout, stderr = utils.captureOutput(cli_client.client_main,
                                          clientCommand.split())
     self.assertEqual(len(stderr), 0)
     return stdout
Exemple #4
0
 def captureCliOutput(self, command, arguments, outputFormat):
     clientCommand = "{} {} {} -O {}".format(
         command, self._dataUrl, arguments, outputFormat)
     stdout, stderr = utils.captureOutput(
         cli_client.client_main, clientCommand.split())
     self.assertEqual(len(stderr), 0)
     return stdout