Improvement on the invalid inputs
This commit is contained in:
parent
28cb1b1749
commit
5d736a43e5
|
@ -111,7 +111,11 @@ class XLBook(BookReader):
|
|||
"""Return iterable sheet array"""
|
||||
|
||||
if self.sheet_name is not None:
|
||||
return [self.native_book.sheet_by_name(self.sheet_name)]
|
||||
try:
|
||||
sheet = self.native_book.sheet_by_name(self.sheet_name)
|
||||
return [sheet]
|
||||
except xlrd.XLRDError:
|
||||
raise ValueError("%s cannot be found" % self.sheet_name)
|
||||
elif self.sheet_index is not None:
|
||||
return [self.native_book.sheet_by_index(self.sheet_index)]
|
||||
else:
|
||||
|
|
|
@ -2,6 +2,7 @@ from base import PyexcelMultipleSheetBase
|
|||
import pyexcel
|
||||
import os
|
||||
from pyexcel.ext import xls
|
||||
from nose.tools import raises
|
||||
import sys
|
||||
|
||||
if sys.version_info[0] == 2 and sys.version_info[1] < 7:
|
||||
|
@ -56,9 +57,17 @@ class TestAddBooks:
|
|||
assert b1['Sheet1'].to_array() == self.content['Sheet1']
|
||||
|
||||
def test_load_a_single_sheet2(self):
|
||||
b1 = pyexcel.load_book(self.testfile, sheet_index=0)
|
||||
b1 = pyexcel.load_book(self.testfile, sheet_index=2)
|
||||
assert len(b1.sheet_names()) == 1
|
||||
assert b1['Sheet1'].to_array() == self.content['Sheet1']
|
||||
assert b1['Sheet3'].to_array() == self.content['Sheet3']
|
||||
|
||||
@raises(IndexError)
|
||||
def test_load_a_single_sheet3(self):
|
||||
pyexcel.load_book(self.testfile, sheet_index=10000)
|
||||
|
||||
@raises(ValueError)
|
||||
def test_load_a_single_sheet4(self):
|
||||
pyexcel.load_book(self.testfile, sheet_name="Not exist")
|
||||
|
||||
def test_delete_sheets(self):
|
||||
b1 = pyexcel.load_book(self.testfile)
|
||||
|
|
Loading…
Reference in New Issue