����JFIF��H�H����Exif��MM�*���� ��3����V�����3������3�(��������������������3�����
Server IP : 74.208.127.88 / Your IP : 216.73.216.82 Web Server : Apache/2.4.41 (Ubuntu) System : Linux ubuntu 5.4.0-163-generic #180-Ubuntu SMP Tue Sep 5 13:21:23 UTC 2023 x86_64 User : www-data ( 33) PHP Version : 7.4.3-4ubuntu2.29 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /proc/self/root/snap/core20/current/usr/share/subiquity/subiquitycore/ui/tests/ |
Upload File : |
# Copyright 2019 Canonical, Ltd. # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, version 3. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. from collections import defaultdict from unittest import TestCase from urwid import Text from subiquitycore.ui.table import ( _compute_widths_for_size, ColSpec, TableRow, ) class TestComputeWidthsForSize(TestCase): def rowsForContentSizes(self, sizes): rows = [] for row in sizes: cells = [] for size in row: if not isinstance(size, tuple): span = 1 else: span, size = size cells.append((span, Text("x"*size))) rows.append(TableRow(cells)) return rows def test_simple(self): trows = self.rowsForContentSizes([[10]]) widths, total, has_unpacked = _compute_widths_for_size( 100, trows, defaultdict(ColSpec, {}), 0) self.assertEqual( ({0: 10}, 10, False), (widths, total, has_unpacked), ) def test_two_cols(self): trows = self.rowsForContentSizes([[10, 10]]) widths, total, has_unpacked = _compute_widths_for_size( 100, trows, defaultdict(ColSpec, {}), 0) self.assertEqual( ({0: 10, 1: 0, 2: 10}, 20, False), (widths, total, has_unpacked), ) def test_two_cols_confined(self): # When there is not enough space for the table, a column with # can_shrink=True is not assigned a width so urwid can give # that column as much space as it can. trows = self.rowsForContentSizes([[10, 10]]) colspecs = defaultdict( ColSpec, {0: ColSpec(can_shrink=True)}) widths, total, has_unpacked = _compute_widths_for_size( 15, trows, colspecs, 0) self.assertEqual( ({1: 0, 2: 10}, 15, False), (widths, total, has_unpacked), ) def test_two_cols_spacing(self): trows = self.rowsForContentSizes([[10, 10]]) widths, total, has_unpacked = _compute_widths_for_size( 100, trows, defaultdict(ColSpec, {}), 2) self.assertEqual( ({0: 10, 1: 2, 2: 10}, 22, False), (widths, total, has_unpacked), ) def test_three_cols_spacing_rpad(self): # rpad overrides the spacing to the right of a column trows = self.rowsForContentSizes([[10, 10, 10]]) colspecs = defaultdict( ColSpec, {0: ColSpec(rpad=40)}) widths, total, has_unpacked = _compute_widths_for_size( 100, trows, colspecs, 2) self.assertEqual( ({0: 10, 1: 40, 2: 10, 3: 2, 4: 10}, 72, False), (widths, total, has_unpacked), ) def test_no_inherent_width(self): # If a column has no cells that span only that column, it gets # allocated space in preference to other columns. Content # like this: # # [[(2, "longer content567890"), "shorter890"], # ["shorter890", (2, "longer content5")]] # # should be rendered like this: # # +----------------------+------------+ # | longer content567890 | shorter890 | # +------------+---------+------------+ # | shorter890 | longer content5 | # +------------+----------------------+ trows = self.rowsForContentSizes([[(2, 20), 10], [10, (2, 15)]]) widths, total, has_unpacked = _compute_widths_for_size( 100, trows, defaultdict(ColSpec, {}), 0) self.assertEqual( ({0: 10, 1: 0, 2: 10, 3: 0, 4: 10}, 30, False), (widths, total, has_unpacked), ) def test_no_inherent_width_confined(self): # [[(2, "longer content567890"), "shorter890"], # ["shorter890", (2, "longer content5")]] # # should be rendered like this if the view is not quite wide # enough (and column 1 has can_shrink=True): # # +--------------------+------------+ # | longer content5678 | shorter890 | # | 90 | | # +------------+-------+------------+ # | shorter890 | longer content5 | # +------------+--------------------+ # # This is represented by column 1 not being assigned a width # at all, so urwid gives it as much space as it can. trows = self.rowsForContentSizes([[(2, 20), 10], [10, (2, 15)]]) colspecs = defaultdict( ColSpec, {1: ColSpec(can_shrink=True)}) widths, total, has_unpacked = _compute_widths_for_size( 28, trows, colspecs, 0) self.assertEqual( ({0: 10, 1: 0, 3: 0, 4: 10}, 28, False), (widths, total, has_unpacked), )