Skip to content
Snippets Groups Projects

Update test_eventlog_handler.py

Closed Shufei Du requested to merge dushufei5-main-patch-54684 into main
1 unresolved thread
1 file
+ 94
0
Compare changes
  • Side-by-side
  • Inline
import unittest
from eventlog_handler import Event_handler
import pandas as pd
class Test_EventHandler(unittest.TestCase):
def setUp(self) -> None:
self.csv_file_path="test_data.csv"
self.xls_file_path="test_data.xlsx"
self.xes_file_path="test_data.xes"
self.parquet_file_path="test_data.parquet"
self.xlsx_file_path="test_data.xlsx"
self.doc_file_path="test_data.doc"
#all type file
#test all type file
def test_check_file_type(self):
handler1=Event_handler(self.csv_file_path)
result1=handler1.check_file_type()
handler2=Event_handler(self.xls_file_path)
result2=handler2.check_file_type()
handler3=Event_handler(self.xes_file_path)
result3=handler3.check_file_type()
handler4=Event_handler(self.parquet_file_path)
result4=handler4.check_file_type()
handler5=Event_handler(self.xlsx_file_path)
result5=handler5.check_file_type()
handler6=Event_handler(self.doc_file_path)
result6=handler6.check_file_type()
self.assertTrue(result1 and result2 and result3 and result4 and result5)
self.assertFalse(result6)
def test_read_file(self)->None:
handler1=Event_handler(self.csv_file_path)
handler1.read_file()
self.assertIsInstance(handler1.df, pd.DataFrame)
handler2=Event_handler(self.xls_file_path)
handler2.read_file()
self.assertIsInstance(handler2.df, pd.DataFrame)
handler3=Event_handler(self.xes_file_path)
handler3.read_file()
self.assertIsInstance(handler3.df, pd.DataFrame)
handler4=Event_handler(self.parquet_file_path)
handler4.read_file()
self.assertIsInstance(handler4.df, pd.DataFrame)
handler5=Event_handler(self.xlsx_file_path)
handler5.read_file()
self.assertIsInstance(handler5.df, pd.DataFrame)
def test_list_of_columns(self)->None:
handler=Event_handler(self.csv_file_path)
handler.check_file_type()
handler.read_file()
columns=handler.list_of_columns()
self.assertIsInstance(columns,list)
def test_select_columns(self)->None:
handler = Event_handler(self.csv_file_path)
handler.check_file_type()
handler.read_file()
selected_columns = handler.select_columns("caseid", "timestamp", "activity", "resource")
self.assertIsInstance(selected_columns,dict)
def test_timestamp_handler(self)->None:
handler = Event_handler(self.csv_file_path)
handler.check_file_type()
handler.read_file()
selected_columns = handler.select_columns("caseid", "timestamp", "activity", "resource")
handler.timestamp_handler()
expected_format=handler.df["timestamp"].dt.strftime('%Y-%m-%dT%H:%M:%S')
actual_format = pd.to_datetime(handler.df['timestamp'], format='%Y-%m-%dT%H:%M:%S')
self.assertTrue(all(expected_format == actual_format), "Date time format is not as expected.\
Expected: {} Actual: {}".format(expected_format, actual_format))
def test_clean_data(self)->None:
handler = Event_handler(self.csv_file_path)
handler.check_file_type()
handler.read_file()
handler.clean_data()
self.assertFalse(handler.df.isnull().any().any())
def test_return_dataframe(self)->None:
handler = Event_handler(self.csv_file_path)
handler.check_file_type()
handler.read_file()
df = handler.return_dataframe()
self.assertIsNotNone(df)
self.assertTrue(df.equals(handler.df))
def tearDown(self)->None:
pass
if __name__=="__main__":
unittest.main()
\ No newline at end of file
Loading