From 20be2e582606d20620d106fb0f45268c75d526f4 Mon Sep 17 00:00:00 2001 From: "Oleg E. Peil" Date: Tue, 7 Feb 2017 10:31:28 +0100 Subject: [PATCH] Modified the way group tests compare output Instead of comparing text output files the tests are now done on h5-files. The latter are compared with a finite precision eliminating thus a problem of platform-dependence of the results. --- test/plovasp/proj_group/.gitignore | 1 + test/plovasp/proj_group/mytest.py | 13 ++++++ test/plovasp/proj_group/projortho.out | 10 ----- test/plovasp/proj_group/projortho.out.h5 | Bin 0 -> 2544 bytes test/plovasp/proj_group/projortho_2site.out | 22 ---------- .../plovasp/proj_group/projortho_2site.out.h5 | Bin 0 -> 2944 bytes test/plovasp/proj_group/projortho_normion.out | 22 ---------- .../proj_group/projortho_normion.out.h5 | Bin 0 -> 2944 bytes test/plovasp/proj_group/test_all.py | 2 +- test/plovasp/proj_group/test_one_site.py | 39 ++++++++++++------ test/plovasp/proj_group/test_two_site.py | 39 ++++++++++++------ 11 files changed, 69 insertions(+), 79 deletions(-) delete mode 100644 test/plovasp/proj_group/projortho.out create mode 100644 test/plovasp/proj_group/projortho.out.h5 delete mode 100644 test/plovasp/proj_group/projortho_2site.out create mode 100644 test/plovasp/proj_group/projortho_2site.out.h5 delete mode 100644 test/plovasp/proj_group/projortho_normion.out create mode 100644 test/plovasp/proj_group/projortho_normion.out.h5 diff --git a/test/plovasp/proj_group/.gitignore b/test/plovasp/proj_group/.gitignore index 1ed2bd4a..f761dc19 100644 --- a/test/plovasp/proj_group/.gitignore +++ b/test/plovasp/proj_group/.gitignore @@ -1,2 +1,3 @@ *.pyc *.test +*.test.h5 diff --git a/test/plovasp/proj_group/mytest.py b/test/plovasp/proj_group/mytest.py index fb0c64e8..9d28fdbe 100644 --- a/test/plovasp/proj_group/mytest.py +++ b/test/plovasp/proj_group/mytest.py @@ -5,6 +5,7 @@ Module defining a custom TestCase with extra functionality. import unittest import numpy as np import difflib +from pytriqs.utility.h5diff import h5diff class MyTestCase(unittest.TestCase): """ @@ -54,4 +55,16 @@ class MyTestCase(unittest.TestCase): if diff: return self.fail("Files '%s' and '%s' differ"%(file1, file2)) + def assertH5FileEqual(self, file1, file2): + """ + Compares two files using difflib. + Empty lines are ignored. + Files are assumed to be relatively small; + the data is truncated for files larger than MAX_SIZE bytes. + """ + try: + h5diff(file1, file2, precision=1e-6) + except RuntimeError as err: + if "FAILED" in err: + return self.fail("Files '%s' and '%s' differ"%(file1, file2)) diff --git a/test/plovasp/proj_group/projortho.out b/test/plovasp/proj_group/projortho.out deleted file mode 100644 index 474f4841..00000000 --- a/test/plovasp/proj_group/projortho.out +++ /dev/null @@ -1,10 +0,0 @@ -density matrix: [[[[ 0.54239242 -0.00069107 0.00000946 -0.00067639 -0.00000019] - [-0.00069107 0.54295547 0.00000486 0.00082855 -0.00002492] - [ 0.00000946 0.00000486 0.57155757 0.00000454 0.00000002] - [-0.00067639 0.00082855 0.00000454 0.54666342 0.00002474] - [-0.00000019 -0.00002492 0.00000002 0.00002474 0.57284179]]]] -overlap matrix: [[[[ 1. -0. 0. 0. 0.] - [-0. 1. -0. -0. 0.] - [ 0. -0. 1. -0. -0.] - [ 0. -0. -0. 1. 0.] - [ 0. 0. -0. 0. 1.]]]] diff --git a/test/plovasp/proj_group/projortho.out.h5 b/test/plovasp/proj_group/projortho.out.h5 new file mode 100644 index 0000000000000000000000000000000000000000..f81708f671091943978a07b2ec943042aa5a52ce GIT binary patch literal 2544 zcmeD5aB<`1lHy_j0S*oZ76t(@6Gr@pf)AV!5f~pPp8#brLg@}Dy@CnCU}OM61_lYJ zxFFPgbaf#?uC5F~l`!*RG*lad0Skl$GY2LRk;eeFB=!pj?KO z)V$)%lFInp#FC=S3I>M!vecrS!~!@UmQD>|8VJyg3~b=^3n4%$)B~)8kp*HB%sd#) z3N;T#!^B}UOdLit19JvQPEf&~fdj19fx(2E!Q?+P#2{9nC`g`(i3w~32UI;XV**4u z!wHB&C@BOr1*CZCq?y3rg18q&5e1xJKYtfS1}3O23=9fTcj7V%3`gozK{ zbfp0;>FJxUMp*QZ81Hs@PY!pFerP`-!)mJhQn&pL4O=`SZa%ha7I0(#tLe6XtNQoz z%1NF3CPC#h6}{D;#6PreShd;HH0_GrBQuHHS!&+)2ST5o$WZ#V52ha`zd34_xUttG z`-Ynb?__Xaw)@V(sgUs~1aAHzk7Ucm%mFfxE31A_!q zTo7tLy1I}cS62q0N|^aD8mf)KfCa*WnFA9arAI~xc(^(SfP5MO^{xh#J^@WNo9O)Vo6bE1p`BVS!z*EVgZ~FOQ!}f4FqUL1~zc|g%F?=>H*fl$O175W**EL ztWfh{G$DCrV9o%k5mc~e-~j7&U@+lkF!|36F^Cl?3X*4HVgeh*0aee;m;h1EFac%- zSc4GM6p$d#Gy)l zryP&FTC(S!{krJn%2|dF>{rOWf3u#q-u{{+Uy*AN&;Ch;7ZKS(Z_vD zpz>V5X8J2mzGr{j^Ppk3Fth!t#fFSdhOPTI%Sk0Y*vq>A3RM3IsQlf(&P`u{{#d^M z=`&v!Vf#JKdv=IMJl;12WZK=a(C>X#VS|)x~OQs7HU7t{Jl{9kD&6C zh3tRF0{!s~+^~9Y|6rTejR`lF*)TLDDMqx`?qOK9dHdN@3-&k|ILtB-X|RFGLn@aK z_6!S-FP6$%U~^#O@f1aoT{aA+2bXxAsow+F50!`1gFy8Sljba`U$=*0!43WUUv|OG zhwF#QgLA?M`v#9$b|K0u;P%7Khw6vP!`$-+>W>2vmsM^~Y_VZ*n9}E4xxj{j`P+JP zyA697u4NtB9=Op4CJ$53z@Q&?+`M`Z!=#Wk91K8xQ`mDG^;hhH>xat!gPPCq;KS(+ pM}gtA!OMEnECv9t_sKiqtneyBXmd;lS8&~^X- literal 0 HcmV?d00001 diff --git a/test/plovasp/proj_group/projortho_normion.out b/test/plovasp/proj_group/projortho_normion.out deleted file mode 100644 index bbb59d9a..00000000 --- a/test/plovasp/proj_group/projortho_normion.out +++ /dev/null @@ -1,22 +0,0 @@ -density matrix: [[[[ 0.56016062 0.01202778 -0.00006002 0.00164142 -0.0000189 ] - [ 0.01202778 0.5465868 0.0000203 -0.00199428 -0.00001706] - [-0.00006002 0.0000203 0.54446136 0.00006678 -0.00003108] - [ 0.00164142 -0.00199428 0.00006678 0.48839256 0.00013617] - [-0.0000189 -0.00001706 -0.00003108 0.00013617 0.54338373]] - - [[ 0.56260435 0.00750293 -0.00005427 0.00661288 -0.00001657] - [ 0.00750293 0.53541612 0.0000371 -0.01036245 -0.00004262] - [-0.00005427 0.0000371 0.54445834 0.0000739 -0.00000814] - [ 0.00661288 -0.01036245 0.0000739 0.49707557 0.00013642] - [-0.00001657 -0.00004262 -0.00000814 0.00013642 0.54337993]]]] -overlap matrix: [[[[ 1. -0. -0. 0. 0.] - [-0. 1. 0. 0. 0.] - [-0. 0. 1. -0. 0.] - [ 0. 0. -0. 1. 0.] - [ 0. 0. 0. 0. 1.]] - - [[ 1. -0. -0. -0. -0.] - [-0. 1. 0. 0. 0.] - [-0. 0. 1. -0. 0.] - [-0. 0. -0. 1. -0.] - [-0. 0. 0. -0. 1.]]]] diff --git a/test/plovasp/proj_group/projortho_normion.out.h5 b/test/plovasp/proj_group/projortho_normion.out.h5 new file mode 100644 index 0000000000000000000000000000000000000000..b147eae14588779eb4ee3e20ee3082e1be628efb GIT binary patch literal 2944 zcmeD5aB<`1lHy_j0S*oZ76t(@6Gr@pf(CAg2#gPtPk=HQp>zk7Ucm%mFfxE31A_!q zTo7tLy1I}cS62q0N|^aD8mf)KfCa*WnFA9arAI~xc(^(SfP5MO^{xh#J^@WNo9O)Vo6bE1p`BVS!z*EVgZ~FOQ!}f4FqUL1~zc|g%F?=>H*fl$O175W**EL ztWfh{G$DCrV9o%k5mc~e-~j7&U@+lkF!|36F^Cl?3X*4HVgeh*0aee;m;h1EFac%- zSc4GM6p-NhNi%`L1#vILG|I_fKYtfS1}3O23=9fTcj7V`mR~Di0fI~62ooQ?>FNU~ zBr52eu0~k&j~MSRPW$xj>YIo5-@oi%&$6h){;zlEqqcJX{R)Og+Vh`8*;{b^@Rh&t zdEYOn{2#5bnTu;5+S{LJdh*TvtDQrhyR2_m!v4P}UA(_O`nc~ORKFusev?+atyRuL z`yK2V=Q0`v?LYm$c-h690dBqtR6k5!koVeyOOE&L*DuT4sBlveZvP*s`7r%!q4KIf z-g%@YKeSJJ)_vs`!z23-wmP<{yX)*b8fOG8E9TjM!lF4wMy%TY+09j_rp15U_X8^b z_khlC1*M1f>B1>{(uHiLu-~07|PaM!6 z|G*8a_x23!Kc7!NG-VIN0jG1(Vbk_7{BSfg=a02%*vtGVenO!QOdiq>1FCmekoWu7 z1e*sw`m#PDD{L4Z{JN9prf&n+50yu#-=Sy}uwoCxizl7Y#;a{$=EL9kRn`Cp~o?GpT_6;@+4(vkDrxw}3^fN%^A@w=XT?~O6O(Khd;goeO lwrPb8%zU_hs65O)3^EBepXN@6+YdJ%svjl~sWv~@0{|{#)6M_@ literal 0 HcmV?d00001 diff --git a/test/plovasp/proj_group/test_all.py b/test/plovasp/proj_group/test_all.py index 18a0be63..95b429ab 100644 --- a/test/plovasp/proj_group/test_all.py +++ b/test/plovasp/proj_group/test_all.py @@ -5,7 +5,7 @@ import unittest if __name__ == '__main__': # suite = unittest.TestLoader().discover('./') - suite = unittest.TestLoader().discover('./', pattern='test_two*') + suite = unittest.TestLoader().discover('./', pattern='test_one*') unittest.TextTestRunner(verbosity=2, buffer=True).run(suite) # unittest.TextTestRunner(verbosity=2, buffer=False).run(suite) diff --git a/test/plovasp/proj_group/test_one_site.py b/test/plovasp/proj_group/test_one_site.py index 76be6ed7..9a4939e0 100644 --- a/test/plovasp/proj_group/test_one_site.py +++ b/test/plovasp/proj_group/test_one_site.py @@ -9,6 +9,7 @@ from pytriqs.applications.dft.converters.plovasp.elstruct import ElectronicStruc from pytriqs.applications.dft.converters.plovasp.inpconf import ConfigParameters from pytriqs.applications.dft.converters.plovasp.proj_shell import ProjectorShell from pytriqs.applications.dft.converters.plovasp.proj_group import ProjectorGroup +from pytriqs.archive import HDFArchive import mytest ################################################################################ @@ -47,15 +48,22 @@ class TestProjectorGroup(mytest.MyTestCase): dens_mat, overl = self.proj_sh.density_matrix(self.el_struct) - testout = _rpath + 'projortho.out.test' - with open(testout, 'wt') as f: - f.write("density matrix: %s\n"%(dens_mat)) - f.write("overlap matrix: %s\n"%(overl)) +# testout = _rpath + 'projortho.out.test' +# with open(testout, 'wt') as f: +# f.write("density matrix: %s\n"%(dens_mat)) +# f.write("overlap matrix: %s\n"%(overl)) + testout = _rpath + 'projortho.test.h5' + with HDFArchive(testout, 'w') as h5test: + h5test['density_matrix'] = dens_mat + h5test['overlap_matrix'] = overl +# FIXME: seems redundant, as 'overl' is written to the file anyway self.assertEqual(overl, np.eye(5)) - expected_file = _rpath + 'projortho.out' - self.assertFileEqual(testout, expected_file) +# expected_file = _rpath + 'projortho.out' + expected_file = _rpath + 'projortho.out.h5' +# self.assertFileEqual(testout, expected_file) + self.assertH5FileEqual(testout, expected_file) # Scenario 2 def test_ortho_normion(self): @@ -64,14 +72,21 @@ class TestProjectorGroup(mytest.MyTestCase): dens_mat, overl = self.proj_sh.density_matrix(self.el_struct) - testout = _rpath + 'projortho.out.test' - with open(testout, 'wt') as f: - f.write("density matrix: %s\n"%(dens_mat)) - f.write("overlap matrix: %s\n"%(overl)) +# testout = _rpath + 'projortho.out.test' +# with open(testout, 'wt') as f: +# f.write("density matrix: %s\n"%(dens_mat)) +# f.write("overlap matrix: %s\n"%(overl)) + testout = _rpath + 'projortho.test.h5' + with HDFArchive(testout, 'w') as h5test: + h5test['density_matrix'] = dens_mat + h5test['overlap_matrix'] = overl +# FIXME: seems redundant, as 'overl' is written to the file anyway self.assertEqual(overl, np.eye(5)) - expected_file = _rpath + 'projortho.out' - self.assertFileEqual(testout, expected_file) +# expected_file = _rpath + 'projortho.out' +# self.assertFileEqual(testout, expected_file) + expected_file = _rpath + 'projortho.out.h5' + self.assertH5FileEqual(testout, expected_file) diff --git a/test/plovasp/proj_group/test_two_site.py b/test/plovasp/proj_group/test_two_site.py index c29c18f9..4f62961a 100644 --- a/test/plovasp/proj_group/test_two_site.py +++ b/test/plovasp/proj_group/test_two_site.py @@ -9,6 +9,7 @@ from pytriqs.applications.dft.converters.plovasp.elstruct import ElectronicStruc from pytriqs.applications.dft.converters.plovasp.inpconf import ConfigParameters from pytriqs.applications.dft.converters.plovasp.proj_shell import ProjectorShell from pytriqs.applications.dft.converters.plovasp.proj_group import ProjectorGroup +from pytriqs.archive import HDFArchive import mytest ################################################################################ @@ -50,16 +51,23 @@ class TestProjectorGroupTwoSite(mytest.MyTestCase): dens_mat, overl = self.proj_sh.density_matrix(self.el_struct) - testout = _rpath + 'projortho_2site.out.test' - with open(testout, 'wt') as f: - f.write("density matrix: %s\n"%(dens_mat)) - f.write("overlap matrix: %s\n"%(overl)) +# testout = _rpath + 'projortho_2site.out.test' +# with open(testout, 'wt') as f: +# f.write("density matrix: %s\n"%(dens_mat)) +# f.write("overlap matrix: %s\n"%(overl)) + testout = _rpath + 'projortho_2site.test.h5' + with HDFArchive(testout, 'w') as h5test: + h5test['density_matrix'] = dens_mat + h5test['overlap_matrix'] = overl +# FIXME: redundant self.assertEqual(overl[0, 0, ...], np.eye(5)) self.assertEqual(overl[0, 1, ...], np.eye(5)) - expected_file = _rpath + 'projortho_2site.out' - self.assertFileEqual(testout, expected_file) +# expected_file = _rpath + 'projortho_2site.out' +# self.assertFileEqual(testout, expected_file) + expected_file = _rpath + 'projortho_2site.out.h5' + self.assertH5FileEqual(testout, expected_file) # Scenario 2 def test_ortho_normion(self): @@ -68,15 +76,22 @@ class TestProjectorGroupTwoSite(mytest.MyTestCase): dens_mat, overl = self.proj_sh.density_matrix(self.el_struct) - testout = _rpath + 'projortho_normion.out.test' - with open(testout, 'wt') as f: - f.write("density matrix: %s\n"%(dens_mat)) - f.write("overlap matrix: %s\n"%(overl)) +# testout = _rpath + 'projortho_normion.out.test' +# with open(testout, 'wt') as f: +# f.write("density matrix: %s\n"%(dens_mat)) +# f.write("overlap matrix: %s\n"%(overl)) + testout = _rpath + 'projortho_normion.test.h5' + with HDFArchive(testout, 'w') as h5test: + h5test['density_matrix'] = dens_mat + h5test['overlap_matrix'] = overl +# FIXME: redundant self.assertEqual(overl[0, 0, ...], np.eye(5)) self.assertEqual(overl[0, 1, ...], np.eye(5)) - expected_file = _rpath + 'projortho_normion.out' - self.assertFileEqual(testout, expected_file) +# expected_file = _rpath + 'projortho_normion.out' +# self.assertFileEqual(testout, expected_file) + expected_file = _rpath + 'projortho_normion.out.h5' + self.assertH5FileEqual(testout, expected_file)