def test_method_column_widths_object_new_column(self): mock_line_data = MagicMock() mock_line_data.size = (20, 20) mock_column_1 = MagicMock(spec=DisplayColumn) mock_column_1.align = 'left' mock_column_1.attribute = 'test' mock_column_1.colspan = 1 mock_column_1.default = None mock_column_1.formatter = PropertyMock(return_value=mock_line_data) mock_column_1.formatter_args = None mock_column_1.lookup = None mock_column_2 = MagicMock(spec=DisplayColumn) mock_column_2.align = 'left' mock_column_2.attribute = 'test' mock_column_2.colspan = 1 mock_column_2.default = None mock_column_2.formatter = PropertyMock(return_value=mock_line_data) mock_column_2.formatter_args = None mock_column_2.lookup = None mock_data = MagicMock(test="test") column_widths = [40] instance = DisplayLine([mock_column_1, mock_column_2], mock_data) instance._column_widths = column_widths expected_result = [40, 20] self.assertListEqual( instance.column_widths(sentinel.font, column_widths), expected_result)
def test_method_column_widths_string_new_column(self): mock_column_1 = MagicMock(spec=DisplayColumn) mock_column_1.align = 'left' mock_column_1.attribute = 'test' mock_column_1.colspan = 1 mock_column_1.default = None mock_column_1.formatter = None mock_column_1.lookup = None mock_column_2 = MagicMock(spec=DisplayColumn) mock_column_2.align = 'left' mock_column_2.attribute = 'test' mock_column_2.colspan = 1 mock_column_2.default = None mock_column_2.formatter = None mock_column_2.lookup = None mock_data = MagicMock(test="test") mock_font = MagicMock() mock_font.getsize.return_value = (20, 20) column_widths = [40] instance = DisplayLine([mock_column_1, mock_column_2], mock_data) instance._column_widths = column_widths expected_result = [40, 20] self.assertListEqual(instance.column_widths(mock_font, column_widths), expected_result)
def test_method_reset(self): mock_column = MagicMock(spec=DisplayColumn) mock_column.align = 'left' mock_column.attribute = 'test' mock_column.colspan = 1 mock_column.default = None mock_column.formatter = None mock_column.lookup = None mock_data = MagicMock(test="test") instance = DisplayLine([mock_column], mock_data) DisplayLine.reset() expected_result = list() self.assertListEqual(instance._column_widths, expected_result)
def test_method_column_widths_heading_line_and_colspan(self): mock_column = MagicMock(spec=DisplayColumn) mock_column.align = 'left' mock_column.attribute = 'test' mock_column.colspan = 2 mock_column.default = None mock_column.formatter = None mock_column.lookup = None mock_column.heading = "Heading" mock_data = MagicMock(test="test") instance = DisplayLine([mock_column], mock_data, make_headings=True) expected_result = [0] self.assertListEqual(instance.column_widths(sentinel.font, None), expected_result)
def test_next(self): mock_column = MagicMock(spec=DisplayColumn) mock_column.align = 'left' mock_column.attribute = 'test' mock_column.colspan = 1 mock_column.default = None mock_column.formatter = None mock_column.lookup = None mock_data = MagicMock(test="test") mock_font = MagicMock() mock_font.getsize.return_value = (20, 20) instance = DisplayLine([mock_column], mock_data) instance.column_widths(mock_font, []) iterator = iter(instance) expected_result = tuple self.assertIsInstance(next(iterator), expected_result)
def test_init_no_headings(self): mock_column = MagicMock(spec=DisplayColumn) mock_column.align = 'left' mock_column.attribute = 'test' mock_column.colspan = 1 mock_column.default = None mock_column.formatter = None mock_column.lookup = None mock_data = MagicMock(test="test") instance = DisplayLine([mock_column], mock_data) expected_result = DisplayLine self.assertIsInstance(instance, expected_result)
def test_init_with_column_default(self): mock_column = MagicMock(spec=DisplayColumn) mock_column.align = 'left' mock_column.attribute = 'test' mock_column.colspan = 1 mock_column.default = 'default' mock_column.formatter = None mock_column.lookup = PropertyMock(side_effect=KeyError) mock_column.heading = 'heading' mock_data = MagicMock(test="test") instance = DisplayLine([mock_column], mock_data) expected_result = DisplayLine self.assertIsInstance(instance, expected_result)
def test_next_stop(self): mock_column = MagicMock(spec=DisplayColumn) mock_column.align = 'left' mock_column.attribute = 'test' mock_column.colspan = 1 mock_column.default = None mock_column.formatter = None mock_column.lookup = None mock_data = MagicMock(test="test") instance = DisplayLine([mock_column], mock_data) iterator = iter(instance) with self.assertRaises(StopIteration): next(iterator)
def test_init_with_column_formatter_no_args(self): mock_formatter = MagicMock() mock_formatter.return_value = sentinel.formatted mock_column = MagicMock(spec=DisplayColumn) mock_column.align = 'left' mock_column.attribute = 'test' mock_column.colspan = 1 mock_column.default = None mock_column.formatter = mock_formatter mock_column.formatter_args = None mock_column.heading = 'heading' mock_column.lookup = None mock_data = MagicMock(test="test") instance = DisplayLine([mock_column], mock_data) expected_result = DisplayLine self.assertIsInstance(instance, expected_result)
def tearDown(self): DisplayLine.reset()