From 090ce3b2d0750f7c49f81a6aa3506e42f29be196 Mon Sep 17 00:00:00 2001 From: chfw Date: Thu, 20 Nov 2014 18:11:18 +0000 Subject: [PATCH] improve test coverage --- tests/fixtures/date_field.xls | Bin 0 -> 7168 bytes tests/test_formatters.py | 39 ++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 tests/fixtures/date_field.xls create mode 100644 tests/test_formatters.py diff --git a/tests/fixtures/date_field.xls b/tests/fixtures/date_field.xls new file mode 100644 index 0000000000000000000000000000000000000000..3224701e7c74e6f2caf5a906ed8d20caa3c24972 GIT binary patch literal 7168 zcmeHLU2IfE6h3#mTeg(8+rm}^sh27(&~51tl>&h-v{i_fHZ4L(AhK<5e_-1+WgGQD zS&BTEK!Sk;A4r6VCWgeHnCOET=o^WUs*wapOo~1ceOQdf5TWb$&Asa`>n`0jji%bU z`DW&x`9J5(IWzOsc;Up^j~CsNgs@(+WHOQ?*>Q9Y`P}HgOT>meX_JviBuYkhHq0On z+_&aR8QLL42SAz60h~Y%Fc)C?JS&|+%bT6*6ddS~0KTB;(jr4hhvgMWIsH%!jfo#3 zotE+TBAxnE)tMbX#(}AL#qxOm(|*&AX8{k}|Frwu|9L<@PyoOMNFh)J%m)?#ZlD-= z1Xu_>3M>K^1CIeqfD+(wKnIorrN9%wlfW{d3@8Vd11o@)Kn36dDuF71YpAwT=IfAO z4b)q-HAow*e2hD@xkL`+I3dMshkTxQg(hFw{#($9kL+VgFTMwDx4cN*X!7~H^?xdC zR&(%a)Xhs!(hXWR&Kfr8>1o9I@}VlZpyCZm15wc{I%UpN$rb#t?J*UXsyH99CZDM` zHx;D@x_KG3A_tFK8^NJ%f(;xHpZF!A6!oU7w8TD7&e6v{)3U9lW7Bgb_B?r){H{UzviQlaww{4mBTIXcf%)2y{fzn`877HdG2p zgsCf(rP9Jswn~dac9qT#%~9!skR!5JZHFV+Qg)vGU;sM%4I@}XipCRQlu}E|1kZy} zO5IVI1rNS4R2+j6Za=2UkFt->A>74^k{zZIr|00*>0}7%D?xo@8l}}qZkW#GBDR84 z4rv(7c}epk_Dabex*ND3CpvS&y*Ph^2f7Dm!(IrC(CiBuNVX3Q8W9{@o$@9A=(f6@ zZU7l8&`mMec(yfdpz8q}I1gR+U?H>^g{pfOy1V!Ooo`yZ+8bX`^bjb~u#9Y%h#W%6 zn0=*cQK8~dRd)fr+ful;rm|Ab?ts3{cuDUF4ElyV9Y)`X-#1)ZR#RKH$qkPO|2IXw zc3+>Nm$e^O1H7){GEAmUh1-qgarx!QAFjMUT6sO(xFRlpR!U)CdayixqvFv#TC{yM z)#Q2fohz>@9*UgIHTlMWwmO+hS1+m@63|ZO@>qai;}OBUOqjB9+9*Bdt(&4&Af%aE z@F2~U=YuqANMc(uJf3!6T~y2?h=}>8K|eUgYY;S3x2!u3CxZEL{>AdcHdpzHZ@+6~ zImdO&Mys5HFP8At^KbOEOsI0s!7V$i@+?&z2#y~-a^_a!7jQwGk6ZO(>ZB$=Njp_2 zyagptpD@*hvtZQ%$qH8^TOf9|M>NR^n>=ELSg^@l)sAhrK{wip)tq+@}FQ%v{(|8DAv;V#FQye^1q@nzOQEtU|6~&8Lj~6qzp0SwG z=1(!J-o3GbO!1okN{^786>nM3 zd75{w)`9Nfz=1$-P;Ys;+wkja*Hmuzbs2uY0WU7Hd7!t~JTjYYGLE5!=Aaq3G#gC9 z5OD`42CDbOk+*-o+t%+o|E5za%0Ib5bNLp)iweuV01ev~faj9k08Lsy!24GItQln{ZHv%f(=T>AL^vnJR!fbr8|JXjBxVqEe6EM~mm!^|t59jHRZ+vZelgN%mb4C!t>(yPoU~E` zk@k&mbqo&alo70d5HB8l``wCH;9eyYQi6C134oG1EVss|Q%iUKwWxd9>e3<27@=Fu g!B8*Ina!u+Z>;|*jD5ixe>##(`5*uO`frc_2g^>L6#xJL literal 0 HcmV?d00001 diff --git a/tests/test_formatters.py b/tests/test_formatters.py new file mode 100644 index 0000000..d391cf7 --- /dev/null +++ b/tests/test_formatters.py @@ -0,0 +1,39 @@ +import pyexcel as pe +import pyexcel.ext.xl +import datetime +import os + + +class TestDateFormat: + def test_reading_date_format(self): + """ + date time + 25/12/14 11:11:11 + 25/12/14 12:11:11 + 01/01/15 13:13:13 + 0.0 0.0 + """ + r = pe.Reader(os.path.join("tests", "fixtures", "date_field.xls")) + assert isinstance(r[1,0], datetime.date) == True + assert r[1,0].strftime("%d/%m/%y") == "25/12/14" + assert isinstance(r[1,1], datetime.time) == True + assert r[1,1].strftime("%H:%M:%S") == "11:11:11" + assert r[4,0].strftime("%d/%m/%Y") == "01/01/1900" + assert r[4,1].strftime("%H:%M:%S") == "00:00:00" + + def test_writing_date_format(self): + excel_filename = "testdateformat.xls" + data = [[datetime.date(2014,12,25), + datetime.time(11,11,11), + datetime.datetime(2014,12,25,11,11,11)]] + w = pe.Writer(excel_filename) + w.write_rows(data) + w.close() + r = pe.Reader(excel_filename) + assert isinstance(r[0,0], datetime.date) == True + assert r[0,0].strftime("%d/%m/%y") == "25/12/14" + assert isinstance(r[0,1], datetime.time) == True + assert r[0,1].strftime("%H:%M:%S") == "11:11:11" + assert isinstance(r[0,2], datetime.date) == True + assert r[0,2].strftime("%d/%m/%y") == "25/12/14" + os.unlink(excel_filename) \ No newline at end of file