Skip to content

Commit 4e864b2

Browse files
committed
added more comments, fixed imports
1 parent c8bd6ce commit 4e864b2

8 files changed

Lines changed: 21 additions & 42 deletions

tests/test_cli.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
1-
import pytest
21
import sys
3-
from tests.test_fixtures import any_to_any_instance
2+
import subprocess
3+
import os
44

55
def test_cli_help_output(tmp_path):
6-
import subprocess
7-
import os
86
script_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'any_to_any.py'))
97
result = subprocess.run([sys.executable, script_path, "-h"], capture_output=True, text=True)
108
assert "usage" in result.stdout.lower() or "usage" in result.stderr.lower()
119

1210
def test_cli_invalid_format(tmp_path):
13-
import subprocess
1411
result = subprocess.run([sys.executable, "any_to_any.py", "-i", str(tmp_path), "-f", "xyz"], cwd=str(tmp_path.parent), capture_output=True, text=True)
1512
assert "unsupported format" in result.stdout.lower() or "unsupported format" in result.stderr.lower() or result.returncode != 0
1613

1714
def test_blank_start_no_files_in_cli_output(any_to_any_instance, caplog):
1815
with caplog.at_level("INFO"):
16+
# Jesus Christ, centralize this; maybe make a central factory for this
1917
any_to_any_instance.run([], None, None, None, None, False, False, False, False, False, False, "en_US")
2018
assert "No convertible media files" in caplog.text

tests/test_conversion_methods.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import pytest
22
import warnings
33
from any_to_any import Category
4-
from tests.test_fixtures import any_to_any_instance
54

65
def test_to_audio_invalid_format(any_to_any_instance, tmp_path):
76
invalid_file = tmp_path / "invalid_file.mp3"
@@ -17,6 +16,7 @@ def test_to_audio_invalid_format(any_to_any_instance, tmp_path):
1716

1817
def test_to_gif_handles_invalid_file(any_to_any_instance, tmp_path):
1918
fake_file = tmp_path / "fake.mp3"
19+
# This is funny, I like this pattern, need to suppress any rambling from ffmpeg though
2020
fake_file.write_bytes(b"\x00" * 128)
2121
with pytest.raises(Exception):
2222
any_to_any_instance.to_gif({'audio': [(str(tmp_path) + "/", 'fake', 'mp3')]}, 'gif')

tests/test_core.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
import pytest
2-
from any_to_any import AnyToAny
3-
from tests.test_fixtures import any_to_any_instance, test_input_folder
41
from modules.category import Category
52

63
def test_supported_formats(any_to_any_instance):
74
assert isinstance(any_to_any_instance.supported_formats, list)
85
assert len(any_to_any_instance.supported_formats) > 0
96

107
def test_audio_bitrate(any_to_any_instance):
8+
# Kind of nonsensical, I know, but it is a low-level structural test anyway
119
assert any_to_any_instance._audio_bitrate('mp3', 'high') == '320k'
1210
assert any_to_any_instance._audio_bitrate('flac', 'medium') == '320k'
1311
assert any_to_any_instance._audio_bitrate('ogg', 'low') == '128k'

tests/test_edge_cases.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import pytest
2-
from tests.test_fixtures import any_to_any_instance
2+
import random
3+
import string
34
from unittest.mock import patch
45

56
def test_empty_directory(any_to_any_instance, tmp_path):
@@ -10,6 +11,7 @@ def test_empty_directory(any_to_any_instance, tmp_path):
1011

1112
def test_permission_error_on_output(any_to_any_instance, tmp_path):
1213
file_path = tmp_path / "test.mp4"
14+
# Building a tiny fake file
1315
file_path.write_bytes(b"\x00" * 128)
1416
with patch("os.remove", side_effect=PermissionError):
1517
with pytest.raises(PermissionError):
@@ -20,10 +22,10 @@ def test_get_file_paths_invalid_directory(any_to_any_instance):
2022
any_to_any_instance._get_file_paths(input="nonexistent_directory")
2123

2224
def test_fuzz_random_file_names(any_to_any_instance, tmp_path):
23-
import random
24-
import string
2525
for _ in range(10):
2626
name = ''.join(random.choices(string.ascii_letters, k=8))
27+
# Specifically checking the 'malformed' case of 'jpg' instead of 'jpeg'
28+
# because people use it so often, this has to be handled/supported
2729
ext = random.choice(['mp4', 'mp3', 'jpg', 'wav', 'pdf'])
2830
file = tmp_path / f"{name}.{ext}"
2931
file.write_bytes(b"\x00" * 128)

tests/test_fixtures.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import sys
21
import os
3-
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
2+
import sys
43
import pytest
5-
import tempfile
6-
import shutil
4+
5+
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
76
from any_to_any import AnyToAny
87

98
@pytest.fixture
109
def temp_media_dir(tmp_path):
1110
media_dir = tmp_path / "media"
1211
media_dir.mkdir()
12+
# Fake File Creation
1313
(media_dir / "test.mp4").write_bytes(b"\x00" * 128)
1414
(media_dir / "test.mp3").write_bytes(b"\x00" * 128)
1515
(media_dir / "test.jpg").write_bytes(b"\x00" * 128)

tests/test_integration_and_routing.py

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
11
import pytest
2-
import sys
3-
import os
42
import argparse
53
from unittest import mock
64
from any_to_any import AnyToAny
7-
from modules.category import Category
8-
import types
95

106
@pytest.fixture
117
def instance():
128
return AnyToAny()
139

1410
def test_routing_supported_formats(instance):
15-
"""
16-
Ensure all supported formats are routed to the correct handler or codec.
17-
"""
11+
# Ensure all supported formats are routed to the correct handler or codec.
1812
for cat, formats in instance._supported_formats.items():
1913
for fmt, handler in formats.items():
2014
if callable(handler):
@@ -27,28 +21,22 @@ def test_routing_supported_formats(instance):
2721
assert isinstance(handler, (str, list))
2822

2923
def test_run_web_flag_starts_web():
30-
"""
31-
Test that the CLI parser recognizes the -w/--web flag.
32-
"""
24+
# Test that the CLI parser recognizes the -w/--web flag.
3325
parser = argparse.ArgumentParser()
3426
parser.add_argument('-w', '--web', action='store_true')
3527
args = parser.parse_args(['-w'])
3628
assert args.web
3729

3830

3931
def test_end_with_msg_logs_and_exits(instance, caplog):
40-
"""
41-
Test _end_with_msg logs error and raises SystemExit.
42-
"""
32+
# Test _end_with_msg logs error and raises SystemExit.
4333
with caplog.at_level('WARNING'):
4434
with pytest.raises(SystemExit):
4535
instance._end_with_msg(SystemExit, 'fail message')
4636
assert 'fail message' in caplog.text
4737

4838
def test_recursive_file_discovery(instance, tmp_path):
49-
"""
50-
_get_file_paths does not recurse; only top-level files are found.
51-
"""
39+
# _get_file_paths does not recurse; only top-level files are found.
5240
d1 = tmp_path / "a"
5341
d2 = d1 / "b"
5442
d2.mkdir(parents=True)
@@ -60,13 +48,11 @@ def test_recursive_file_discovery(instance, tmp_path):
6048
str(f.parent) in path[0] and path[1] == 'test' and path[2] == 'mp4'
6149
for paths in file_paths.values() for path in paths
6250
)
63-
assert not found # Documented limitation
51+
assert not found # Documented limitation, this is intentional
6452

6553

6654
def test_weird_filenames(instance, tmp_path):
67-
"""
68-
Test handling of files with unicode and special chars in names.
69-
"""
55+
# Test handling of files with unicode and special chars in names.
7056
fname = "weird_名字_#@!.mp3"
7157
f = tmp_path / fname
7258
f.write_bytes(b"\x00"*128)
@@ -75,9 +61,7 @@ def test_weird_filenames(instance, tmp_path):
7561
assert found
7662

7763
def test_post_process_permission_error(instance, tmp_path):
78-
"""
79-
Test _post_process logs and raises on permission error during delete.
80-
"""
64+
# Test _post_process logs and raises on permission error during delete.
8165
f = tmp_path / "test.mp4"
8266
f.write_bytes(b"\x00"*128)
8367
with mock.patch("os.remove", side_effect=PermissionError):

tests/test_logging_progress.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import pytest
2-
from tests.test_fixtures import any_to_any_instance
31

42
def test_logging_and_progress(any_to_any_instance, caplog):
53
with caplog.at_level("INFO"):

tests/test_merge_concat.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import pytest
2-
from tests.test_fixtures import any_to_any_instance, test_input_folder, test_output_folder
32
from modules.category import Category
43

54
def test_merging_method(any_to_any_instance, test_input_folder, test_output_folder):

0 commit comments

Comments
 (0)