import sys, os
sys.path.append("C:/Users/Delgado/Documents/Research/rheology-data-toolkit/rheodata/extractors")

import h5py
import pandas as pd
from antonpaar import AntonPaarExtractor as APE
from ARES_G2 import ARES_G2Extractor 
# %%
sys.path.append("C:/Users/Delgado/Documents/Research/rheology-data-toolkit/rheodata")
from data_converter import rheo_data_transformer

import unittest

extractor = APE()
#converter = data_converter()

class TestAntonPaar(unittest.TestCase):

    def setUp(self):
        self.multi_file_test = "C:/Users/Delgado/Documents/Research/rheology-data-toolkit/tests/test_data/Anton_Paar/excel_test_data/two_tests_Steady State Viscosity Curve-LO50C_excel.xlsx"

        self.modified_dict, self.raw_data_dict, self.cols, self.units = extractor.import_rheo_data(self.multi_file_test)

        # Inilize the class to convert
        self.converter = rheo_data_transformer(self.modified_dict, self.raw_data_dict, self.cols, self.units)
        self.converter.load_to_hdf("test")

    def test_modified_output_isdictionary(self):

        self.assertIsInstance(self.modified_dict, dict)

    def test_modified_output_dictionary_contains_pandas(self):
        """ Test if the output is a dictonary of pandas dataframes'"""

        for value in self.modified_dict.values():
            self.assertIsInstance(value, pd.DataFrame)

    def test_raw_output_isdictionary(self):
        self.assertIsInstance(self.raw_data_dict, dict)

    def test_raw_output_dictionary_contains_pandas(self):
        """ Test if the output is a dictonary of pandas dataframes'"""
        for value in self.raw_data_dict.values():
            self.assertIsInstance(value, pd.DataFrame)

    def test_project_name_added_raw_data(self):
        """ Test if the output is a dictonary of pandas dataframes'"""
        for df in self.raw_data_dict.values():
            self.assertEqual(df.iloc[0,0], "Project:")
    
    def test_hdf5_created(self):
        name, ext = os.path.splitext("test.hdf5")
        self.assertEqual(ext, ".hdf5")
    
    def test_project_subfolders_added(self):
        f = h5py.File('test.hdf5', "r")
        project_keys = list(f['Project'].keys())
        f.close()
        self.assertListEqual(project_keys, ['Steady State Viscosity Curve-75C','Steady State Viscosity Curve-LO80C', ])
    
    def test_analyze_cols(self):
        temp_df = extractor.make_analyze_dataframes(self.multi_file_test)

        for test_key in temp_df.keys():
            test_cols = list(temp_df[test_key].columns)
            parsed_cols = list(self.cols[test_key])

            self.assertListEqual(test_cols, parsed_cols)

    # TODO Write test for saving a file
    
if __name__ == '__main__':
    unittest.main()


[((2, 0, 2, 96), 'sys.path.append', 'sys.path.append', ({(2, 16, 2, 95): '"""C:/Users/Delgado/Documents/Research/rheology-data-toolkit/rheodata/extractors"""'}, {}), "(\n    'C:/Users/Delgado/Documents/Research/rheology-data-toolkit/rheodata/extractors'\n    )", False, 'import sys, os\n'), ((9, 0, 9, 85), 'sys.path.append', 'sys.path.append', ({(9, 16, 9, 84): '"""C:/Users/Delgado/Documents/Research/rheology-data-toolkit/rheodata"""'}, {}), "(\n    'C:/Users/Delgado/Documents/Research/rheology-data-toolkit/rheodata')", False, 'import sys, os\n'), ((14, 12, 14, 17), 'antonpaar.AntonPaarExtractor', 'APE', ({}, {}), '()', True, 'from antonpaar import AntonPaarExtractor as APE\n'), ((73, 4, 73, 19), 'unittest.main', 'unittest.main', ({}, {}), '()', False, 'import unittest\n'), ((25, 25, 25, 109), 'data_converter.rheo_data_transformer', 'rheo_data_transformer', ({(25, 47, 25, 65): 'self.modified_dict', (25, 67, 25, 85): 'self.raw_data_dict', (25, 87, 25, 96): 'self.cols', (25, 98, 25, 108): 'self.units'}, {}), '(self.modified_dict, self.raw_data_dict, self.cols,\n    self.units)', False, 'from data_converter import rheo_data_transformer\n'), ((52, 20, 52, 49), 'os.path.splitext', 'os.path.splitext', ({(52, 37, 52, 48): '"""test.hdf5"""'}, {}), "('test.hdf5')", False, 'import sys, os\n'), ((56, 12, 56, 39), 'h5py.File', 'h5py.File', ({(56, 22, 56, 33): '"""test.hdf5"""', (56, 35, 56, 38): '"""r"""'}, {}), "('test.hdf5', 'r')", False, 'import h5py\n')]