<commit_before>#
#  ENVISIoN
#
#  Copyright (c) 2019 <NAME>
#  All rights reserved.
#
#  Redistribution and use in source and binary forms, with or without
#  modification, are permitted provided that the following conditions are met:
#
#  1. Redistributions of source code must retain the above copyright notice, this
#  list of conditions and the following disclaimer.
#  2. Redistributions in binary form must reproduce the above copyright notice,
#  this list of conditions and the following disclaimer in the documentation
#  and/or other materials provided with the distribution.
#
#  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
#  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
#  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
#  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
#  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
#  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
#  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
#  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
#  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
#  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#

#This file is created for the purpose of testing the parser system for
#visualisation of the pair-correlation function. The file uses the unittest python module.
#It can be called from the terminal with command: "python3 test_paircorrelation"


import os
import sys
import unittest

import h5py
import numpy

sys.path.insert(0, os.path.expanduser("~/ENVISIoN/envision/envision/parser"))
sys.path.insert(0, os.path.expanduser("~/ENVISIoN/envision/envision/parser/vasp"))

from PKF import _parse_pcdat, paircorrelation
from h5writer import _write_pcdat_onecol, _write_pcdat_multicol


# Test parsing correct line from file.
# Test that it is 256 values long.
# Test that it is t_0 and t_1
# Comment on new tests
# Write copyright on every file and push + merge it with master.

class except_n_error(unittest.TestCase):
	# Tests - for exception thrown for empty PCDAT-file
	def test_empty_file(self):
		dir_testfiles = os.path.expanduser("~/ENVISIoN/envision/envision/parser/tests/VASP")
		vasp_dir = os.path.expanduser(dir_testfiles + "/testdata/empty_PCDAT")
		h5file_path = os.path.join(dir_testfiles, "testh5file.hdf5")
		empty_file = os.path.join(vasp_dir, "PCDAT_empty")

		with self.assertRaises(Exception) as ex:
			_parse_pcdat(h5file_path, empty_file, vasp_dir)
		self.assertEqual("PCDAT-file is empty.", str(ex.exception))

	# Tests - to skip parsing if it's already done
	def test_is_parsed(self):
		dir_testfiles = os.path.expanduser("~/ENVISIoN/envision/envision/parser/tests/VASP")
	h5file_path = os.path.join(dir_testfiles, "testh5file.hdf5")

	testh5 = h5py.File(h5file_path, 'w')
	testh5.create_dataset('PairCorrelationFunc/test', (10,))
	testh5.close()
	self.assertFalse(paircorrelation(h5file_path, ''))
	os.remove(h5file_path)

# Tests - for exception to be thrown when PCDAT file is not found
def test_pcdat_file(self):
	dir_testfiles = os.path.expanduser("~/ENVISIoN/envision/envision/parser/tests/VASP")
vasp_dir = os.path.expanduser("~/ENVISIoN/envision/envision/parser/vasp/Tests/testdata/Modified VASP-files")
h5file_path = os.path.join(dir_testfiles, "testh5file.hdf5")

with self.assertRaises(Exception) as ex:
	paircorrelation(h5file_path, vasp_dir)
self.assertEqual("PCDAT-file not found.", str(ex.exception))

class parse_multitimes(unittest.TestCase):

	def test_write_pcdat_multicol(self):
		dir_testfiles = os.path.expanduser("~/ENVISIoN/envision/envision/parser/tests/VASP")
	dir_Cu = os.path.expanduser(dir_testfiles + "/testdata/Cu")
	file_Cu_t0nt1 = os.path.join(dir_Cu, "PCDAT")
	h5file_path = os.path.join(dir_testfiles, "testh5file.hdf5")

	pcdat_data = _parse_pcdat(h5file_path, file_Cu_t0nt1, dir_Cu)
	key0 = list(pcdat_data)[0]
	list0 = pcdat_data[key0]

	# Tests - to control pcdat_data's format
	# expected format is {'Cu':[0.00, 0.00,... 0.206,..]}
	self.assertIsInstance(pcdat_data, dict)
	self.assertEqual(str(key0), "Cu")
	self.assertIsInstance(list0, list)

	# Tests - to control pcdat_data has correct data
	# expected 513 values from 256*2 (t_0, and t_1) plus 1 other value
	self.assertEqual(len(list0), 513)
	self.assertEqual(list0[0], 0.000)
	self.assertEqual(list0[34], 0.206)
	self.assertEqual(list0[36], 1.469)
	self.assertEqual(list0[257], 0.000)
	self.assertEqual(list0[291], 0.411)
	self.assertEqual(list0[293], 1.286)


	# Create empty HDF5-file
	testh5 = h5py.File(h5file_path, 'w')
	group = list(testh5.keys())
	# Test - to show HDF5-file is empty.
	self.assertEqual(len(group), 0)
	testh5.close()

	# _write_pcdat_multicol is called for systems of one element, or multiple elements with no
	# average pair-correlation function.
	_write_pcdat_multicol(h5file_path, pcdat_data, 16, 256) #default APACO = 16, NPACO = 256

	testh5 = h5py.File(h5file_path, 'r')
	group = list(testh5.keys())

	# Test - to show HDF5-file is written to.
	self.assertNotEqual(len(group), 0)

	distance = testh5["PairCorrelationFunc/Iterations"]
	timeframes = list(testh5["PairCorrelationFunc/Elements/Cu"].keys())
	dataset_obj1 = testh5["PairCorrelationFunc/Elements/Cu/t_0"]
	dataset_obj2 = testh5["PairCorrelationFunc/Elements/Cu/t_1"]


	# Tests - to control the writing to HDF5-file
	self.assertIn("PairCorrelationFunc", testh5)
	self.assertIn("PairCorrelationFunc/Iterations", testh5)
	self.assertIn("PairCorrelationFunc/Elements", testh5)
	self.assertIn("PairCorrelationFunc/Elements/Cu", testh5)
	self.assertIn("PairCorrelationFunc/Elements/Cu/t_0", testh5)
	self.assertIn("PairCorrelationFunc/Elements/Cu/t_1", testh5)

	self.assertEqual(timeframes, ["t_0", "t_1"])
	self.assertIsInstance(dataset_obj1[()], numpy.ndarray)
	self.assertIsInstance(dataset_obj2[()], numpy.ndarray)
	self.assertEqual(dataset_obj1.shape, (256,))
	self.assertEqual(dataset_obj2.shape, (256,))
	self.assertEqual(dataset_obj1.attrs["element"], "Cu")
	self.assertEqual(dataset_obj2.attrs["element"], "Cu")

	self.assertIsInstance(distance[()], numpy.ndarray)
	self.assertEqual(distance.shape, (256,))
	# Tests - to control HDF5-file has correct data
	self.assertEqual(dataset_obj1[0], 0.000)
	self.assertEqual(dataset_obj1[34], 0.206)
	self.assertEqual(dataset_obj1[36], 1.469)

	self.assertEqual(dataset_obj2[0], 0.000)
	self.assertEqual(dataset_obj2[34], 0.411)
	self.assertEqual(dataset_obj2[36], 1.286)

	testh5.close()
	os.remove(h5file_path)


#This class make sure that the whole parsing system works.
def test_parsing(self):
	dir_testfiles = os.path.expanduser("~/ENVISIoN/envision/envision/parser/tests/VASP")
dir_Cu = os.path.expanduser(dir_testfiles + "/testdata/Cu")
h5file_path = os.path.join(dir_testfiles, "testh5file.hdf5")

# Create empty HDF5-file
testh5 = h5py.File(h5file_path, 'w')
group = list(testh5.keys())
# Test - to show HDF5-file is empty.
self.assertEqual(len(group), 0)
testh5.close()

#Is the function calls other parsing functions such as _parse_pcdat, _write_pcdat_onecol or _write_pcdat_multicol
paircorrelation(h5file_path, dir_Cu)

testh5 = h5py.File(h5file_path, 'r')
group = list(testh5.keys())

# Test - to show HDF5-file is written to.
self.assertNotEqual(len(group), 0)

distance = testh5["PairCorrelationFunc/Iterations"]
timeframes = list(testh5["PairCorrelationFunc/Elements/Cu"].keys())
dataset_obj1 = testh5["PairCorrelationFunc/Elements/Cu/t_0"]
dataset_obj2 = testh5["PairCorrelationFunc/Elements/Cu/t_1"]

# Tests - to control the writing to HDF5-file
self.assertIn("PairCorrelationFunc", testh5)
self.assertIn("PairCorrelationFunc/Iterations", testh5)
self.assertIn("PairCorrelationFunc/Elements", testh5)
self.assertIn("PairCorrelationFunc/Elements/Cu", testh5)
self.assertIn("PairCorrelationFunc/Elements/Cu/t_0", testh5)
self.assertIn("PairCorrelationFunc/Elements/Cu/t_1", testh5)

self.assertEqual(timeframes, ["t_0", "t_1"])
self.assertIsInstance(dataset_obj1[()], numpy.ndarray)
self.assertIsInstance(dataset_obj2[()], numpy.ndarray)
self.assertEqual(dataset_obj1.shape, (256,))
self.assertEqual(dataset_obj2.shape, (256,))
self.assertEqual(dataset_obj1.attrs["element"], "Cu")
self.assertEqual(dataset_obj2.attrs["element"], "Cu")

self.assertIsInstance(distance[()], numpy.ndarray)
self.assertEqual(distance.shape, (256,))
# Tests - to control HDF5-file has correct data
self.assertEqual(dataset_obj1[0], 0.000)
self.assertEqual(dataset_obj1[34], 0.206)
self.assertEqual(dataset_obj1[36], 1.469)

self.assertEqual(dataset_obj2[0], 0.000)
self.assertEqual(dataset_obj2[34], 0.411)
self.assertEqual(dataset_obj2[36], 1.286)

testh5.close()
os.remove(h5file_path)



class parse_average_PKF(unittest.TestCase):
	def test_write_pcdat_onecol(self):
		dir_testfiles = os.path.expanduser("~/ENVISIoN/envision/envision/parser/tests/VASP")
		dir_generalPKF = os.path.expanduser(dir_testfiles + "/testdata/LiC")
		file_general = os.path.join(dir_generalPKF, "PCDAT")
		h5file_path = os.path.join(dir_testfiles, "testh5file.hdf5")

		pcdat_data = _parse_pcdat("testh5file.hdf5", file_general, dir_generalPKF)
		key0 = list(pcdat_data)[0]
		list0 = pcdat_data[key0]

		# Tests - to control pcdat_data's format
		# expected format is {'general paircorr':[0.00, 0.00,... 3.660,..]}
		self.assertIsInstance(pcdat_data, dict)
		self.assertEqual(str(key0), "general paircorr")
		self.assertIsInstance(list0, list)

		# Tests - to control pcdat_data has correct data
		# expected 256 values from t_0
		self.assertEqual(len(list0), 256)
		self.assertEqual(list0[0], 0.000)
		self.assertEqual(list0[20], 3.660)
		self.assertEqual(list0[32], 0.861)


		# Create empty HDF5-file
		testh5 = h5py.File(h5file_path, 'w')
		group = list(testh5.keys())
		# Test - to show HDF5-file is empty.
		self.assertEqual(len(group), 0)
		testh5.close()

		# _write_pcdat_onecol is called, for systems of multiple elements with an
		# average pair-correlation function.
		_write_pcdat_onecol(h5file_path, pcdat_data, 16, 256)  # default APACO = 16, NPACO = 256

		testh5 = h5py.File(h5file_path, 'r')
		group = list(testh5.keys())
		timeframes = list(testh5["PairCorrelationFunc"].keys())
		dataset_obj = testh5["PairCorrelationFunc/t_0"]
		distance = testh5["PairCorrelationFunc/Iterations"]

		# Test - to show HDF5-file is written to.
		self.assertNotEqual(len(group), 0)

		# Tests - to control the writing to HDF5-file
		self.assertIn("PairCorrelationFunc", testh5)
		self.assertIn("PairCorrelationFunc/Iterations", testh5)
		self.assertIn("PairCorrelationFunc/t_0", testh5)
		self.assertEqual(timeframes, ["Iterations", "t_0"])
		self.assertIsInstance(dataset_obj[()], numpy.ndarray)
		self.assertEqual(dataset_obj.shape, (256,))

		self.assertIsInstance(distance[()], numpy.ndarray)
		self.assertEqual(distance.shape, (256,))

		#Tests - to control HDF5-file has correct data
		self.assertEqual(dataset_obj[0], 0.000)
		self.assertEqual(dataset_obj[32], 0.861)
		self.assertEqual(dataset_obj[20], 3.660)
		testh5.close()
		os.remove(h5file_path)

#This class make sure that the whole parsing system works.
def test_parsing(self):
	dir_testfiles = os.path.expanduser("~/ENVISIoN/envision/envision/parser/tests/VASP")
	dir_generalPKF = os.path.expanduser(dir_testfiles + "/testdata/LiC")
	h5file_path = os.path.join(dir_testfiles, "testh5file.hdf5")

	# Create empty HDF5-file
	testh5 = h5py.File(h5file_path, 'w')
	group = list(testh5.keys())
	# Test - to show HDF5-file is empty.
	self.assertEqual(len(group), 0)
	testh5.close()

	#Is the function calls other parsing functions such as _parse_pcdat, _write_pcdat_onecol or _write_pcdat_multicol
	paircorrelation(h5file_path, dir_generalPKF)

	testh5 = h5py.File(h5file_path, 'r')
	group = list(testh5.keys())
	timeframes = list(testh5["PairCorrelationFunc"].keys())
	dataset_obj = testh5["PairCorrelationFunc/t_0"]
	distance = testh5["PairCorrelationFunc/Iterations"]

	# Test - to show HDF5-file is written to.
	self.assertNotEqual(len(group), 0)

	# Tests - to control the writing to HDF5-file
	self.assertIn("PairCorrelationFunc", testh5)
	self.assertIn("PairCorrelationFunc/Iterations", testh5)
	self.assertIn("PairCorrelationFunc/Iterations", testh5)
	self.assertEqual(timeframes, ["Iterations", "t_0"])
	self.assertIsInstance(dataset_obj[()], numpy.ndarray)
	self.assertEqual(dataset_obj.shape, (256,))

	self.assertIsInstance(distance[()], numpy.ndarray)
	self.assertEqual(distance.shape, (256,))

	#Tests - for contents
	self.assertEqual(dataset_obj[28], 0.003)
	self.assertEqual(dataset_obj[19], 1.371)
	testh5.close()
	os.remove(h5file_path)<commit_msg>Fixed relative import. Now test_paircorrelation.py testfiles work for every choice of placement of ENVISIoN directory.<commit_after>#
#  ENVISIoN
#
#  Copyright (c) 2019 <NAME>
#  All rights reserved.
#
#  Redistribution and use in source and binary forms, with or without
#  modification, are permitted provided that the following conditions are met:
#
#  1. Redistributions of source code must retain the above copyright notice, this
#  list of conditions and the following disclaimer.
#  2. Redistributions in binary form must reproduce the above copyright notice,
#  this list of conditions and the following disclaimer in the documentation
#  and/or other materials provided with the distribution.
#
#  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
#  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
#  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
#  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
#  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
#  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
#  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
#  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
#  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
#  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#

#This file is created for the purpose of testing the parser system for
#visualisation of the pair-correlation function. The file uses the unittest python module.
#It can be called from the terminal with command: "python3 test_paircorrelation.py"


import os
import sys
import inspect
import unittest
import h5py
import numpy

path_to_current_folder = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
sys.path.insert(0, os.path.expanduser(path_to_current_folder+'/../..'))
sys.path.insert(0, os.path.expanduser(path_to_current_folder))
sys.path.insert(0, os.path.expanduser(path_to_current_folder+'/../../VASP'))

from PCF import _parse_pcdat, paircorrelation
from h5writer import _write_pcdat_onecol, _write_pcdat_multicol

# Test parsing correct line from file.
# Test that it is 256 values long.
# Test that it is t_0 and t_1
# Comment on new tests
# Write copyright on every file and push + merge it with master.

class except_n_error(unittest.TestCase):
	# Tests - for exception thrown for empty PCDAT-file
	def test_empty_file(self):
		vasp_dir = os.path.expanduser(path_to_current_folder + "/testdata/empty-PCDAT")
		h5file_path = os.path.join(path_to_current_folder, "testh5file.hdf5")
		empty_file = os.path.join(vasp_dir, "PCDAT_empty")

		with self.assertRaises(Exception) as ex:
			_parse_pcdat(h5file_path, empty_file, vasp_dir)
		self.assertEqual("PCDAT-file is empty.", str(ex.exception))


	# Tests - to skip parsing if it's already done
	def test_is_parsed(self):
		h5file_path = os.path.join(path_to_current_folder, "testh5file.hdf5")

		testh5 = h5py.File(h5file_path, 'w')
		testh5.create_dataset('PairCorrelationFunc/test', (10,))
		testh5.close()
		self.assertFalse(paircorrelation(h5file_path, ''))
		os.remove(h5file_path)


# Tests - for exception to be thrown when PCDAT file is not found
	def test_pcdat_file(self):
		vasp_dir = os.path.expanduser(path_to_current_folder + "/testdata/empty-PCDAT")
		h5file_path = os.path.join(path_to_current_folder, "testh5file.hdf5")

		with self.assertRaises(Exception) as ex:
			paircorrelation(h5file_path, vasp_dir)
		self.assertEqual("PCDAT-file not found.", str(ex.exception))

class parse_multitimes(unittest.TestCase):

	def test_write_pcdat_multicol(self):
		dir_Cu = os.path.expanduser(path_to_current_folder + "/testdata/Cu")
		file_Cu_t0nt1 = os.path.join(dir_Cu, "PCDAT")
		h5file_path = os.path.join(path_to_current_folder, "testh5file.hdf5")

		pcdat_data = _parse_pcdat(h5file_path, file_Cu_t0nt1, dir_Cu)
		key0 = list(pcdat_data)[0]
		list0 = pcdat_data[key0]

		# Tests - to control pcdat_data's format
		# expected format is {'Cu':[0.00, 0.00,... 0.206,..]}
		self.assertIsInstance(pcdat_data, dict)
		self.assertEqual(str(key0), "Cu")
		self.assertIsInstance(list0, list)

		# Tests - to control pcdat_data has correct data
		# expected 513 values from 256*2 (t_0, and t_1) plus 1 other value
		self.assertEqual(len(list0), 513)
		self.assertEqual(list0[0], 0.000)
		self.assertEqual(list0[34], 0.206)
		self.assertEqual(list0[36], 1.469)
		self.assertEqual(list0[257], 0.000)
		self.assertEqual(list0[291], 0.411)
		self.assertEqual(list0[293], 1.286)


		# Create empty HDF5-file
		testh5 = h5py.File(h5file_path, 'w')
		group = list(testh5.keys())
		# Test - to show HDF5-file is empty.
		self.assertEqual(len(group), 0)
		testh5.close()

		# _write_pcdat_multicol is called for systems of one element, or multiple elements with no
		# average pair-correlation function.
		_write_pcdat_multicol(h5file_path, pcdat_data, 16, 256) #default APACO = 16, NPACO = 256

		testh5 = h5py.File(h5file_path, 'r')
		group = list(testh5.keys())

		# Test - to show HDF5-file is written to.
		self.assertNotEqual(len(group), 0)

		distance = testh5["PairCorrelationFunc/Distance"]
		timeframes = list(testh5["PairCorrelationFunc/Elements/Cu"].keys())
		dataset_obj1 = testh5["PairCorrelationFunc/Elements/Cu/PCF for t_0"]
		dataset_obj2 = testh5["PairCorrelationFunc/Elements/Cu/PCF for t_1"]


		# Tests - to control the writing to HDF5-file
		self.assertIn("PairCorrelationFunc", testh5)
		self.assertIn("PairCorrelationFunc/Distance", testh5)
		self.assertIn("PairCorrelationFunc/Elements", testh5)
		self.assertIn("PairCorrelationFunc/Elements/Cu", testh5)
		self.assertIn("PairCorrelationFunc/Elements/Cu/PCF for t_0", testh5)
		self.assertIn("PairCorrelationFunc/Elements/Cu/PCF for t_1", testh5)

		self.assertEqual(timeframes, ["PCF for t_0", "PCF for t_1"])
		self.assertIsInstance(dataset_obj1[()], numpy.ndarray)
		self.assertIsInstance(dataset_obj2[()], numpy.ndarray)
		self.assertAlmostEqual(dataset_obj1.shape, (256,))
		self.assertAlmostEqual(dataset_obj2.shape, (256,))
		self.assertAlmostEqual(dataset_obj1.attrs["element"], "Cu")
		self.assertAlmostEqual(dataset_obj2.attrs["element"], "Cu")

		self.assertIsInstance(distance[()], numpy.ndarray)
		self.assertEqual(distance.shape, (256,))
		# Tests - to control HDF5-file has correct data
		self.assertAlmostEqual(dataset_obj1[0], 0.000)
		self.assertAlmostEqual(dataset_obj1[34], 0.206)
		self.assertAlmostEqual(dataset_obj1[36], 1.469)

		self.assertAlmostEqual(dataset_obj2[0], 0.000)
		self.assertAlmostEqual(dataset_obj2[34], 0.411)
		self.assertAlmostEqual(dataset_obj2[36], 1.286)

		testh5.close()
		os.remove(h5file_path)


	#This class make sure that the whole parsing system works.
	def test_parsing(self):
		dir_Cu = os.path.expanduser(path_to_current_folder + "/testdata/Cu")
		h5file_path = os.path.join(path_to_current_folder, "testh5file.hdf5")

		# Create empty HDF5-file
		testh5 = h5py.File(h5file_path, 'w')
		group = list(testh5.keys())
		# Test - to show HDF5-file is empty.
		self.assertEqual(len(group), 0)
		testh5.close()

		#Is the function calls other parsing functions such as _parse_pcdat, _write_pcdat_onecol or _write_pcdat_multicol
		paircorrelation(h5file_path, dir_Cu)

		testh5 = h5py.File(h5file_path, 'r')
		group = list(testh5.keys())

		# Test - to show HDF5-file is written to.
		self.assertNotEqual(len(group), 0)

		distance = testh5["PairCorrelationFunc/Distance"]
		timeframes = list(testh5["PairCorrelationFunc/Elements/Cu"].keys())
		dataset_obj1 = testh5["PairCorrelationFunc/Elements/Cu/PCF for t_0"]
		dataset_obj2 = testh5["PairCorrelationFunc/Elements/Cu/PCF for t_1"]

		# Tests - to control the writing to HDF5-file
		self.assertIn("PairCorrelationFunc", testh5)
		self.assertIn("PairCorrelationFunc/Distance", testh5)
		self.assertIn("PairCorrelationFunc/Elements", testh5)
		self.assertIn("PairCorrelationFunc/Elements/Cu", testh5)
		self.assertIn("PairCorrelationFunc/Elements/Cu/PCF for t_0", testh5)
		self.assertIn("PairCorrelationFunc/Elements/Cu/PCF for t_1", testh5)

		self.assertEqual(timeframes, ["PCF for t_0", "PCF for t_1"])
		self.assertIsInstance(dataset_obj1[()], numpy.ndarray)
		self.assertIsInstance(dataset_obj2[()], numpy.ndarray)
		self.assertAlmostEqual(dataset_obj1.shape, (256,))
		self.assertAlmostEqual(dataset_obj2.shape, (256,))
		self.assertAlmostEqual(dataset_obj1.attrs["element"], "Cu")
		self.assertAlmostEqual(dataset_obj2.attrs["element"], "Cu")

		self.assertIsInstance(distance[()], numpy.ndarray)
		self.assertEqual(distance.shape, (256,))
		# Tests - to control HDF5-file has correct data
		self.assertAlmostEqual(dataset_obj1[0], 0.000)
		self.assertAlmostEqual(dataset_obj1[34], 0.206)
		self.assertAlmostEqual(dataset_obj1[36], 1.469)

		self.assertAlmostEqual(dataset_obj2[0], 0.000)
		self.assertAlmostEqual(dataset_obj2[34], 0.411)
		self.assertAlmostEqual(dataset_obj2[36], 1.286)

		testh5.close()
		os.remove(h5file_path)



class parse_average_PKF(unittest.TestCase):
	def test_write_pcdat_onecol(self):
		dir_generalPKF = os.path.expanduser(path_to_current_folder + "/testdata/LiC")
		file_general = os.path.join(dir_generalPKF, "PCDAT")
		h5file_path = os.path.join(path_to_current_folder, "testh5file.hdf5")

		pcdat_data = _parse_pcdat("testh5file.hdf5", file_general, dir_generalPKF)
		key0 = list(pcdat_data)[0]
		list0 = pcdat_data[key0]

		# Tests - to control pcdat_data's format
		# expected format is {'general paircorr':[0.00, 0.00,... 3.660,..]}
		self.assertIsInstance(pcdat_data, dict)
		self.assertEqual(str(key0), "general paircorr")
		self.assertIsInstance(list0, list)

		# Tests - to control pcdat_data has correct data
		# expected 256 values from t_0
		self.assertEqual(len(list0), 256)
		self.assertEqual(list0[0], 0.000)
		self.assertEqual(list0[20], 3.660)
		self.assertEqual(list0[32], 0.861)


		# Create empty HDF5-file
		testh5 = h5py.File(h5file_path, 'w')
		group = list(testh5.keys())
		# Test - to show HDF5-file is empty.
		self.assertEqual(len(group), 0)
		testh5.close()

		# _write_pcdat_onecol is called, for systems of multiple elements with an
		# average pair-correlation function.
		_write_pcdat_onecol(h5file_path, pcdat_data, 16, 256)  # default APACO = 16, NPACO = 256

		testh5 = h5py.File(h5file_path, 'r')
		group = list(testh5.keys())
		timeframes = list(testh5["PairCorrelationFunc"].keys())
		dataset_obj = testh5["PairCorrelationFunc/PCF for t_0"]
		distance = testh5["PairCorrelationFunc/Distance"]

		# Test - to show HDF5-file is written to.
		self.assertNotEqual(len(group), 0)

		# Tests - to control the writing to HDF5-file
		self.assertIn("PairCorrelationFunc", testh5)
		self.assertIn("PairCorrelationFunc/Distance", testh5)
		self.assertIn("PairCorrelationFunc/PCF for t_0", testh5)
		self.assertEqual(timeframes, ["Distance", "PCF for t_0"])
		self.assertIsInstance(dataset_obj[()], numpy.ndarray)
		self.assertAlmostEqual(dataset_obj.shape, (256,))

		self.assertIsInstance(distance[()], numpy.ndarray)
		self.assertEqual(distance.shape, (256,))

		#Tests - to control HDF5-file has correct data
		self.assertAlmostEqual(dataset_obj[0], 0.000)
		self.assertAlmostEqual(dataset_obj[32], 0.861)
		testh5.close()
		os.remove(h5file_path)

#This class make sure that the whole parsing system works.
def test_parsing(self):
	dir_generalPKF = os.path.expanduser(path_to_current_folder + "/testdata/LiC")
	h5file_path = os.path.join(path_to_current_folder, "testh5file.hdf5")

	# Create empty HDF5-file
	testh5 = h5py.File(h5file_path, 'w')
	group = list(testh5.keys())
	# Test - to show HDF5-file is empty.
	self.assertEqual(len(group), 0)
	testh5.close()

	#Is the function calls other parsing functions such as _parse_pcdat, _write_pcdat_onecol or _write_pcdat_multicol
	paircorrelation(h5file_path, dir_generalPKF)

	testh5 = h5py.File(h5file_path, 'r')
	group = list(testh5.keys())
	timeframes = list(testh5["PairCorrelationFunc"].keys())
	dataset_obj = testh5["PairCorrelationFunc/PCF for "]
	distance = testh5["PairCorrelationFunc/Distance"]

	# Test - to show HDF5-file is written to.
	self.assertNotEqual(len(group), 0)

	# Tests - to control the writing to HDF5-file
	self.assertIn("PairCorrelationFunc", testh5)
	self.assertIn("PairCorrelationFunc/Distance", testh5)
	self.assertIn("PairCorrelationFunc/Distance", testh5)
	self.assertEqual(timeframes, ["Distance", "PCF for "])
	self.assertIsInstance(dataset_obj[()], numpy.ndarray)
	self.assertAlmostEqual(dataset_obj.shape, (256,))

	self.assertIsInstance(distance[()], numpy.ndarray)
	self.assertEqual(distance.shape, (256,))

	#Tests - for contents
	self.assertAlmostEqual(dataset_obj[28], 0.003)
	self.assertAlmostEqual(dataset_obj[19], 1.371)
	testh5.close()
	os.remove(h5file_path)
{'fraction_non_alphanumeric': 0.12097781943142769, 'fraction_numerical': 0.036590128084973444, 'mean_word_length': 5.514627321292292, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5042286', 'n_tokens_mistral': 10016, 'n_tokens_neox': 9062, 'n_words': 1977}