summaryrefslogtreecommitdiffstats
path: root/tests/test_terminal_io/test_get_console_info.py
blob: 1a9b98f9627e1925af8098d135a0a3714f4e0257 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# coding: utf-8
"""Test function in module."""

import ctypes

import pytest

from terminaltables.terminal_io import get_console_info, INVALID_HANDLE_VALUE, IS_WINDOWS

from tests.test_terminal_io import MockKernel32


def test():
    """Test function."""
    # Test live WinError.
    if IS_WINDOWS:
        with pytest.raises(OSError):
            get_console_info(ctypes.windll.kernel32, 0)

    # Test INVALID_HANDLE_VALUE.
    kernel32 = MockKernel32(stderr=1)
    with pytest.raises(OSError):
        get_console_info(kernel32, INVALID_HANDLE_VALUE)

    # Test no error with mock methods.
    width, height = get_console_info(kernel32, 1)
    assert width == 119
    assert height == 29