🐛 give a graceful exception instead of stack trace. fix https://github.com/pyexcel/pyexcel/issues/120
This commit is contained in:
parent
ba793b104f
commit
d8fa9296ea
|
@ -18,6 +18,7 @@ from pyexcel_io.sheet import SheetWriter
|
|||
DEFAULT_DATE_FORMAT = "DD/MM/YY"
|
||||
DEFAULT_TIME_FORMAT = "HH:MM:SS"
|
||||
DEFAULT_DATETIME_FORMAT = "%s %s" % (DEFAULT_DATE_FORMAT, DEFAULT_TIME_FORMAT)
|
||||
EMPTY_SHEET_NOT_ALLOWED = "xlwt does not support a book without any sheets"
|
||||
|
||||
|
||||
class XLSheetWriter(SheetWriter):
|
||||
|
@ -76,6 +77,12 @@ class XLSWriter(BookWriter):
|
|||
self.work_book = Workbook(style_compression=style_compression,
|
||||
encoding=encoding)
|
||||
|
||||
def write(self, incoming_dict):
|
||||
if incoming_dict:
|
||||
BookWriter.write(self, incoming_dict)
|
||||
else:
|
||||
raise NotImplementedError(EMPTY_SHEET_NOT_ALLOWED)
|
||||
|
||||
def create_sheet(self, name):
|
||||
return XLSheetWriter(self.work_book, None, name)
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
import os
|
||||
import pyexcel as pe
|
||||
from pyexcel_xls import save_data
|
||||
from pyexcel_xls.xlsw import XLSWriter as Writer
|
||||
from _compact import OrderedDict
|
||||
from nose.tools import eq_, raises
|
||||
from nose import SkipTest
|
||||
|
@ -90,5 +91,14 @@ def test_issue_20():
|
|||
pe.get_book(url="https://github.com/pyexcel/pyexcel-xls/raw/master/tests/fixtures/file_with_an_empty_sheet.xls"); # flake8: noqa
|
||||
|
||||
|
||||
@raises(NotImplementedError)
|
||||
def test_empty_book_pyexcel_issue_120():
|
||||
"""
|
||||
https://github.com/pyexcel/pyexcel/issues/120
|
||||
"""
|
||||
writer = Writer()
|
||||
writer.write({})
|
||||
|
||||
|
||||
def get_fixture(file_name):
|
||||
return os.path.join("tests", "fixtures", file_name)
|
||||
|
|
Loading…
Reference in New Issue