Exemple #1
0
 def test_output_is_redirected(self):
     self.stdout = 'stdout'
     self.stderr = 'stderr'
     service.capture_exceptions_stdout_stderr()
     # These would raise exceptions if not replaced by the above call.
     print >>self.stdout, 'test stdout'
     print >>self.stderr, 'test stderr'
Exemple #2
0
    def test_stderr_calls_us(self):
        self.stdout = 'stdout'
        self.stderr = 'stderr'
        calls = []

        def _stderr(*args):
            calls.append(args)

        service.capture_exceptions_stdout_stderr(stderr_func=_stderr)
        self.assertEquals(len(calls), 0)
        print >>self.stderr, 'test'
        self.assertEquals(calls, [('test\n',)])
Exemple #3
0
    def test_excepthook_calls_us(self):
        self.stdout = 'stdout'
        self.stderr = 'stderr'
        calls = []

        def _exc(*args):
            calls.append(args)

        service.capture_exceptions_stdout_stderr(_exc)
        self.assertEquals(len(calls), 0)
        self.excepthook(1, 2, 3)
        self.assertEquals(calls, [(1, 2, 3)])
Exemple #4
0
    def test_ignores_dup2_exceptions(self):
        self.stdout = open(devnull, 'wb')
        self.stderr = open(devnull, 'wb')

        def _dup2(*args):
            raise OSError()

        orig_dup2 = service.dup2
        try:
            service.dup2 = _dup2
            service.capture_exceptions_stdout_stderr()
        finally:
            service.dup2 = orig_dup2
Exemple #5
0
    def test_writelines(self):
        self.stdout = 'stdout'
        self.stderr = 'stderr'
        calls = []

        def _stdout(*args):
            calls.append(args)

        service.capture_exceptions_stdout_stderr(stdout_func=_stdout)
        self.assertEquals(len(calls), 0)
        self.stdout.writelines(['abc\n', 'def', 'ghi\n', 'jkl'])
        self.assertEquals(calls, [('abc\ndefghi\n',)])
        self.stdout.flush()
        self.assertEquals(calls, [('abc\ndefghi\n',), ('jkl',)])
Exemple #6
0
    def test_combine_writes(self):
        self.stdout = 'stdout'
        self.stderr = 'stderr'
        calls = []

        def _stdout(*args):
            calls.append(args)

        service.capture_exceptions_stdout_stderr(stdout_func=_stdout)
        self.assertEquals(len(calls), 0)
        print >>self.stdout, 'test',
        self.assertEquals(calls, [])
        print >>self.stdout, 'and more'
        self.assertEquals(calls, [('test and more\n',)])
Exemple #7
0
    def test_close_just_flushes(self):
        self.stdout = 'stdout'
        self.stderr = 'stderr'
        calls = []

        def _stdout(*args):
            calls.append(args)

        service.capture_exceptions_stdout_stderr(stdout_func=_stdout)
        self.assertEqual(len(calls), 0)
        print >>self.stdout, 'test',
        self.assertEqual(calls, [])
        self.stdout.close()
        self.assertEqual(calls, [('test',)])
        print >>self.stdout, 'and more'
        self.assertEqual(calls, [('test',), (' and more\n',)])
Exemple #8
0
    def test_calls_flush_dup2_on_standard_io(self):

        class FakeFile(object):

            def __init__(self, fileno):
                self._fileno = fileno
                self._flush_calls = 0

            def fileno(self):
                return self._fileno

            def flush(self):
                self._flush_calls += 1

        self.stdout = stdout = FakeFile(456)
        self.stderr = stderr = FakeFile(789)
        service.capture_exceptions_stdout_stderr()
        self.assertEquals(set([b for a, b in self.dup2calls]),
                          set([stdout.fileno(), stderr.fileno()]))
        self.assertEquals(stdout._flush_calls, 1)
        self.assertEquals(stderr._flush_calls, 1)
Exemple #9
0
 def test_excepthook_is_set(self):
     self.excepthook = 'excepthook'
     self.stdout = 'stdout'
     self.stderr = 'stderr'
     service.capture_exceptions_stdout_stderr()
     self.assertNotEquals(self.excepthook, 'excepthook')
Exemple #10
0
 def test_does_not_call_dup2_on_things_not_understood(self):
     self.stdout = 'stdout'
     self.stderr = 'stderr'
     service.capture_exceptions_stdout_stderr()
     self.assertEquals(len(self.dup2calls), 0)