Skip to content

Commit

Permalink
feat: add out_dir to DAQJobStoreCSV and update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
furkan-bilgin committed Nov 6, 2024
1 parent d4bad71 commit 759234d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
4 changes: 3 additions & 1 deletion src/daq/jobs/store/csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class DAQJobStoreConfigCSV(DAQJobStoreConfig):

@dataclass
class DAQJobStoreCSVConfig(DAQJobConfig):
pass
out_dir: str = "out/"


@dataclass
Expand Down Expand Up @@ -53,6 +53,8 @@ def handle_message(self, message: DAQJobMessageStore) -> bool:
file_path = modify_file_path(
store_config.file_path, store_config.add_date, message.prefix
)
file_path = os.path.join(self.config.out_dir, file_path)

file, new_file = self._open_csv_file(file_path, store_config.overwrite)
if file.overwrite:
file.write_queue.clear()
Expand Down
14 changes: 7 additions & 7 deletions src/tests/test_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

class TestDAQJobStoreCSV(unittest.TestCase):
def setUp(self):
self.config = MagicMock()
self.config = MagicMock(out_dir="out/")
self.store = DAQJobStoreCSV(self.config)

@patch("daq.jobs.store.csv.modify_file_path", return_value="test.csv")
Expand All @@ -35,9 +35,9 @@ def test_handle_message_new_file(
self.store.handle_message(message)

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

@patch("daq.jobs.store.csv.modify_file_path", return_value="test.csv")
Expand All @@ -55,9 +55,9 @@ def test_handle_message_existing_file(self, mock_exists, mock_open, mock_add_dat
self.store.handle_message(message)

mock_add_date.assert_called_once_with("test.csv", True, None)
mock_open.assert_called_once_with("test.csv", "a", newline="")
self.assertIn("test.csv", self.store._open_csv_files)
file = self.store._open_csv_files["test.csv"]
mock_open.assert_called_once_with("out/test.csv", "a", newline="")
self.assertIn("out/test.csv", self.store._open_csv_files)
file = self.store._open_csv_files["out/test.csv"]
self.assertEqual(len(file.write_queue), 2) # 2 rows only, no header

def test_flush(self):
Expand Down

0 comments on commit 759234d

Please sign in to comment.