Skip to content

Commit f23dd3f

Browse files
Saurabh PandeySaurabh Pandey
authored andcommitted
test added, but with some issues
1 parent be7a143 commit f23dd3f

File tree

1 file changed

+65
-26
lines changed

1 file changed

+65
-26
lines changed

PostProcessing/test_functions.py

Lines changed: 65 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@
55

66
from typing import List
77

8-
from dataframes import repair_dropped_frames
8+
from dataframes import repair_dropped_frames, compute_time_range, trim_into_interval
99

1010
import pandas as pd
1111

12+
import pandas.testing as pd_testing
13+
14+
import numpy as np
15+
1216
RECSYNCH_SESSION_DIR_VAR = "RECSYNCH_SESSION_DIR"
1317

1418
print(f"Getting data dir from {RECSYNCH_SESSION_DIR_VAR} environment variable...")
@@ -21,42 +25,77 @@
2125
# raise Exception(f"Environment variable {RECSYNCH_SESSION_DIR_VAR} not defined")
2226

2327

24-
def client_IDs() -> List[str]:
28+
# def client_IDs() -> List[str]:
29+
30+
# out = []
31+
32+
# for p in Path(RECSYNCH_SESSION_DIR).iterdir():
33+
# print("-->", p.stem)
34+
# out.append(p)
35+
36+
# return out
37+
38+
39+
# def CSVs() -> List[str]:
2540

26-
out = []
41+
# out = []
2742

28-
for p in Path(RECSYNCH_SESSION_DIR).iterdir():
29-
print("-->", p.stem)
30-
out.append(p)
43+
# clients = client_IDs()
44+
# for c in clients:
45+
# client_dir = Path(RECSYNCH_SESSION_DIR) / c
46+
# for csv_file in client_dir.glob("*.csv"):
47+
# print("==>", csv_file)
48+
# rel_filepath = str(csv_file.relative_to(RECSYNCH_SESSION_DIR))
49+
# print("++>", rel_filepath)
50+
# out.append(rel_filepath)
3151

32-
return out
52+
# return out
3353

3454

35-
def CSVs() -> List[str]:
55+
# @pytest.mark.parametrize("csv_file", CSVs())
56+
# def test_df_reparation(csv_file):
3657

37-
out = []
58+
# # Load the test dataframes
59+
# csv_path = Path(RECSYNCH_SESSION_DIR) / csv_file
60+
# df = pd.read_csv(csv_path)
3861

39-
clients = client_IDs()
40-
for c in clients:
41-
client_dir = Path(RECSYNCH_SESSION_DIR) / c
42-
for csv_file in client_dir.glob("*.csv"):
43-
print("==>", csv_file)
44-
rel_filepath = str(csv_file.relative_to(RECSYNCH_SESSION_DIR))
45-
print("++>", rel_filepath)
46-
out.append(rel_filepath)
62+
# assert len(df) >= 2
4763

48-
return out
64+
# repaired_df = repair_dropped_frames(df)
4965

66+
# assert len(repaired_df) >= len(df)
5067

51-
@pytest.mark.parametrize("csv_file", CSVs())
52-
def test_df_reparation(csv_file):
5368

54-
# Load the test dataframes
55-
csv_path = Path(RECSYNCH_SESSION_DIR) / csv_file
56-
df = pd.read_csv(csv_path)
69+
def test_df_trim():
70+
# Create three sample dataframes with single column and no headers
71+
df1 = pd.DataFrame([9, 10, 11, 16])
72+
df2 = pd.DataFrame([7, 8, 12, 13])
73+
df3 = pd.DataFrame([12, 15, 16, 19])
5774

58-
assert len(df) >= 2
75+
# Add the dataframes to a list
76+
df_list = [df1, df2, df3]
5977

60-
repaired_df = repair_dropped_frames(df)
78+
# Compute time range and trim the dataframe
79+
min_val, max_val = compute_time_range(df_list)
80+
trimmed_df_list = trim_into_interval(df_list, min_val, max_val, 3)
6181

62-
assert len(repaired_df) >= len(df)
82+
# Create expected list of dataframes to compare with trimmed_df_list
83+
compare_list = [
84+
pd.DataFrame([9, 10, 11, 16]),
85+
pd.DataFrame([12, 13]),
86+
pd.DataFrame([12, 15, 16])
87+
]
88+
89+
# print(trimmed_df_list.to_string(index=False))
90+
# print(compare_list.to_string(index=False))
91+
# try:
92+
# for df1, df2 in zip(trimmed_df_list, compare_list):
93+
# df1_reset = df1.reset_index(drop=True)
94+
# df2_reset = df2.reset_index(drop=True)
95+
# pd_testing.assert_frame_equal(df1_reset, df2_reset)
96+
# print("All dataframes match")
97+
# except AssertionError as e:
98+
# print("Dataframes do not match:")
99+
# print(e)
100+
# Assert if all dataframes in df_list match the corresponding dataframes in compare_list
101+
assert trimmed_df_list == compare_list

0 commit comments

Comments
 (0)