Skip to content

Commit 9f38118

Browse files
committed
improve test coverage
1 parent fe1c6d7 commit 9f38118

File tree

1 file changed

+53
-2
lines changed

1 file changed

+53
-2
lines changed

tests/test_webio.py

+53-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ def load_book(self, filename=None, **keywords):
2525
return pe.get_book(file_name=filename, **keywords)
2626

2727

28+
class TestExtendedInput(webio.ExcelInputInMultiDict):
29+
"""This is sample implementation that read excel source from file"""
30+
def get_file_tuple(self, field_name):
31+
return field_name
32+
33+
2834
def dumpy_response(content, content_type=None, status=200):
2935
"""A dummy response"""
3036
f = open(OUTPUT, 'wb')
@@ -46,6 +52,11 @@ def test_load_book(self):
4652
testinput = webio.ExcelInput()
4753
testinput.get_book(filename="test") # booom
4854

55+
@raises(NotImplementedError)
56+
def test_excel_input_get_file_tuple(self):
57+
testinput = webio.ExcelInputInMultiDict()
58+
testinput.get_file_tuple(field_name="test") # booom
59+
4960
def test_get_sheet(self):
5061
myinput = TestInput()
5162
sheet = myinput.get_sheet(unrelated="foo bar")
@@ -82,7 +93,6 @@ def test_dummy_function(self):
8293

8394

8495
# excel inputs
85-
8696
class TestExcelInput:
8797
def setUp(self):
8898
self.data = [
@@ -134,6 +144,27 @@ def test_save_to_database(self):
134144
def tearDown(self):
135145
os.unlink(self.testfile)
136146

147+
class TestExcelInput2:
148+
def setUp(self):
149+
self.data = [
150+
["X", "Y", "Z"],
151+
[1, 2, 3],
152+
[4, 5, 6]
153+
]
154+
sheet = pe.Sheet(self.data)
155+
self.testfile = "testfile.xls"
156+
sheet.save_as(self.testfile)
157+
158+
def tearDown(self):
159+
os.unlink(self.testfile)
160+
161+
def test_get_sheet(self):
162+
myinput = TestExtendedInput()
163+
f = open(self.testfile, 'rb')
164+
sheet = myinput.get_sheet(field_name=('xls', f))
165+
assert sheet.to_array() == self.data
166+
f.close()
167+
137168

138169
class TestExcelInputOnBook:
139170
def setUp(self):
@@ -173,8 +204,28 @@ def test_save_to_database(self):
173204
def tearDown(self):
174205
os.unlink(self.testfile)
175206

176-
## responses
177207

208+
class TestExcelInput2OnBook:
209+
def setUp(self):
210+
self.data = [['X', 'Y', 'Z'], [1, 2, 3], [4, 5, 6]]
211+
self.data1 = [['A', 'B', 'C'], [1, 2, 3], [4, 5, 6]]
212+
mydict = OrderedDict()
213+
mydict.update({'sheet1': self.data})
214+
mydict.update({'sheet2': self.data1})
215+
book = pe.Book(mydict)
216+
self.testfile = "testfile.xls"
217+
book.save_as(self.testfile)
218+
219+
def test_get_book(self):
220+
myinput = TestExtendedInput()
221+
f = open(self.testfile,'rb')
222+
result = myinput.get_book(field_name=('xls', f))
223+
assert result["sheet1"].to_array() == self.data
224+
assert result["sheet2"].to_array() == self.data1
225+
f.close()
226+
227+
228+
## responses
178229
class TestResponse:
179230
def setUp(self):
180231
self.data = [

0 commit comments

Comments
 (0)