Skip to content

Commit

Permalink
refactor: update obsolute function name in test_csv.py and add prefix…
Browse files Browse the repository at this point in the history
… to message mock
  • Loading branch information
furkan-bilgin committed Oct 12, 2024
1 parent d8607b7 commit fb18c05
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/tests/test_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def setUp(self):
self.config = MagicMock()
self.store = DAQJobStoreCSV(self.config)

@patch("daq.store.csv.add_date_to_file_name", return_value="test.csv")
@patch("daq.store.csv.modify_file_path", return_value="test.csv")
@patch("builtins.open", new_callable=mock_open)
@patch("os.path.exists", return_value=False)
@patch("pathlib.Path.touch")
Expand All @@ -30,16 +30,17 @@ def test_handle_message_new_file(
)
message.keys = ["header1", "header2"]
message.data = [["row1_col1", "row1_col2"], ["row2_col1", "row2_col2"]]
message.prefix = None

self.store.handle_message(message)

mock_add_date.assert_called_once_with("test.csv", True)
mock_add_date.assert_called_once_with("test.csv", True, None)
mock_open.assert_called_once_with("test.csv", "a")
self.assertIn("test.csv", self.store._open_csv_files)
file = self.store._open_csv_files["test.csv"]
self.assertEqual(file.write_queue.qsize(), 3) # 1 header + 2 rows

@patch("daq.store.csv.add_date_to_file_name", return_value="test.csv")
@patch("daq.store.csv.modify_file_path", return_value="test.csv")
@patch("builtins.open", new_callable=mock_open)
@patch("os.path.exists", return_value=True)
def test_handle_message_existing_file(self, mock_exists, mock_open, mock_add_date):
Expand All @@ -49,10 +50,11 @@ def test_handle_message_existing_file(self, mock_exists, mock_open, mock_add_dat
)
message.keys = ["header1", "header2"]
message.data = [["row1_col1", "row1_col2"], ["row2_col1", "row2_col2"]]
message.prefix = None

self.store.handle_message(message)

mock_add_date.assert_called_once_with("test.csv", True)
mock_add_date.assert_called_once_with("test.csv", True, None)
mock_open.assert_called_once_with("test.csv", "a")
self.assertIn("test.csv", self.store._open_csv_files)
file = self.store._open_csv_files["test.csv"]
Expand Down

0 comments on commit fb18c05

Please sign in to comment.