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 00000000..f81708f6 Binary files /dev/null and b/test/plovasp/proj_group/projortho.out.h5 differ diff --git a/test/plovasp/proj_group/projortho_2site.out b/test/plovasp/proj_group/projortho_2site.out deleted file mode 100644 index ed2aba58..00000000 --- a/test/plovasp/proj_group/projortho_2site.out +++ /dev/null @@ -1,22 +0,0 @@ -density matrix: [[[[ 0.50361386 0.01210591 -0.00005976 0.00166392 -0.00001898] - [ 0.01210591 0.48889987 0.00001956 -0.00197949 -0.00001589] - [-0.00005976 0.00001956 0.48077169 0.00006637 -0.00003311] - [ 0.00166392 -0.00197949 0.00006637 0.43066013 0.0001357 ] - [-0.00001898 -0.00001589 -0.00003311 0.0001357 0.48025246]] - - [[ 0.5060551 0.00758141 -0.00005402 0.00663632 -0.00001664] - [ 0.00758141 0.47773011 0.00003639 -0.01034786 -0.00004147] - [-0.00005402 0.00003639 0.48077119 0.0000735 -0.00000922] - [ 0.00663632 -0.01034786 0.0000735 0.43934266 0.00013596] - [-0.00001664 -0.00004147 -0.00000922 0.00013596 0.48024702]]]] -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_2site.out.h5 b/test/plovasp/proj_group/projortho_2site.out.h5 new file mode 100644 index 00000000..1fa71ffe Binary files /dev/null and b/test/plovasp/proj_group/projortho_2site.out.h5 differ 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 00000000..b147eae1 Binary files /dev/null and b/test/plovasp/proj_group/projortho_normion.out.h5 differ 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)