def test_ioctl(self, mock_ioctl): mock_ioctl.return_value = struct.pack('hhhh', 57, 101, 0, 0) width = utils.terminal_width(sys.stdout) self.assertEqual(101, width) mock_ioctl.side_effect = IOError() width = utils.terminal_width(sys.stdout) self.assertIs(None, width)
def test_get_terminal_size(self, mock_os): ts = os.terminal_size((10, 5)) mock_os.get_terminal_size.return_value = ts width = utils.terminal_width(sys.stdout) self.assertEqual(10, width) mock_os.get_terminal_size.side_effect = OSError() width = utils.terminal_width(sys.stdout) self.assertIs(None, width)
def test_get_terminal_size(self, mock_os): ts = os.terminal_size((10, 5)) mock_os.get_terminal_size.return_value = ts width = utils.terminal_width(sys.stdout) self.assertEqual(10, width) mock_os.get_terminal_size.side_effect = OSError() width = utils.terminal_width(sys.stdout) self.assertIs(None, width)
def test_utils_terminal_width_ioctl(mock_ioctl): if hasattr(os, 'get_terminal_size'): raise nose.SkipTest('only needed for python 3.2 and before') mock_ioctl.return_value = struct.pack('hhhh', 57, 101, 0, 0) width = utils.terminal_width(sys.stdout) assert width == 101 mock_ioctl.side_effect = IOError() width = utils.terminal_width(sys.stdout) assert width is None
def test_utils_terminal_width_ioctl(mock_ioctl): if hasattr(os, 'get_terminal_size'): raise nose.SkipTest('only needed for python 3.2 and before') mock_ioctl.return_value = struct.pack('hhhh', 57, 101, 0, 0) width = utils.terminal_width(sys.stdout) assert width == 101 mock_ioctl.side_effect = IOError() width = utils.terminal_width(sys.stdout) assert width is None
def test_utils_terminal_width_get_terminal_size(mock_os): if not hasattr(os, 'get_terminal_size'): raise nose.SkipTest('only needed for python 3.3 onwards') ts = os.terminal_size((10, 5)) mock_os.get_terminal_size.return_value = ts width = utils.terminal_width(sys.stdout) assert width == 10 mock_os.get_terminal_size.side_effect = OSError() width = utils.terminal_width(sys.stdout) assert width is None
def test_utils_terminal_width_get_terminal_size(mock_os): if not hasattr(os, 'get_terminal_size'): raise nose.SkipTest('only needed for python 3.3 onwards') ts = os.terminal_size((10, 5)) mock_os.get_terminal_size.return_value = ts width = utils.terminal_width(sys.stdout) assert width == 10 mock_os.get_terminal_size.side_effect = OSError() width = utils.terminal_width(sys.stdout) assert width is None
def _assign_max_widths(stdout, x, max_width, min_width=0): if min_width: x.min_width = min_width if max_width > 0: x.max_width = max_width return term_width = utils.terminal_width(stdout) if not term_width: # not a tty, so do not set any max widths return field_count = len(x.field_names) first_line = x.get_string().splitlines()[0] if len(first_line) <= term_width: return usable_total_width, optimal_width = TableFormatter._width_info( term_width, field_count) field_widths = TableFormatter._field_widths(x.field_names, first_line) shrink_fields, shrink_remaining = TableFormatter._build_shrink_fields( usable_total_width, optimal_width, field_widths, x.field_names) shrink_to = shrink_remaining // len(shrink_fields) # make all shrinkable fields size shrink_to apart from the last one for field in shrink_fields[:-1]: x.max_width[field] = max(min_width, shrink_to) shrink_remaining -= shrink_to # give the last shrinkable column shrink_to plus any remaining field = shrink_fields[-1] x.max_width[field] = max(min_width, shrink_remaining)
def test_windows(self, mock_ctypes): mock_ctypes.create_string_buffer.return_value.raw = struct.pack( 'hhhhHhhhhhh', 101, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) mock_ctypes.windll.kernel32.GetStdHandle.return_value = -11 mock_ctypes.windll.kernel32.GetConsoleScreenBufferInfo.return_value = 1 width = utils.terminal_width(sys.stdout) self.assertEqual(101, width) mock_ctypes.windll.kernel32.GetConsoleScreenBufferInfo.return_value = 0 width = utils.terminal_width(sys.stdout) self.assertIs(None, width) width = utils.terminal_width('foo') self.assertIs(None, width)
def _assign_max_widths(stdout, x, max_width, min_width=0): if min_width: x.min_width = min_width if max_width > 0: x.max_width = max_width return term_width = utils.terminal_width(stdout) if not term_width: # not a tty, so do not set any max widths return field_count = len(x.field_names) first_line = x.get_string().splitlines()[0] if len(first_line) <= term_width: return usable_total_width, optimal_width = TableFormatter._width_info( term_width, field_count) field_widths = TableFormatter._field_widths(x.field_names, first_line) shrink_fields, shrink_remaining = TableFormatter._build_shrink_fields( usable_total_width, optimal_width, field_widths, x.field_names) shrink_to = shrink_remaining // len(shrink_fields) # make all shrinkable fields size shrink_to apart from the last one for field in shrink_fields[:-1]: x.max_width[field] = max(min_width, shrink_to) shrink_remaining -= shrink_to # give the last shrinkable column shrink_to plus any remaining field = shrink_fields[-1] x.max_width[field] = max(min_width, shrink_remaining)
def test_utils_terminal_width_windows(mock_ctypes): if hasattr(os, 'get_terminal_size'): raise nose.SkipTest('only needed for python 3.2 and before') mock_ctypes.create_string_buffer.return_value.raw = struct.pack( 'hhhhHhhhhhh', 101, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) mock_ctypes.windll.kernel32.GetStdHandle.return_value = -11 mock_ctypes.windll.kernel32.GetConsoleScreenBufferInfo.return_value = 1 width = utils.terminal_width(sys.stdout) assert width == 101 mock_ctypes.windll.kernel32.GetConsoleScreenBufferInfo.return_value = 0 width = utils.terminal_width(sys.stdout) assert width is None width = utils.terminal_width('foo') assert width is None
def test_utils_terminal_width_windows(mock_ctypes): if hasattr(os, 'get_terminal_size'): raise nose.SkipTest('only needed for python 3.2 and before') mock_ctypes.create_string_buffer.return_value.raw = struct.pack( 'hhhhHhhhhhh', 101, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) mock_ctypes.windll.kernel32.GetStdHandle.return_value = -11 mock_ctypes.windll.kernel32.GetConsoleScreenBufferInfo.return_value = 1 width = utils.terminal_width(sys.stdout) assert width == 101 mock_ctypes.windll.kernel32.GetConsoleScreenBufferInfo.return_value = 0 width = utils.terminal_width(sys.stdout) assert width is None width = utils.terminal_width('foo') assert width is None
def test_utils_terminal_width(): width = utils.terminal_width(sys.stdout) # Results are specific to the execution environment, so only assert # that no error is raised. assert width is None or isinstance(width, int)
def test(self): width = utils.terminal_width(sys.stdout) # Results are specific to the execution environment, so only assert # that no error is raised. if width is not None: self.assertIsInstance(width, int)
def test(self): width = utils.terminal_width(sys.stdout) # Results are specific to the execution environment, so only assert # that no error is raised. if width is not None: self.assertIsInstance(width, int)
def test_utils_terminal_width(): width = utils.terminal_width(sys.stdout) # Results are specific to the execution environment, so only assert # that no error is raised. assert width is None or isinstance(width, int)