diff --git a/example1.py b/example1.py index daf1fbf9..bb3f6fc3 100755 --- a/example1.py +++ b/example1.py @@ -16,7 +16,7 @@ def main(): - """Main function.""" + """Print some information about Golf cars.""" title = 'Jetta SportWagen' # AsciiTable. diff --git a/example2.py b/example2.py index 51644f88..25dc500a 100755 --- a/example2.py +++ b/example2.py @@ -61,7 +61,7 @@ def table_abcd(): def main(): - """Main function.""" + """Print some example tables to the console.""" Windows.enable(auto_colors=True, reset_atexit=True) # Does nothing if not on Windows. # Server timings. diff --git a/example3.py b/example3.py index bec55000..9a984b3f 100755 --- a/example3.py +++ b/example3.py @@ -18,7 +18,7 @@ def main(): - """Main function.""" + """Print a line-wrapped table of Lorem-ipsum sample text.""" table_data = [ ['Long String', ''], # One row. Two columns. Long string will replace this empty string. ] diff --git a/setup.py b/setup.py index a9474446..b9111048 100755 --- a/setup.py +++ b/setup.py @@ -41,12 +41,12 @@ class CheckVersion(Command): @classmethod def initialize_options(cls): - """Required by distutils.""" + """Provide default values for all options, required by distutils.""" pass @classmethod def finalize_options(cls): - """Required by distutils.""" + """Decide on the final values for all options, required by distutils.""" pass @classmethod diff --git a/tests/test_terminal_io/__init__.py b/tests/test_terminal_io/__init__.py index 93738fcf..f5ad82f2 100644 --- a/tests/test_terminal_io/__init__.py +++ b/tests/test_terminal_io/__init__.py @@ -6,7 +6,10 @@ class MockKernel32(object): """Mock kernel32.""" - def __init__(self, stderr=terminal_io.INVALID_HANDLE_VALUE, stdout=terminal_io.INVALID_HANDLE_VALUE): + def __init__(self, + stderr=terminal_io.INVALID_HANDLE_VALUE, + stdout=terminal_io.INVALID_HANDLE_VALUE, + screen_buffer_info=True): """Constructor.""" self.stderr = stderr self.stdout = stdout @@ -14,6 +17,7 @@ def __init__(self, stderr=terminal_io.INVALID_HANDLE_VALUE, stdout=terminal_io.I self.csbi_out = b'L\x00,\x01\x00\x00*\x01\x07\x00\x00\x00\x0e\x01K\x00*\x01L\x00L\x00' # 75 x 28 self.setConsoleTitleA_called = False self.setConsoleTitleW_called = False + self.screen_buffer_info = screen_buffer_info def GetConsoleScreenBufferInfo(self, handle, lpcsbi): # noqa """Mock GetConsoleScreenBufferInfo. @@ -21,6 +25,9 @@ def GetConsoleScreenBufferInfo(self, handle, lpcsbi): # noqa :param handle: Unused handle. :param lpcsbi: ctypes.create_string_buffer() return value. """ + if not self.screen_buffer_info: + return 0 + if handle == self.stderr: lpcsbi.raw = self.csbi_err else: diff --git a/tests/test_terminal_io/test_get_console_info.py b/tests/test_terminal_io/test_get_console_info.py index 1a9b98f9..f617484d 100644 --- a/tests/test_terminal_io/test_get_console_info.py +++ b/tests/test_terminal_io/test_get_console_info.py @@ -5,24 +5,36 @@ import pytest -from terminaltables.terminal_io import get_console_info, INVALID_HANDLE_VALUE, IS_WINDOWS +from terminaltables.terminal_io import get_console_info, INVALID_HANDLE_VALUE 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) +@pytest.mark.skipif("sys.platform != 'win32'") +def test_live_win_error(): + """Test live WinError.""" + with pytest.raises(OSError): + get_console_info(ctypes.windll.kernel32, 0) + - # Test INVALID_HANDLE_VALUE. +def test_invalid_handle_value(): + """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. + +def test_no_error_with_mock_methods(): + """Test no error with mock methods.""" + kernel32 = MockKernel32(stderr=1) width, height = get_console_info(kernel32, 1) assert width == 119 assert height == 29 + + +@pytest.mark.skipif("sys.platform != 'win32'") +def test_no_console_screen_buffer_info(): + """Test no console screen buffer info.""" + kernel32 = MockKernel32(stderr=1, screen_buffer_info=False) + with pytest.raises(OSError): + get_console_info(kernel32, 1) diff --git a/tox.ini b/tox.ini index c6c9c0b9..e5f3ea63 100644 --- a/tox.ini +++ b/tox.ini @@ -28,7 +28,7 @@ commands = flake8 --application-import-names={[general]name},tests pylint --rcfile=tox.ini setup.py {[general]name} deps = - flake8-docstrings==1.0.3 + flake8-docstrings==1.1.0 flake8-import-order==0.12 flake8==3.3.0 pep8-naming==0.4.1