Skip to content

Commit

Permalink
codecov
Browse files Browse the repository at this point in the history
  • Loading branch information
jo-pol committed Nov 30, 2023
1 parent 9ce7983 commit 5c2d4c9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/datastation/common/batch_processing.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import os
import sys
import time

from datastation.common.csv import CsvReport
Expand Down Expand Up @@ -58,7 +59,7 @@ def process_pids(self, pids_or_objects, callback):
if self.wait > 0 and i > 1:
logging.debug(f"Waiting {self.wait} seconds before processing next pid")
time.sleep(self.wait)
if type(obj) is dict:
if type(obj) is dict and 'PID' in obj.keys():
logging.info(f"Processing {i} of {num_pids}: {obj['PID']}")
elif type(obj) is str:
logging.info(f"Processing {i} of {num_pids}: {obj}")
Expand Down
20 changes: 20 additions & 0 deletions src/tests/test_batch_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,26 @@ def test_process_pids(self, capsys):
captured = capsys.readouterr()
assert captured.out == "1\n2\n3\n"

def test_process_objects_with_pids(self, capsys):
batch_processor = BatchProcessor()
objects = [{"PID": "1", "param": "value1"},
{"PID": "2", "param": "value2"},
{"PID": "1", "param": "value3"}]
batch_processor.process_pids(objects, lambda obj: print(obj))
captured = capsys.readouterr()
assert captured.out == ("{'PID': '1', 'param': 'value1'}\n"
"{'PID': '2', 'param': 'value2'}\n"
"{'PID': '1', 'param': 'value3'}\n")

def test_process_objects_without_pids(self, capsys):
batch_processor = BatchProcessor()
objects = [{"no-pid": "1", "param": "value1"},
{"no-pid": "2", "param": "value2"},
{"no-pid": "1", "param": "value3"}]
batch_processor.process_pids(objects, lambda obj: print(obj['param']))
captured = capsys.readouterr()
assert captured.out == ("value1\nvalue2\nvalue3\n")

def test_process_pids_with_wait_on_iterator(self, capsys):
batch_processor = BatchProcessor(wait=0.1)

Expand Down

0 comments on commit 5c2d4c9

Please sign in to comment.