|
1 | 1 | """Tests for utility functions.""" |
2 | 2 |
|
3 | 3 | import subprocess |
4 | | -from unittest.mock import Mock, mock_open, patch |
| 4 | +from unittest.mock import Mock, patch |
5 | 5 |
|
6 | 6 | import pytest |
7 | 7 |
|
|
12 | 12 | class TestSave: |
13 | 13 | """Test save() function.""" |
14 | 14 |
|
15 | | - def test_save_bytes(self): |
| 15 | + def test_save_bytes(self, tmp_path): |
16 | 16 | """Test saving bytes to file.""" |
17 | 17 | audio = b"fake audio data" |
| 18 | + output_file = tmp_path / "output.mp3" |
18 | 19 |
|
19 | | - with patch("pathlib.Path.open", mock_open()) as m: |
20 | | - save(audio, "output.mp3") |
| 20 | + save(audio, str(output_file)) |
21 | 21 |
|
22 | | - m.assert_called_once_with("wb") |
23 | | - m().write.assert_called_once_with(audio) |
| 22 | + assert output_file.read_bytes() == audio |
24 | 23 |
|
25 | | - def test_save_iterator(self): |
| 24 | + def test_save_iterator(self, tmp_path): |
26 | 25 | """Test saving iterator to file.""" |
27 | 26 | audio = iter([b"chunk1", b"chunk2", b"chunk3"]) |
| 27 | + output_file = tmp_path / "output.mp3" |
28 | 28 |
|
29 | | - with patch("pathlib.Path.open", mock_open()) as m: |
30 | | - save(audio, "output.mp3") |
| 29 | + save(audio, str(output_file)) |
31 | 30 |
|
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" |
35 | 33 |
|
36 | 34 |
|
37 | 35 | class TestPlay: |
|
0 commit comments