def test(monkeypatch, is_windows, mode):
    """Test function.

    :param monkeypatch: pytest fixture.
    :param bool is_windows: Monkeypatch terminal_io.IS_WINDOWS
    :param str mode: Scenario to test for.
    """
    monkeypatch.setattr('terminaltables.terminal_io.IS_WINDOWS', is_windows)
    kernel32 = MockKernel32()

    # Title.
    if mode == 'ascii':
        title = 'Testing terminaltables.'
    elif mode == 'unicode':
        title = u'Testing terminaltables with unicode: 世界你好蓝色'
    else:
        title = b'Testing terminaltables with bytes.'

    # Run.
    assert set_terminal_title(title, kernel32)
    if not is_windows:
        return

    # Verify.
    if mode == 'ascii':
        assert kernel32.setConsoleTitleA_called
        assert not kernel32.setConsoleTitleW_called
    elif mode == 'unicode':
        assert not kernel32.setConsoleTitleA_called
        assert kernel32.setConsoleTitleW_called
    else:
        assert kernel32.setConsoleTitleA_called
        assert not kernel32.setConsoleTitleW_called
def test(monkeypatch, is_windows, mode):
    """Test function.

    :param monkeypatch: pytest fixture.
    :param bool is_windows: Monkeypatch terminal_io.IS_WINDOWS
    :param str mode: Scenario to test for.
    """
    monkeypatch.setattr('terminaltables.terminal_io.IS_WINDOWS', is_windows)
    kernel32 = MockKernel32()

    # Title.
    if mode == 'ascii':
        title = 'Testing terminaltables.'
    elif mode == 'unicode':
        title = u'Testing terminaltables with unicode: 世界你好蓝色'
    else:
        title = b'Testing terminaltables with bytes.'

    # Run.
    assert set_terminal_title(title, kernel32)
    if not is_windows:
        return

    # Verify.
    if mode == 'ascii':
        assert kernel32.setConsoleTitleA_called
        assert not kernel32.setConsoleTitleW_called
    elif mode == 'unicode':
        assert not kernel32.setConsoleTitleA_called
        assert kernel32.setConsoleTitleW_called
    else:
        assert kernel32.setConsoleTitleA_called
        assert not kernel32.setConsoleTitleW_called
Esempio n. 3
0
def test_set_terminal_title():
    """Run the function looking for exceptions. Can't get title on Linux/OSX so can't fully test."""
    set_terminal_title('Testing terminaltables.')
def test_set_terminal_title():
    """Run the function looking for exceptions. Can't get title on Linux/OSX so can't fully test."""
    set_terminal_title('Testing terminaltables.')