Skip to content

Commit bc6dd2f

Browse files
committed
fix: update test cases in test_utils.py for improved file handling and readability
1 parent 91a9f59 commit bc6dd2f

1 file changed

Lines changed: 10 additions & 12 deletions

File tree

tests/unit/test_utils.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Tests for utility functions."""
22

33
import subprocess
4-
from unittest.mock import Mock, mock_open, patch
4+
from unittest.mock import Mock, patch
55

66
import pytest
77

@@ -12,26 +12,24 @@
1212
class TestSave:
1313
"""Test save() function."""
1414

15-
def test_save_bytes(self):
15+
def test_save_bytes(self, tmp_path):
1616
"""Test saving bytes to file."""
1717
audio = b"fake audio data"
18+
output_file = tmp_path / "output.mp3"
1819

19-
with patch("pathlib.Path.open", mock_open()) as m:
20-
save(audio, "output.mp3")
20+
save(audio, str(output_file))
2121

22-
m.assert_called_once_with("wb")
23-
m().write.assert_called_once_with(audio)
22+
assert output_file.read_bytes() == audio
2423

25-
def test_save_iterator(self):
24+
def test_save_iterator(self, tmp_path):
2625
"""Test saving iterator to file."""
2726
audio = iter([b"chunk1", b"chunk2", b"chunk3"])
27+
output_file = tmp_path / "output.mp3"
2828

29-
with patch("pathlib.Path.open", mock_open()) as m:
30-
save(audio, "output.mp3")
29+
save(audio, str(output_file))
3130

32-
m.assert_called_once_with("wb")
33-
# Should consolidate chunks
34-
m().write.assert_called_once_with(b"chunk1chunk2chunk3")
31+
# Should consolidate chunks
32+
assert output_file.read_bytes() == b"chunk1chunk2chunk3"
3533

3634

3735
class TestPlay:

0 commit comments

Comments
 (0)