From c29c9ddf82619bc33c8658a63456eb5a76f1c678 Mon Sep 17 00:00:00 2001 From: Andrew Graham-Yooll Date: Sat, 18 Jan 2025 15:28:14 +0800 Subject: [PATCH] Linting and formatting --- AUTHORS | 1 - src/tablib/formats/_xlsx.py | 12 +++++++----- tests/test_tablib.py | 11 +++++------ 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/AUTHORS b/AUTHORS index 61497bfe..670faf12 100644 --- a/AUTHORS +++ b/AUTHORS @@ -35,4 +35,3 @@ Here is a list of past and present much-appreciated contributors: Tsuyoshi Hombashi Tushar Makkar Yunis Yilmaz - Egor Osokin diff --git a/src/tablib/formats/_xlsx.py b/src/tablib/formats/_xlsx.py index 21080b76..30ec6d15 100644 --- a/src/tablib/formats/_xlsx.py +++ b/src/tablib/formats/_xlsx.py @@ -34,7 +34,8 @@ def detect(cls, stream): return False @classmethod - def export_set(cls, dataset, freeze_panes=True, invalid_char_subst="-", escape=False, column_width="adaptive"): + def export_set(cls, dataset, freeze_panes=True, invalid_char_subst="-", + escape=False, column_width="adaptive"): """Returns XLSX representation of Dataset. If ``freeze_panes`` is True, Export will freeze panes only after first line. @@ -50,7 +51,8 @@ def export_set(cls, dataset, freeze_panes=True, invalid_char_subst="-", escape=F If ``column_width`` is set to "adaptive", the column width will be set to the maximum width of the content in each column. If it is set to an integer, the column width will be - set to that integer value. If it is set to None, the column width will be set as the default openpyxl.Worksheet width value. + set to that integer value. If it is set to None, the column width will be set as the + default openpyxl.Worksheet width value. """ wb = Workbook() @@ -181,7 +183,7 @@ def _adapt_column_width(cls, worksheet, width): f"Must be 'adaptive' or an integer." ) raise ValueError(msg) - + if width is None: return @@ -197,6 +199,6 @@ def _adapt_column_width(cls, worksheet, width): column_widths.append(len(cell)) else: column_widths = [width] * worksheet.max_column - - for i, column_width in enumerate(column_widths, 1): # start at 1 + + for i, column_width in enumerate(column_widths, 1): # start at 1 worksheet.column_dimensions[get_column_letter(i)].width = column_width diff --git a/tests/test_tablib.py b/tests/test_tablib.py index 0e5a92ef..32119918 100755 --- a/tests/test_tablib.py +++ b/tests/test_tablib.py @@ -11,13 +11,11 @@ from decimal import Decimal from io import BytesIO, StringIO from pathlib import Path -from tempfile import TemporaryFile from uuid import uuid4 import xlrd from odf import opendocument, table from openpyxl.reader.excel import load_workbook -from MarkupPy import markup import tablib from tablib.core import Row, detect_format @@ -1354,11 +1352,12 @@ def _get_width(data, input_arg): data = tablib.Dataset().load(fh) width_before = _get_width(data, column_width) data.append([ - 'verylongvalue-verylongvalue-verylongvalue-verylongvalue-verylongvalue-verylongvalue-verylongvalue-verylongvalue', + 'verylongvalue-verylongvalue-verylongvalue-verylongvalue-' + 'verylongvalue-verylongvalue-verylongvalue-verylongvalue', ]) width_after = _get_width(data, width_before) return width_before, width_after - + def test_xlsx_format_detect(self): """Test the XLSX format detection.""" in_stream = self.founders.xlsx @@ -1502,7 +1501,7 @@ def test_xlsx_raise_ValueError_on_cell_write_during_export(self): _xlsx = data.export('xlsx') wb = load_workbook(filename=BytesIO(_xlsx)) self.assertEqual('[1]', wb.active['A1'].value) - + def test_xlsx_column_width_adaptive(self): """ Test that column width adapts to value length""" width_before, width_after = self._helper_export_column_width("adaptive") @@ -1514,7 +1513,7 @@ def test_xlsx_column_width_integer(self): width_before, width_after = self._helper_export_column_width(10) self.assertEqual(width_before, 10) self.assertEqual(width_after, 10) - + def test_xlsx_column_width_none(self): """Test that column width does not change""" width_before, width_after = self._helper_export_column_width(None)