Skip to content

Commit

Permalink
Refactor object tracking func setup and fix unit tests for tracker
Browse files Browse the repository at this point in the history
  • Loading branch information
yihong1120 committed Jul 16, 2024
1 parent d77173c commit 7a44a8f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/live_stream_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def run_detection(self):
for ids, datas, frame, timestamp in self.generate_detections():
print(
'Timestamp:', datetime.datetime.fromtimestamp(
timestamp,
timestamp, tz=datetime.timezone.utc
).strftime('%Y-%m-%d %H:%M:%S'),
)
print('IDs:', ids)
Expand Down
5 changes: 3 additions & 2 deletions tests/live_stream_tracker_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def test_generate_detections(
mock_results[0].boxes = mock_boxes
mock_yolo_instance.track.return_value = mock_results

mock_now = datetime.datetime(2023, 1, 1, 0, 0, 0)
mock_now = datetime.datetime(2023, 1, 1, 0, 0, 0, tzinfo=datetime.timezone.utc)
mock_datetime.datetime.now.side_effect = [mock_now, mock_now]

frame_generator = self.detector.generate_detections()
Expand Down Expand Up @@ -98,9 +98,10 @@ def test_run_detection(self, mock_generate_detections):

with patch('builtins.print') as mock_print:
self.detector.run_detection()
expected_datetime = datetime.datetime.fromtimestamp(1234567890.0, tz=datetime.timezone.utc).strftime('%Y-%m-%d %H:%M:%S')
self.assertTrue(
any(
'Timestamp:' in str(call) and '2009-02-14' in str(call)
'Timestamp:' in str(call) and expected_datetime in str(call)
for call in mock_print.call_args_list
),
)
Expand Down

0 comments on commit 7a44a8f

Please sign in to comment.