Skip to content

Commit 090ce3b

Browse files
committed
improve test coverage
1 parent 76ca37f commit 090ce3b

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

tests/fixtures/date_field.xls

7 KB
Binary file not shown.

tests/test_formatters.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import pyexcel as pe
2+
import pyexcel.ext.xl
3+
import datetime
4+
import os
5+
6+
7+
class TestDateFormat:
8+
def test_reading_date_format(self):
9+
"""
10+
date time
11+
25/12/14 11:11:11
12+
25/12/14 12:11:11
13+
01/01/15 13:13:13
14+
0.0 0.0
15+
"""
16+
r = pe.Reader(os.path.join("tests", "fixtures", "date_field.xls"))
17+
assert isinstance(r[1,0], datetime.date) == True
18+
assert r[1,0].strftime("%d/%m/%y") == "25/12/14"
19+
assert isinstance(r[1,1], datetime.time) == True
20+
assert r[1,1].strftime("%H:%M:%S") == "11:11:11"
21+
assert r[4,0].strftime("%d/%m/%Y") == "01/01/1900"
22+
assert r[4,1].strftime("%H:%M:%S") == "00:00:00"
23+
24+
def test_writing_date_format(self):
25+
excel_filename = "testdateformat.xls"
26+
data = [[datetime.date(2014,12,25),
27+
datetime.time(11,11,11),
28+
datetime.datetime(2014,12,25,11,11,11)]]
29+
w = pe.Writer(excel_filename)
30+
w.write_rows(data)
31+
w.close()
32+
r = pe.Reader(excel_filename)
33+
assert isinstance(r[0,0], datetime.date) == True
34+
assert r[0,0].strftime("%d/%m/%y") == "25/12/14"
35+
assert isinstance(r[0,1], datetime.time) == True
36+
assert r[0,1].strftime("%H:%M:%S") == "11:11:11"
37+
assert isinstance(r[0,2], datetime.date) == True
38+
assert r[0,2].strftime("%d/%m/%y") == "25/12/14"
39+
os.unlink(excel_filename)

0 commit comments

Comments
 (0)