Ejemplo n.º 1
0
def quickfix_reporter():
    """QuickFixReporter"""

    with attest.capture_output() as (out, err):
        with Assert.raises(SystemExit):
            _meta.suite.run(attest.QuickFixReporter)

    assert out == ['%s:%d: TestFailure' % (SOURCEFILE, LINENO)]
Ejemplo n.º 2
0
def quickfix_reporter():
    """QuickFixReporter"""

    with attest.capture_output() as (out, err):
        with Assert.raises(SystemExit):
            _meta.suite.run(attest.QuickFixReporter)

    assert out == ['%s:%d: TestFailure' % (SOURCEFILE, LINENO)]
Ejemplo n.º 3
0
def capture():
    """capture_output()"""

    stdout, stderr = sys.stdout, sys.stderr

    with attest.capture_output() as (out, err):
        print 'Capture the flag!'
        print >> sys.stderr, 'Rapture the flag?'

    assert out == ['Capture the flag!']
    assert err == ['Rapture the flag?']

    assert sys.stdout is stdout
    assert sys.stderr is stderr
Ejemplo n.º 4
0
def capture():
    """capture_output()"""

    stdout, stderr = sys.stdout, sys.stderr

    with attest.capture_output() as (out, err):
        print 'Capture the flag!'
        print >>sys.stderr, 'Rapture the flag?'

    assert out == ['Capture the flag!']
    assert err == ['Rapture the flag?']

    assert sys.stdout is stdout
    assert sys.stderr is stderr
Ejemplo n.º 5
0
def xml_reporter():
    """XmlReporter"""

    with attest.capture_output() as (out, err):
        _meta.suite.run(attest.XmlReporter)

    for line, expected in zip(out[:5] + out[-3:], [
        '<?xml version="1.0" encoding="UTF-8"?>',
        '<testreport tests="2">',
        '  <pass name="attest.tests._meta.passing"/>',
        '  <fail name="attest.tests._meta.failing" type="TestFailure">',
        '    Traceback (most recent call last):',
        '    %s' % EXCEPTION,
        '  </fail>',
        '</testreport>',
    ]):
        assert line == expected
Ejemplo n.º 6
0
def xml_reporter():
    """XmlReporter"""

    with attest.capture_output() as (out, err):
        _meta.suite.run(attest.XmlReporter)

    for line, expected in zip(out, [
        '<?xml version="1.0" encoding="UTF-8"?>',
        '<testreport tests="2">',
        '  <pass name="attest.tests._meta.passing"/>',
        '  <fail name="attest.tests._meta.failing" type="TestFailure">',
        '    Traceback (most recent call last):',
        '      File &quot;%s&quot;, line %d, in failing' % (SOURCEFILE, LINENO),
        '        assert value == 3',
        '    %s' % EXCEPTION,
        '  </fail>',
        '</testreport>',
    ]):
        assert line == expected
Ejemplo n.º 7
0
def plain_reporter():
    """PlainReporter"""

    with attest.capture_output() as (out, err):
        with Assert.raises(SystemExit):
            _meta.suite.run(attest.PlainReporter)

    width, _ = utils.get_terminal_size()
    for line, expected in zip(out[:7] + out[-3:], [
        '.F',
        '',
        'attest.tests._meta.failing',
        '-' * width,
        '-> stdout',
        'E: stderr',
        'Traceback (most recent call last):',
        '%s' % EXCEPTION,
        '',
        'Failures: 1/2 (1 assertions)',
    ]):
        assert line == expected
Ejemplo n.º 8
0
def plain_reporter():
    """PlainReporter"""

    with attest.capture_output() as (out, err):
        with Assert.raises(SystemExit):
            _meta.suite.run(attest.PlainReporter)

    for line, expected in zip(out, [
        '.F',
        '',
        'attest.tests._meta.failing',
        '-' * 80,
        '-> stdout',
        'E: stderr',
        'Traceback (most recent call last):',
        '  File "%s", line %d, in failing' % (SOURCEFILE, LINENO),
        '    assert value == 3',
        '%s' % EXCEPTION,
        '',
    ]):
        assert line == expected

    assert out[-1].split(' ')[:2] == ['Failures:', '1/2']
Ejemplo n.º 9
0
        def _exc_info_to_string(self, err, test):
            if err[0] is TestFailure:
                # retrieve stdout/stderr
                if self.buffer:
                    stdout = sys.stdout.getvalue().splitlines()
                    stderr = sys.stderr.getvalue().splitlines()
                else:
                    stdout, stderr = [], []

                # pull the test function out of the TestCase.
                test_func = getattr(test, test._testMethodName)
                result = TestResult(test=test_func, exc_info=err, time=0,
                                    error=err[1], stdout=stdout, stderr=stderr)
                reporter = get_reporter_by_name('auto')()
                reporter.begin(())
                reporter.progress = DummyProgress()
                reporter.failure(result)
                with capture_output() as (out, err):
                    try:
                        reporter.finished()
                    except SystemExit:
                        pass
                return '\n'.join(out + err)
            return super(TextResult, self)._exc_info_to_string(err, test)