Skip to content

Commit a0b8ae1

Browse files
committed
update tests due to the removal of writers.py in pyexcel 0.1.8
1 parent 7e51fa6 commit a0b8ae1

File tree

4 files changed

+9
-41
lines changed

4 files changed

+9
-41
lines changed

tests/base.py

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@
33

44

55
def create_sample_file1(file):
6-
w = pyexcel.Writer(file)
76
data=['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 1.1, 1]
87
table = []
98
table.append(data[:4])
109
table.append(data[4:8])
1110
table.append(data[8:12])
12-
w.write_array(table)
13-
w.close()
11+
pyexcel.save_as(dest_file_name=file, array=table)
1412

1513

1614
class PyexcelHatWriterBase:
@@ -24,9 +22,7 @@ class PyexcelHatWriterBase:
2422
}
2523

2624
def test_series_table(self):
27-
w = pyexcel.Writer(self.testfile)
28-
w.write_dict(self.content)
29-
w.close()
25+
pyexcel.save_as(adict=self.content, dest_file_name=self.testfile)
3026
r = pyexcel.SeriesReader(self.testfile)
3127
actual = pyexcel.utils.to_dict(r)
3228
assert actual == self.content
@@ -47,9 +43,7 @@ class PyexcelWriterBase:
4743
]
4844

4945
def _create_a_file(self, file):
50-
w = pyexcel.Writer(file)
51-
w.write_array(self.content)
52-
w.close()
46+
pyexcel.save_as(dest_file_name=file, array=self.content)
5347

5448
def test_write_array(self):
5549
self._create_a_file(self.testfile)
@@ -66,9 +60,7 @@ def test_write_reader(self):
6660
"""
6761
self._create_a_file(self.testfile)
6862
r = pyexcel.Reader(self.testfile)
69-
w2 = pyexcel.Writer(self.testfile2)
70-
w2.write_reader(r)
71-
w2.close()
63+
r.save_as(self.testfile2)
7264
r2 = pyexcel.Reader(self.testfile2)
7365
r2.format(int)
7466
actual = pyexcel.utils.to_array(r2.rows())
@@ -78,9 +70,7 @@ def test_write_reader(self):
7870
class PyexcelMultipleSheetBase:
7971

8072
def _write_test_file(self, filename):
81-
w = pyexcel.BookWriter(filename)
82-
w.write_book_from_dict(self.content)
83-
w.close()
73+
pyexcel.save_book_as(dest_file_name=filename, bookdict=self.content)
8474

8575
def _clean_up(self):
8676
if os.path.exists(self.testfile2):
@@ -122,22 +112,6 @@ def test_iterate_through_sheets(self):
122112
data = pyexcel.utils.to_array(s)
123113
assert self.content[s.name] == data
124114

125-
def test_write_a_book_reader(self):
126-
b = pyexcel.BookReader(self.testfile)
127-
bw = pyexcel.BookWriter(self.testfile2)
128-
for s in b:
129-
data = pyexcel.utils.to_array(s)
130-
sheet = bw.create_sheet(s.name)
131-
sheet.write_array(data)
132-
sheet.close()
133-
bw.close()
134-
x = pyexcel.BookReader(self.testfile2)
135-
for s in x:
136-
data = pyexcel.utils.to_array(s)
137-
print(data)
138-
print(self.content[s.name])
139-
assert self.content[s.name] == data
140-
141115
def test_random_access_operator(self):
142116
r = pyexcel.BookReader(self.testfile)
143117
value = r["Sheet1"][0,1]

tests/test_formatters.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ def test_writing_date_format(self):
2626
data = [[datetime.date(2014,12,25),
2727
datetime.time(11,11,11),
2828
datetime.datetime(2014,12,25,11,11,11)]]
29-
w = pe.Writer(excel_filename)
30-
w.write_rows(data)
31-
w.close()
29+
pe.save_as(dest_file_name=excel_filename, array=data)
3230
r = pe.Reader(excel_filename)
3331
assert isinstance(r[0,0], datetime.date) == True
3432
assert r[0,0].strftime("%d/%m/%y") == "25/12/14"

tests/test_mutliple_sheets.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ def _write_test_file(self, file):
3636
3,3,3,3
3737
"""
3838
self.rows = 3
39-
w = pyexcel.BookWriter(file)
40-
w.write_book_from_dict(self.content)
41-
w.close()
39+
pyexcel.save_book_as(bookdict=self.content,dest_file_name=file)
4240

4341
def setUp(self):
4442
self.testfile = "multiple1.xls"

tests/test_stringio.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,8 @@ def test_xls_output_stringio(self):
2929
[1, 2, 3],
3030
[4, 5, 6]
3131
]
32-
io = StringIO()
33-
w = pyexcel.Writer(("xls",io))
34-
w.write_rows(data)
35-
w.close()
32+
io = pyexcel.save_as(dest_file_type="xls",
33+
array=data)
3634
r = pyexcel.Reader(("xls", io.getvalue()))
3735
result=[1, 2, 3, 4, 5, 6]
3836
actual = pyexcel.utils.to_array(r.enumerate())

0 commit comments

Comments
 (0)