Skip to content

Commit 54c87e6

Browse files
committed
test against pyexcel v0.3.0
1 parent 3654738 commit 54c87e6

File tree

4 files changed

+34
-49
lines changed

4 files changed

+34
-49
lines changed

rnd_requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
https://github.com/pyexcel/pyexcel-io/archive/master.zip
2-
https://github.com/pyexcel/pyexcel-xls/archive/master.zip
1+
https://github.com/pyexcel/pyexcel/archive/master.zip
2+

tests/base.py

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import pyexcel
21
import os
2+
import pyexcel
3+
from nose.tools import eq_
34

45

56
def create_sample_file1(file):
@@ -24,8 +25,7 @@ class PyexcelHatWriterBase:
2425
def test_series_table(self):
2526
pyexcel.save_as(adict=self.content, dest_file_name=self.testfile)
2627
r = pyexcel.get_sheet(file_name=self.testfile, name_columns_by_row=0)
27-
actual = pyexcel.utils.to_dict(r)
28-
assert actual == self.content
28+
eq_(r.dict, self.content)
2929

3030

3131
class PyexcelWriterBase:
@@ -48,7 +48,7 @@ def _create_a_file(self, file):
4848
def test_write_array(self):
4949
self._create_a_file(self.testfile)
5050
r = pyexcel.get_sheet(file_name=self.testfile)
51-
actual = pyexcel.utils.to_array(r.rows())
51+
actual = list(r.rows())
5252
assert actual == self.content
5353

5454

@@ -72,36 +72,17 @@ def test_sheet_names(self):
7272

7373
def test_reading_through_sheets(self):
7474
b = pyexcel.BookReader(self.testfile)
75-
data = pyexcel.utils.to_array(b["Sheet1"].rows())
75+
data = list(b["Sheet1"].rows())
7676
expected = [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3]]
7777
assert data == expected
78-
data = pyexcel.utils.to_array(b["Sheet2"].rows())
78+
data = list(b["Sheet2"].rows())
7979
expected = [[4, 4, 4, 4], [5, 5, 5, 5], [6, 6, 6, 6]]
8080
assert data == expected
81-
data = pyexcel.utils.to_array(b["Sheet3"].rows())
81+
data = list(b["Sheet3"].rows())
8282
expected = [[u'X', u'Y', u'Z'], [1, 4, 7], [2, 5, 8], [3, 6, 9]]
8383
assert data == expected
8484
sheet3 = b["Sheet3"]
8585
sheet3.name_columns_by_row(0)
86-
data = pyexcel.utils.to_array(b["Sheet3"].rows())
86+
data = list(b["Sheet3"].rows())
8787
expected = [[1, 4, 7], [2, 5, 8], [3, 6, 9]]
8888
assert data == expected
89-
90-
def test_iterate_through_sheets(self):
91-
b = pyexcel.BookReader(self.testfile)
92-
for s in b:
93-
data = pyexcel.utils.to_array(s)
94-
assert self.content[s.name] == data
95-
si = pyexcel.iterators.SheetIterator(b)
96-
for s in si:
97-
data = pyexcel.utils.to_array(s)
98-
assert self.content[s.name] == data
99-
100-
def test_random_access_operator(self):
101-
r = pyexcel.BookReader(self.testfile)
102-
value = r["Sheet1"][0, 1]
103-
assert value == 1
104-
value = r["Sheet3"][0, 1]
105-
assert value == 'Y'
106-
r["Sheet3"].name_columns_by_row(0)
107-
assert r["Sheet3"][0, 1] == 4
Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import os
22
import sys
3-
from nose.tools import raises
4-
53
import pyexcel
6-
4+
from nose.tools import raises
75
from base import PyexcelMultipleSheetBase
86

97
if sys.version_info[0] == 2 and sys.version_info[1] < 7:
@@ -44,7 +42,8 @@ def _write_test_file(self, file):
4442
3,3,3,3
4543
"""
4644
self.rows = 3
47-
pyexcel.save_book_as(bookdict=self.content, dest_file_name=file)
45+
pyexcel.save_book_as(bookdict=self.content,
46+
dest_file_name=file)
4847

4948
def setUp(self):
5049
self.testfile = "multiple3.xlsx"
@@ -68,7 +67,11 @@ def test_load_a_single_sheet2(self):
6867

6968
@raises(IndexError)
7069
def test_load_a_single_sheet3(self):
71-
pyexcel.load_book(self.testfile, sheet_index=10000)
70+
pyexcel.get_book(file_name=self.testfile, sheet_index=10000)
71+
72+
@raises(ValueError)
73+
def test_load_a_single_sheet4(self):
74+
pyexcel.get_book(file_name=self.testfile, sheet_name="Not exist")
7275

7376
def test_delete_sheets(self):
7477
b1 = pyexcel.load_book(self.testfile)
@@ -105,7 +108,7 @@ def test_add_book1(self):
105108
b1 = pyexcel.get_book(file_name=self.testfile)
106109
b2 = pyexcel.get_book(file_name=self.testfile2)
107110
b3 = b1 + b2
108-
content = pyexcel.utils.to_dict(b3)
111+
content = b3.dict
109112
sheet_names = content.keys()
110113
assert len(sheet_names) == 6
111114
for name in sheet_names:
@@ -118,12 +121,12 @@ def test_add_book1(self):
118121

119122
def test_add_book1_in_place(self):
120123
"""
121-
test this scenario book1 += book2
124+
test this scenario: book1 += book2
122125
"""
123126
b1 = pyexcel.BookReader(self.testfile)
124127
b2 = pyexcel.BookReader(self.testfile2)
125128
b1 += b2
126-
content = pyexcel.utils.to_dict(b1)
129+
content = b1.dict
127130
sheet_names = content.keys()
128131
assert len(sheet_names) == 6
129132
for name in sheet_names:
@@ -136,12 +139,12 @@ def test_add_book1_in_place(self):
136139

137140
def test_add_book2(self):
138141
"""
139-
test this scenario book3 = book1 + sheet3
142+
test this scenario: book3 = book1 + sheet3
140143
"""
141144
b1 = pyexcel.BookReader(self.testfile)
142145
b2 = pyexcel.BookReader(self.testfile2)
143146
b3 = b1 + b2["Sheet3"]
144-
content = pyexcel.utils.to_dict(b3)
147+
content = b3.dict
145148
sheet_names = content.keys()
146149
assert len(sheet_names) == 4
147150
for name in sheet_names:
@@ -154,12 +157,12 @@ def test_add_book2(self):
154157

155158
def test_add_book2_in_place(self):
156159
"""
157-
test this scenario book3 = book1 + sheet3
160+
test this scenario: book3 = book1 + sheet3
158161
"""
159162
b1 = pyexcel.BookReader(self.testfile)
160163
b2 = pyexcel.BookReader(self.testfile2)
161164
b1 += b2["Sheet3"]
162-
content = pyexcel.utils.to_dict(b1)
165+
content = b1.dict
163166
sheet_names = content.keys()
164167
assert len(sheet_names) == 4
165168
for name in sheet_names:
@@ -172,25 +175,25 @@ def test_add_book2_in_place(self):
172175

173176
def test_add_book3(self):
174177
"""
175-
test this scenario book3 = sheet1 + sheet2
178+
test this scenario: book3 = sheet1 + sheet2
176179
"""
177180
b1 = pyexcel.BookReader(self.testfile)
178181
b2 = pyexcel.BookReader(self.testfile2)
179182
b3 = b1["Sheet1"] + b2["Sheet3"]
180-
content = pyexcel.utils.to_dict(b3)
183+
content = b3.dict
181184
sheet_names = content.keys()
182185
assert len(sheet_names) == 2
183186
assert content["Sheet3"] == self.content["Sheet3"]
184187
assert content["Sheet1"] == self.content["Sheet1"]
185188

186189
def test_add_book4(self):
187190
"""
188-
test this scenario book3 = sheet1 + book
191+
test this scenario: book3 = sheet1 + book
189192
"""
190193
b1 = pyexcel.BookReader(self.testfile)
191194
b2 = pyexcel.BookReader(self.testfile2)
192195
b3 = b1["Sheet1"] + b2
193-
content = pyexcel.utils.to_dict(b3)
196+
content = b3.dict
194197
sheet_names = content.keys()
195198
assert len(sheet_names) == 4
196199
for name in sheet_names:

tests/test_stringio.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
from nose.tools import eq_
23
import pyexcel
34
from base import create_sample_file1
45

@@ -12,8 +13,8 @@ def test_ods_stringio(self):
1213
content = f.read()
1314
r = pyexcel.get_sheet(file_type="xlsx", file_content=content)
1415
result = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 1.1, 1]
15-
actual = pyexcel.utils.to_array(r.enumerate())
16-
assert result == actual
16+
actual = list(r.enumerate())
17+
eq_(result, actual)
1718
if os.path.exists(odsfile):
1819
os.unlink(odsfile)
1920

@@ -25,5 +26,5 @@ def test_xls_output_stringio(self):
2526
io = pyexcel.save_as(dest_file_type='xlsx', array=data)
2627
r = pyexcel.get_sheet(file_type="xlsx", file_content=io.getvalue())
2728
result = [1, 2, 3, 4, 5, 6]
28-
actual = pyexcel.utils.to_array(r.enumerate())
29-
assert result == actual
29+
actual = list(r.enumerate())
30+
eq_(result, actual)

0 commit comments

Comments
 (0)