Skip to content

Commit

Permalink
Linting and formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewgy8 committed Jan 18, 2025
1 parent c3fcf8d commit c29c9dd
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
1 change: 0 additions & 1 deletion AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,3 @@ Here is a list of past and present much-appreciated contributors:
Tsuyoshi Hombashi
Tushar Makkar
Yunis Yilmaz
Egor Osokin
12 changes: 7 additions & 5 deletions src/tablib/formats/_xlsx.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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()
Expand Down Expand Up @@ -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

Expand All @@ -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
11 changes: 5 additions & 6 deletions tests/test_tablib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand All @@ -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)
Expand Down

0 comments on commit c29c9dd

Please sign in to comment.