コード例 #1
0
ファイル: log_tests.py プロジェクト: passdedd/piglit
def test_print_when_expected():
    """ Generator that creates tests that ensure that methods print

    For most logger classes <class>.log() and <class>.summary() should print
    something, for some classes <class>.start() should print.

    This doesn't try to check what they are printing, just that they are
    printing, since 1) the output is very implementation dependent, and 2) it
    is subject to change.

    """
    # a list of tuples which element 1 is the name of the class and method
    # element 2 is a callable, and element 3 is a list of arguments to be
    # passed to that callable. it needs to work with the splat operator
    printing = []

    # Test QuietLog
    quiet = log.QuietLog(TEST_STATE)
    printing.append(('QuietLog.log', quiet.log, ['pass']))
    printing.append(('QuietLog.summary', quiet.summary, []))

    # Test VerboseLog
    verbose = log.VerboseLog(TEST_STATE)
    printing.append(('VerboseLog.start', verbose.start, ['a test']))
    printing.append(('VerboseLog.log', verbose.log, ['pass']))
    printing.append(('VerboseLog.summary', verbose.summary, []))

    for name, func, args in printing:
        check_for_output.description = "{} produces output".format(name)
        yield check_for_output, func, args
コード例 #2
0
        def test_start(self, log_state):  # pylint: disable=redefined-outer-name
            """Test that the start method doesn't have output."""
            l = log.VerboseLog(log_state, threading.Lock())
            l.start('foo')
            sys.stdout.seek(0)

            assert sys.stdout.read().rstrip() == b'running: foo\n\n[0/1]  \\'
コード例 #3
0
        def test_summary(self, log_state):  # pylint: disable=redefined-outer-name
            """Test the output of the summary method."""
            l = log.VerboseLog(log_state, threading.Lock())
            l.start('foo')
            l.log('pass')
            sys.stdout.seek(0)
            sys.stdout.truncate()

            l.summary()
            sys.stdout.seek(0)

            assert sys.stdout.read().rstrip() == b'[1/1] pass: 1'
コード例 #4
0
        def test_log(self, log_state):  # pylint: disable=redefined-outer-name
            """Test the output of the log method."""
            l = log.VerboseLog(log_state, threading.Lock())
            l.start('foo')
            sys.stdout.seek(0)
            sys.stdout.truncate()

            l.log('pass')
            sys.stdout.seek(0)

            actual = sys.stdout.read()
            assert actual == b'pass: foo\n\n[1/1] pass: 1 /\n'