Exemple #1
0
    def execute_cmd_capture(self, cmd, expected_out, expected_err):
        """Run a single command, captures the output and and stderr and compare it to the expected ones"""
        sys_stdout, sys_stderr = sys.stdout, sys.stderr
        sys.stdout = p3._fake_stdio(
            additional_out=sys_stdout if PRINT_OUTPUT else None)
        sys.stderr = p3._fake_stdio(
            additional_out=sys_stderr if PRINT_OUTPUT else None)

        try:
            pubs_cmd.execute(cmd)
        finally:
            # capturing output even if exception was raised.
            self.captured_stdout = self.normalize(
                p3._get_fake_stdio_ucontent(sys.stdout))
            self.captured_stderr = self.normalize(
                p3._get_fake_stdio_ucontent(sys.stderr))
            sys.stderr, sys.stdout = sys_stderr, sys_stdout

        if expected_out is not None:
            self.assertEqual(p3.u_maybe(self.captured_stdout),
                             p3.u_maybe(expected_out))
        if expected_err is not None:
            self.assertEqual(p3.u_maybe(self.captured_stderr),
                             p3.u_maybe(expected_err))
        return self.captured_stdout
Exemple #2
0
 def newf(*args, **kwargs):
     old_stderr, old_stdout = sys.stderr, sys.stdout
     sys.stdout = _fake_stdio(additional_out=old_stderr if verbose else None)
     sys.stderr = _fake_stdio(additional_out=old_stderr if False else None)
     try:
         return f(*args, **kwargs), _get_fake_stdio_ucontent(sys.stdout), _get_fake_stdio_ucontent(sys.stderr)
     finally:
         sys.stderr, sys.stdout = old_stderr, old_stdout
Exemple #3
0
 def newf(*args, **kwargs):
     old_stderr, old_stdout = sys.stderr, sys.stdout
     stdout = _fake_stdio()
     stderr = _fake_stdio()
     sys.stdout, sys.stderr = stdout, stderr
     try:
         return f(*args, **kwargs), _get_fake_stdio_ucontent(stdout), _get_fake_stdio_ucontent(stderr)
     finally:
         sys.stderr, sys.stdout = old_stderr, old_stdout
Exemple #4
0
 def newf(*args, **kwargs):
     old_stderr, old_stdout = sys.stderr, sys.stdout
     sys.stdout = _fake_stdio(
         additional_out=old_stderr if verbose else None)
     sys.stderr = _fake_stdio(additional_out=old_stderr if False else None)
     try:
         return f(*args, **kwargs), _get_fake_stdio_ucontent(
             sys.stdout), _get_fake_stdio_ucontent(sys.stderr)
     finally:
         sys.stderr, sys.stdout = old_stderr, old_stdout
Exemple #5
0
 def newf(*args, **kwargs):
     old_stderr, old_stdout = sys.stderr, sys.stdout
     stdout = _fake_stdio()
     stderr = _fake_stdio()
     sys.stdout, sys.stderr = stdout, stderr
     try:
         return f(*args, **kwargs), _get_fake_stdio_ucontent(
             stdout), _get_fake_stdio_ucontent(stderr)
     finally:
         sys.stderr, sys.stdout = old_stderr, old_stdout