Skip to content

Commit

Permalink
Fix testcases
Browse files Browse the repository at this point in the history
  • Loading branch information
Anirudh58 committed Nov 11, 2022
1 parent e167a12 commit d5efb8d
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 12 deletions.
12 changes: 2 additions & 10 deletions eva/executor/load_csv_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,6 @@ def exec(self):
num_loaded_frames += len(batch)

# yield result
df_yield_result = Batch(
pd.DataFrame(
{
"CSV": csv_file_path,
"Number of loaded frames": num_loaded_frames,
},
index=[0],
)
yield Batch(
pd.DataFrame([f"CSV successfully loaded at location: {csv_file_path}"])
)

yield df_yield_result
62 changes: 61 additions & 1 deletion test/executor/test_load_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,42 @@ def test_should_fail_to_find_file(self, write_mock, create_mock):
with self.assertRaises(RuntimeError):
next(load_executor.exec())

@patch("eva.executor.load_video_executor.StorageEngine.write")
def test_should_fail_to_find_csv_file(self, write_mock, create_mock):
file_path = "csv"
table_metainfo = "info"
batch_mem_size = 3000
file_options = {}
file_options["file_format"] = FileFormatType.CSV
column_list = None
plan = type(
"LoadDataPlan",
(),
{
"table_metainfo": table_metainfo,
"file_path": file_path,
"batch_mem_size": batch_mem_size,
"column_list": column_list,
"file_options": file_options,
},
)

load_executor = LoadDataExecutor(plan)
with patch.object(Path, "exists") as mock_exists:
mock_exists.side_effect = [False, False]
with self.assertRaises(RuntimeError):
next(load_executor.exec())

@patch("eva.storage.storage_engine.StorageEngine.write")
def test_should_call_csv_reader_and_storage_engine(self, write_mock):
batch_frames = [list(range(5))] * 2

# creates a dummy.csv
create_sample_csv()

self.upload_path = Path(
ConfigurationManager().get_value("storage", "upload_dir")
)
file_path = "dummy.csv"
table_metainfo = "info"
batch_mem_size = 3000
Expand Down Expand Up @@ -164,8 +193,39 @@ def test_should_call_csv_reader_and_storage_engine(self, write_mock):
# Note: We call exec() from the child classes.
self.assertEqual(
batch,
Batch(pd.DataFrame([{"CSV": file_path, "Number of loaded frames": 20}])),
Batch(
pd.DataFrame(
[
f"CSV successfully loaded at location: {self.upload_path / file_path}"
]
)
),
)

# remove the dummy.csv
file_remove("dummy.csv")

def test_should_fail_to_find_csv_file(self):
file_path = "dummy"
table_metainfo = "info"
batch_mem_size = 3000
file_options = {}
file_options["file_format"] = FileFormatType.CSV
column_list = None
plan = type(
"LoadDataPlan",
(),
{
"table_metainfo": table_metainfo,
"file_path": file_path,
"batch_mem_size": batch_mem_size,
"column_list": column_list,
"file_options": file_options,
},
)

load_executor = LoadDataExecutor(plan)
with patch.object(Path, "exists") as mock_exists:
mock_exists.side_effect = [False, False]
with self.assertRaises(RuntimeError):
next(load_executor.exec())
11 changes: 10 additions & 1 deletion test/executor/test_upload_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ def test_should_call_csv_reader_and_storage_engine(self, write_mock):
# creates a dummy.csv
csv_blob = create_sample_csv_as_blob()

self.upload_path = Path(
ConfigurationManager().get_value("storage", "upload_dir")
)
file_path = "dummy.csv"
table_metainfo = "info"
batch_mem_size = 3000
Expand Down Expand Up @@ -173,7 +176,13 @@ def test_should_call_csv_reader_and_storage_engine(self, write_mock):
# Note: We call exec() from the child classes.
self.assertEqual(
batch,
Batch(pd.DataFrame([{"CSV": file_path, "Number of loaded frames": 20}])),
Batch(
pd.DataFrame(
[
f"CSV successfully loaded at location: {self.upload_path / file_path}"
]
)
),
)

# remove the dummy.csv
Expand Down

0 comments on commit d5efb8d

Please sign in to comment.