pymkv2 2.3.0__tar.gz → 2.3.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pymkv2-2.3.0 → pymkv2-2.3.2}/PKG-INFO +2 -1
- {pymkv2-2.3.0 → pymkv2-2.3.2}/pymkv/MKVFile.py +38 -11
- {pymkv2-2.3.0 → pymkv2-2.3.2}/pyproject.toml +2 -1
- pymkv2-2.3.2/tests/test_mux_progress.py +172 -0
- pymkv2-2.3.2/tests/test_ui_language.py +115 -0
- pymkv2-2.3.0/tests/test_mux_progress.py +0 -81
- {pymkv2-2.3.0 → pymkv2-2.3.2}/LICENSE.txt +0 -0
- {pymkv2-2.3.0 → pymkv2-2.3.2}/README.md +0 -0
- {pymkv2-2.3.0 → pymkv2-2.3.2}/pymkv/ISO639_2.py +0 -0
- {pymkv2-2.3.0 → pymkv2-2.3.2}/pymkv/Languages.py +0 -0
- {pymkv2-2.3.0 → pymkv2-2.3.2}/pymkv/MKVAttachment.py +0 -0
- {pymkv2-2.3.0 → pymkv2-2.3.2}/pymkv/MKVTrack.py +0 -0
- {pymkv2-2.3.0 → pymkv2-2.3.2}/pymkv/Timestamp.py +0 -0
- {pymkv2-2.3.0 → pymkv2-2.3.2}/pymkv/TypeTrack.py +0 -0
- {pymkv2-2.3.0 → pymkv2-2.3.2}/pymkv/Verifications.py +0 -0
- {pymkv2-2.3.0 → pymkv2-2.3.2}/pymkv/__init__.py +0 -0
- {pymkv2-2.3.0 → pymkv2-2.3.2}/pymkv/chapters.py +0 -0
- {pymkv2-2.3.0 → pymkv2-2.3.2}/pymkv/command_generators/__init__.py +0 -0
- {pymkv2-2.3.0 → pymkv2-2.3.2}/pymkv/command_generators/attachment_options.py +0 -0
- {pymkv2-2.3.0 → pymkv2-2.3.2}/pymkv/command_generators/base.py +0 -0
- {pymkv2-2.3.0 → pymkv2-2.3.2}/pymkv/command_generators/chapter_options.py +0 -0
- {pymkv2-2.3.0 → pymkv2-2.3.2}/pymkv/command_generators/global_options.py +0 -0
- {pymkv2-2.3.0 → pymkv2-2.3.2}/pymkv/command_generators/linking_options.py +0 -0
- {pymkv2-2.3.0 → pymkv2-2.3.2}/pymkv/command_generators/split_options.py +0 -0
- {pymkv2-2.3.0 → pymkv2-2.3.2}/pymkv/command_generators/track_options.py +0 -0
- {pymkv2-2.3.0 → pymkv2-2.3.2}/pymkv/command_generators/track_order_options.py +0 -0
- {pymkv2-2.3.0 → pymkv2-2.3.2}/pymkv/models.py +0 -0
- {pymkv2-2.3.0 → pymkv2-2.3.2}/pymkv/py.typed +0 -0
- {pymkv2-2.3.0 → pymkv2-2.3.2}/pymkv/utils.py +0 -0
- {pymkv2-2.3.0 → pymkv2-2.3.2}/tests/__init__.py +0 -0
- {pymkv2-2.3.0 → pymkv2-2.3.2}/tests/command_generators/__init__.py +0 -0
- {pymkv2-2.3.0 → pymkv2-2.3.2}/tests/command_generators/test_attachment.py +0 -0
- {pymkv2-2.3.0 → pymkv2-2.3.2}/tests/command_generators/test_base.py +0 -0
- {pymkv2-2.3.0 → pymkv2-2.3.2}/tests/command_generators/test_chapter.py +0 -0
- {pymkv2-2.3.0 → pymkv2-2.3.2}/tests/command_generators/test_global.py +0 -0
- {pymkv2-2.3.0 → pymkv2-2.3.2}/tests/command_generators/test_linking.py +0 -0
- {pymkv2-2.3.0 → pymkv2-2.3.2}/tests/command_generators/test_order.py +0 -0
- {pymkv2-2.3.0 → pymkv2-2.3.2}/tests/command_generators/test_split.py +0 -0
- {pymkv2-2.3.0 → pymkv2-2.3.2}/tests/command_generators/test_track.py +0 -0
- {pymkv2-2.3.0 → pymkv2-2.3.2}/tests/conftest.py +0 -0
- {pymkv2-2.3.0 → pymkv2-2.3.2}/tests/test_actions_track.py +0 -0
- {pymkv2-2.3.0 → pymkv2-2.3.2}/tests/test_add_file.py +0 -0
- {pymkv2-2.3.0 → pymkv2-2.3.2}/tests/test_chapter_commands.py +0 -0
- {pymkv2-2.3.0 → pymkv2-2.3.2}/tests/test_chapters_obj.py +0 -0
- {pymkv2-2.3.0 → pymkv2-2.3.2}/tests/test_create_mkv.py +0 -0
- {pymkv2-2.3.0 → pymkv2-2.3.2}/tests/test_decorator.py +0 -0
- {pymkv2-2.3.0 → pymkv2-2.3.2}/tests/test_extract_file.py +0 -0
- {pymkv2-2.3.0 → pymkv2-2.3.2}/tests/test_init_version.py +0 -0
- {pymkv2-2.3.0 → pymkv2-2.3.2}/tests/test_integration_mux.py +0 -0
- {pymkv2-2.3.0 → pymkv2-2.3.2}/tests/test_iso639_2.py +0 -0
- {pymkv2-2.3.0 → pymkv2-2.3.2}/tests/test_language_loss_fix.py +0 -0
- {pymkv2-2.3.0 → pymkv2-2.3.2}/tests/test_language_real_file.py +0 -0
- {pymkv2-2.3.0 → pymkv2-2.3.2}/tests/test_languages.py +0 -0
- {pymkv2-2.3.0 → pymkv2-2.3.2}/tests/test_languages_integration.py +0 -0
- {pymkv2-2.3.0 → pymkv2-2.3.2}/tests/test_mkv_attachment.py +0 -0
- {pymkv2-2.3.0 → pymkv2-2.3.2}/tests/test_mkv_chapters_tags.py +0 -0
- {pymkv2-2.3.0 → pymkv2-2.3.2}/tests/test_mkv_file_attachments.py +0 -0
- {pymkv2-2.3.0 → pymkv2-2.3.2}/tests/test_mkv_split_methods.py +0 -0
- {pymkv2-2.3.0 → pymkv2-2.3.2}/tests/test_mkvtrack_language.py +0 -0
- {pymkv2-2.3.0 → pymkv2-2.3.2}/tests/test_models.py +0 -0
- {pymkv2-2.3.0 → pymkv2-2.3.2}/tests/test_open_files.py +0 -0
- {pymkv2-2.3.0 → pymkv2-2.3.2}/tests/test_replace_swap_track.py +0 -0
- {pymkv2-2.3.0 → pymkv2-2.3.2}/tests/test_timestamp.py +0 -0
- {pymkv2-2.3.0 → pymkv2-2.3.2}/tests/test_timestamps_external.py +0 -0
- {pymkv2-2.3.0 → pymkv2-2.3.2}/tests/test_typetrack.py +0 -0
- {pymkv2-2.3.0 → pymkv2-2.3.2}/tests/test_utils_prepare_mkvtoolnix_path.py +0 -0
- {pymkv2-2.3.0 → pymkv2-2.3.2}/tests/test_verifications_direct.py +0 -0
- {pymkv2-2.3.0 → pymkv2-2.3.2}/tests/test_verify.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: pymkv2
|
|
3
|
-
Version: 2.3.
|
|
3
|
+
Version: 2.3.2
|
|
4
4
|
Summary: A Python wrapper for mkvmerge. It provides support for muxing, splitting, linking, chapters, tags, and attachments through the use of mkvmerge.
|
|
5
5
|
Keywords: wrapper,mkvmerge,mkvtoolnix,mkvextract,matroska,mkv,video,audio,subtitles,multimedia,mux,muxing,demux,chapters,attachments,tags,iso-639,bcp-47,language-codes
|
|
6
6
|
Author-Email: GitBib <job@bnff.website>, Sheldon Woodward <me@sheldonw.com>
|
|
@@ -22,6 +22,7 @@ Requires-Python: <4.0,>=3.10
|
|
|
22
22
|
Requires-Dist: bitmath<3.0.0,>=2.0.0
|
|
23
23
|
Requires-Dist: python-iso639<2027.0.0,>=2026.4.20
|
|
24
24
|
Requires-Dist: msgspec>=0.21.0
|
|
25
|
+
Requires-Dist: typing-extensions>=4.15.0; python_full_version < "3.11"
|
|
25
26
|
Description-Content-Type: text/markdown
|
|
26
27
|
|
|
27
28
|
# pymkv2
|
|
@@ -60,14 +60,19 @@ import logging
|
|
|
60
60
|
import os
|
|
61
61
|
import re
|
|
62
62
|
import subprocess as sp
|
|
63
|
+
import sys
|
|
63
64
|
import tempfile
|
|
64
65
|
from collections.abc import Callable, Iterable, Sequence
|
|
65
66
|
from pathlib import Path
|
|
66
|
-
from typing import Any, TypeVar, cast
|
|
67
|
+
from typing import Any, ClassVar, TypeVar, cast
|
|
67
68
|
|
|
68
69
|
import bitmath
|
|
69
70
|
import msgspec
|
|
70
|
-
|
|
71
|
+
|
|
72
|
+
if sys.version_info >= (3, 11):
|
|
73
|
+
from typing import Self
|
|
74
|
+
else:
|
|
75
|
+
from typing_extensions import Self
|
|
71
76
|
|
|
72
77
|
from pymkv.chapters import (
|
|
73
78
|
ChapterAtom,
|
|
@@ -137,6 +142,8 @@ class MKVFile:
|
|
|
137
142
|
Raised if the path to mkvmerge could not be verified.
|
|
138
143
|
"""
|
|
139
144
|
|
|
145
|
+
DEFAULT_UI_LANGUAGE: ClassVar[str] = "en" if sys.platform == "win32" else "en_US"
|
|
146
|
+
|
|
140
147
|
def __init__(
|
|
141
148
|
self,
|
|
142
149
|
file_path: str | os.PathLike | None = None,
|
|
@@ -337,7 +344,9 @@ class MKVFile:
|
|
|
337
344
|
def command(
|
|
338
345
|
self,
|
|
339
346
|
output_path: str,
|
|
347
|
+
*,
|
|
340
348
|
subprocess: bool = False,
|
|
349
|
+
ui_language: str | None = None,
|
|
341
350
|
) -> str | list[str]:
|
|
342
351
|
"""
|
|
343
352
|
Generates an mkvmerge command based on the configured :class:`~pymkv.MKVFile`.
|
|
@@ -348,6 +357,17 @@ class MKVFile:
|
|
|
348
357
|
The path to be used as the output file in the mkvmerge command.
|
|
349
358
|
subprocess : bool
|
|
350
359
|
Will return the command as a list so it can be used easily with the :mod:`subprocess` module.
|
|
360
|
+
ui_language : str, optional
|
|
361
|
+
The locale passed to mkvmerge via ``--ui-language`` to control the language of its output
|
|
362
|
+
(progress messages, warnings, errors). When ``None`` or empty, the value of
|
|
363
|
+
:attr:`DEFAULT_UI_LANGUAGE` is used. Forcing English output keeps the progress parser in
|
|
364
|
+
:meth:`mux` working regardless of the system locale. mkvmerge's translation table differs
|
|
365
|
+
between builds: Unix builds expect POSIX-style codes (``en_US``, ``de_DE``), Windows builds
|
|
366
|
+
expect short codes (``en``, ``de``). Run ``mkvmerge --ui-language list`` to see the tokens
|
|
367
|
+
accepted on the host. The default is selected at import time from ``sys.platform``
|
|
368
|
+
(``en`` on ``win32``, ``en_US`` elsewhere); override explicitly when wrapping a foreign-build
|
|
369
|
+
binary — e.g. invoking ``mkvmerge.exe`` from a Cygwin/MSYS Python (``sys.platform`` reports
|
|
370
|
+
``cygwin``/``msys`` so the Unix default is picked, but the Windows binary needs ``en``).
|
|
351
371
|
|
|
352
372
|
Returns
|
|
353
373
|
-------
|
|
@@ -359,14 +379,12 @@ class MKVFile:
|
|
|
359
379
|
--------
|
|
360
380
|
>>> mkv = MKVFile()
|
|
361
381
|
>>> mkv.add_track('path/to/track.h264') # doctest: +SKIP
|
|
362
|
-
>>> # Generate command
|
|
363
|
-
>>>
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
>>>
|
|
367
|
-
|
|
368
|
-
>>> print(cmd_list) # doctest: +SKIP
|
|
369
|
-
['mkvmerge', '-o', 'output.mkv', 'path/to/track.h264']
|
|
382
|
+
>>> # Generate command list for subprocess (locale segment is platform-dependent)
|
|
383
|
+
>>> mkv.command('output.mkv', subprocess=True) # doctest: +SKIP
|
|
384
|
+
['mkvmerge', '--ui-language', 'en_US', '-o', 'output.mkv', 'path/to/track.h264']
|
|
385
|
+
>>> # Override when targeting a foreign-build binary or wanting translated output
|
|
386
|
+
>>> mkv.command('output.mkv', subprocess=True, ui_language='de_DE') # doctest: +SKIP
|
|
387
|
+
['mkvmerge', '--ui-language', 'de_DE', '-o', 'output.mkv', 'path/to/track.h264']
|
|
370
388
|
"""
|
|
371
389
|
|
|
372
390
|
self.output_path = str(Path(output_path).expanduser())
|
|
@@ -394,6 +412,7 @@ class MKVFile:
|
|
|
394
412
|
]
|
|
395
413
|
|
|
396
414
|
command_args = list(self.mkvmerge_path)
|
|
415
|
+
command_args.extend(("--ui-language", ui_language or self.DEFAULT_UI_LANGUAGE))
|
|
397
416
|
generated_args = list(itertools.chain.from_iterable(p.generate(self) for p in pipeline))
|
|
398
417
|
command_args.extend(generated_args)
|
|
399
418
|
|
|
@@ -402,9 +421,11 @@ class MKVFile:
|
|
|
402
421
|
def mux(
|
|
403
422
|
self,
|
|
404
423
|
output_path: str | os.PathLike,
|
|
424
|
+
*,
|
|
405
425
|
silent: bool = False,
|
|
406
426
|
ignore_warning: bool = False,
|
|
407
427
|
progress_handler: Callable[[int], None] | None = None,
|
|
428
|
+
ui_language: str | None = None,
|
|
408
429
|
) -> int:
|
|
409
430
|
"""
|
|
410
431
|
Mixes the specified :class:`~pymkv.MKVFile`.
|
|
@@ -419,6 +440,12 @@ class MKVFile:
|
|
|
419
440
|
If set to True, the muxing process will ignore any warnings (exit code 1) from mkvmerge.
|
|
420
441
|
progress_handler : Callable[[int], None], optional
|
|
421
442
|
A callback function that will be called with the current progress percentage (0-100).
|
|
443
|
+
ui_language : str, optional
|
|
444
|
+
The locale passed to mkvmerge via ``--ui-language``. When ``None`` (the default),
|
|
445
|
+
:attr:`DEFAULT_UI_LANGUAGE` is used so that the progress parser still recognises
|
|
446
|
+
``Progress: NN%`` lines on systems whose locale would otherwise translate mkvmerge
|
|
447
|
+
output. The default is platform-aware (``en_US`` on Unix, ``en`` on Windows);
|
|
448
|
+
see :meth:`command` for accepted tokens. Forwarded to :meth:`command`.
|
|
422
449
|
|
|
423
450
|
Returns
|
|
424
451
|
-------
|
|
@@ -448,7 +475,7 @@ class MKVFile:
|
|
|
448
475
|
0
|
|
449
476
|
"""
|
|
450
477
|
output_path = str(Path(output_path).expanduser())
|
|
451
|
-
args = self.command(output_path, subprocess=True)
|
|
478
|
+
args = self.command(output_path, subprocess=True, ui_language=ui_language)
|
|
452
479
|
|
|
453
480
|
if progress_handler:
|
|
454
481
|
stdout_target = sp.PIPE
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "pymkv2"
|
|
3
|
-
version = "2.3.
|
|
3
|
+
version = "2.3.2"
|
|
4
4
|
description = "A Python wrapper for mkvmerge. It provides support for muxing, splitting, linking, chapters, tags, and attachments through the use of mkvmerge."
|
|
5
5
|
authors = [
|
|
6
6
|
{ name = "GitBib", email = "job@bnff.website" },
|
|
@@ -47,6 +47,7 @@ dependencies = [
|
|
|
47
47
|
"bitmath<3.0.0,>=2.0.0",
|
|
48
48
|
"python-iso639<2027.0.0,>=2026.4.20",
|
|
49
49
|
"msgspec>=0.21.0",
|
|
50
|
+
"typing-extensions>=4.15.0 ; python_full_version < '3.11'",
|
|
50
51
|
]
|
|
51
52
|
|
|
52
53
|
[project.license]
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import subprocess as sp
|
|
2
|
+
import sys
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from unittest.mock import MagicMock, patch
|
|
5
|
+
|
|
6
|
+
import pytest
|
|
7
|
+
|
|
8
|
+
from pymkv import MKVFile
|
|
9
|
+
|
|
10
|
+
# pymkv.MKVFile is a class, effectively hiding the module of the same name.
|
|
11
|
+
# We need the module to patch 'verify_mkvmerge' which is a global in that module.
|
|
12
|
+
MKVFileModule = sys.modules["pymkv.MKVFile"]
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def test_mux_progress_handler() -> None:
|
|
16
|
+
# Setup mock Popen instance
|
|
17
|
+
process_mock = MagicMock()
|
|
18
|
+
# Support context manager
|
|
19
|
+
process_mock.__enter__.return_value = process_mock
|
|
20
|
+
process_mock.__exit__.return_value = None
|
|
21
|
+
|
|
22
|
+
# Configure stdout to be an iterator yielding progress lines
|
|
23
|
+
process_mock.stdout = iter(
|
|
24
|
+
[
|
|
25
|
+
"mkvmerge v1.0.0",
|
|
26
|
+
"Progress: 10%",
|
|
27
|
+
"Something else",
|
|
28
|
+
"Progress: 50%",
|
|
29
|
+
"Progress: 100%",
|
|
30
|
+
]
|
|
31
|
+
)
|
|
32
|
+
process_mock.communicate.return_value = (None, None)
|
|
33
|
+
process_mock.returncode = 0
|
|
34
|
+
|
|
35
|
+
# Setup callback
|
|
36
|
+
progress_values = []
|
|
37
|
+
|
|
38
|
+
def callback(percent: int) -> None:
|
|
39
|
+
progress_values.append(percent)
|
|
40
|
+
|
|
41
|
+
# Patch 'verify_mkvmerge' locally to avoid initialization running a subprocess
|
|
42
|
+
with (
|
|
43
|
+
patch.object(MKVFileModule, "verify_mkvmerge", return_value=True),
|
|
44
|
+
patch("subprocess.Popen", return_value=process_mock) as mock_popen,
|
|
45
|
+
):
|
|
46
|
+
mkv = MKVFile()
|
|
47
|
+
# Mock command generation
|
|
48
|
+
with patch.object(MKVFile, "command", return_value=["mkvmerge", "-o", "out.mkv"]):
|
|
49
|
+
mkv.mux("out.mkv", progress_handler=callback)
|
|
50
|
+
|
|
51
|
+
# Verify
|
|
52
|
+
assert progress_values == [10, 50, 100]
|
|
53
|
+
|
|
54
|
+
# Verify Popen was called with text=True and stdout=PIPE
|
|
55
|
+
_, kwargs = mock_popen.call_args
|
|
56
|
+
assert kwargs["text"] is True
|
|
57
|
+
assert kwargs["stdout"] == sp.PIPE
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def test_mux_progress_handler_no_progress() -> None:
|
|
61
|
+
# Test with no progress lines
|
|
62
|
+
process_mock = MagicMock()
|
|
63
|
+
# Support context manager
|
|
64
|
+
process_mock.__enter__.return_value = process_mock
|
|
65
|
+
process_mock.__exit__.return_value = None
|
|
66
|
+
|
|
67
|
+
process_mock.stdout = iter(["No progress here", "Just logs"])
|
|
68
|
+
process_mock.communicate.return_value = (None, None)
|
|
69
|
+
process_mock.returncode = 0
|
|
70
|
+
|
|
71
|
+
progress_values = []
|
|
72
|
+
|
|
73
|
+
def callback(percent: int) -> None:
|
|
74
|
+
progress_values.append(percent)
|
|
75
|
+
|
|
76
|
+
with (
|
|
77
|
+
patch.object(MKVFileModule, "verify_mkvmerge", return_value=True),
|
|
78
|
+
patch("subprocess.Popen", return_value=process_mock),
|
|
79
|
+
):
|
|
80
|
+
mkv = MKVFile()
|
|
81
|
+
with patch.object(MKVFile, "command", return_value=["mkvmerge", "-o", "out.mkv"]):
|
|
82
|
+
mkv.mux("out.mkv", progress_handler=callback)
|
|
83
|
+
|
|
84
|
+
assert progress_values == []
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
@pytest.mark.skipif(
|
|
88
|
+
sys.platform == "win32",
|
|
89
|
+
reason=(
|
|
90
|
+
"Windows mkvmerge ignores LANG/LC_ALL — it picks the UI locale via Windows API, "
|
|
91
|
+
"so the gettext-driven regression this test guards against cannot occur there. "
|
|
92
|
+
"Cross-platform coverage of the default flag is provided by "
|
|
93
|
+
"test_real_mkvmerge_default_ui_language_is_accepted_on_host."
|
|
94
|
+
),
|
|
95
|
+
)
|
|
96
|
+
def test_real_mkvmerge_progress_handler_default_ui_language_under_non_english_locale(
|
|
97
|
+
monkeypatch: pytest.MonkeyPatch,
|
|
98
|
+
get_base_path: Path,
|
|
99
|
+
get_path_test_file: Path,
|
|
100
|
+
) -> None:
|
|
101
|
+
"""Regression test for issue #115 (Unix-only).
|
|
102
|
+
|
|
103
|
+
Force the subprocess to inherit a non-English locale; if ``--ui-language`` were
|
|
104
|
+
not injected by default, ``mkvmerge`` on a system with German translations
|
|
105
|
+
installed would emit ``Fortschritt: 1%`` and the ``Progress:\\s*(\\d+)%`` parser
|
|
106
|
+
would silently never fire. Asserting that progress callbacks still arrive proves
|
|
107
|
+
the default flag is normalising output. On translation-less installs this still
|
|
108
|
+
exercises the real binary end-to-end.
|
|
109
|
+
"""
|
|
110
|
+
monkeypatch.setenv("LANG", "de_DE.UTF-8")
|
|
111
|
+
monkeypatch.setenv("LC_ALL", "de_DE.UTF-8")
|
|
112
|
+
monkeypatch.setenv("LANGUAGE", "de_DE")
|
|
113
|
+
|
|
114
|
+
output = get_base_path / "ui_language_progress_default.mkv"
|
|
115
|
+
|
|
116
|
+
mkv = MKVFile(get_path_test_file)
|
|
117
|
+
progress_values: list[int] = []
|
|
118
|
+
rc = mkv.mux(output, progress_handler=progress_values.append)
|
|
119
|
+
|
|
120
|
+
assert rc == 0
|
|
121
|
+
assert output.is_file()
|
|
122
|
+
assert progress_values, "progress_handler was never invoked — --ui-language not applied?"
|
|
123
|
+
assert progress_values[-1] == 100 # noqa: PLR2004
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def test_real_mkvmerge_explicit_ui_language_reaches_mkvmerge(
|
|
127
|
+
capfd: pytest.CaptureFixture[str],
|
|
128
|
+
get_base_path: Path,
|
|
129
|
+
get_path_test_file: Path,
|
|
130
|
+
) -> None:
|
|
131
|
+
"""Verify the explicit ``ui_language`` argument is actually forwarded to mkvmerge.
|
|
132
|
+
|
|
133
|
+
Pass an unsupported locale: mkvmerge rejects it (``Error: There is no translation
|
|
134
|
+
available for 'xyz_ZZ'``) on stdout and exits non-zero, which ``mux`` turns into
|
|
135
|
+
a ``ValueError``. To prove the override actually reached the binary (and was not
|
|
136
|
+
silently dropped, falling back to the platform default), assert ``xyz_ZZ`` shows
|
|
137
|
+
up in the subprocess stdout captured at the file-descriptor level — which is the
|
|
138
|
+
only place mkvmerge writes that string. Without this check, any unrelated
|
|
139
|
+
non-zero exit would also satisfy the test.
|
|
140
|
+
"""
|
|
141
|
+
output = get_base_path / "ui_language_invalid_override.mkv"
|
|
142
|
+
|
|
143
|
+
mkv = MKVFile(get_path_test_file)
|
|
144
|
+
with pytest.raises(ValueError, match=r"non-zero exit status \d+"):
|
|
145
|
+
mkv.mux(output, ui_language="xyz_ZZ")
|
|
146
|
+
|
|
147
|
+
captured = capfd.readouterr()
|
|
148
|
+
assert "xyz_ZZ" in captured.out, (
|
|
149
|
+
"mkvmerge stdout did not mention 'xyz_ZZ' — override likely never reached the binary"
|
|
150
|
+
)
|
|
151
|
+
assert not output.exists()
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def test_real_mkvmerge_default_ui_language_is_accepted_on_host(
|
|
155
|
+
get_base_path: Path,
|
|
156
|
+
get_path_test_file: Path,
|
|
157
|
+
) -> None:
|
|
158
|
+
"""Smoke test: the platform-aware default must be a token mkvmerge accepts.
|
|
159
|
+
|
|
160
|
+
If ``DEFAULT_UI_LANGUAGE`` is ever set to a value the host's mkvmerge build does
|
|
161
|
+
not have in its translation catalog (e.g. ``en_US`` on Windows, ``en`` on Unix —
|
|
162
|
+
both of which produce ``Error: There is no translation available for ...``),
|
|
163
|
+
``mux`` raises ``ValueError``. This test calls ``mux`` with no override and
|
|
164
|
+
asserts the binary actually accepts the default and produces a file.
|
|
165
|
+
"""
|
|
166
|
+
output = get_base_path / "ui_language_default_smoke.mkv"
|
|
167
|
+
|
|
168
|
+
mkv = MKVFile(get_path_test_file)
|
|
169
|
+
rc = mkv.mux(output, silent=True)
|
|
170
|
+
|
|
171
|
+
assert rc == 0
|
|
172
|
+
assert output.is_file()
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"""Unit tests for the ``ui_language`` plumbing on :class:`pymkv.MKVFile`.
|
|
2
|
+
|
|
3
|
+
These tests inspect the argument list returned by :meth:`MKVFile.command`
|
|
4
|
+
without invoking ``mkvmerge``. Real-binary coverage lives in
|
|
5
|
+
``tests/test_mux_progress.py``.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import sys
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
|
|
13
|
+
import pytest
|
|
14
|
+
|
|
15
|
+
from pymkv import MKVFile
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def test_command_default_ui_language(get_path_test_file: Path) -> None:
|
|
19
|
+
"""The default flag value comes from ``MKVFile.DEFAULT_UI_LANGUAGE``."""
|
|
20
|
+
mkv = MKVFile(get_path_test_file)
|
|
21
|
+
cmd = mkv.command("output.mkv", subprocess=True)
|
|
22
|
+
|
|
23
|
+
assert isinstance(cmd, list)
|
|
24
|
+
prefix_len = len(mkv.mkvmerge_path)
|
|
25
|
+
assert cmd[prefix_len : prefix_len + 2] == ["--ui-language", MKVFile.DEFAULT_UI_LANGUAGE]
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
@pytest.mark.skipif(sys.platform == "win32", reason="Unix mkvmerge expects POSIX-style locale codes")
|
|
29
|
+
def test_default_ui_language_is_en_us_on_unix() -> None:
|
|
30
|
+
"""Unix builds of mkvmerge accept ``en_US`` (POSIX); ``en`` is rejected.
|
|
31
|
+
|
|
32
|
+
The catalog is hardcoded in mkvmerge's ``translation.cpp``: each row has separate
|
|
33
|
+
``unix_locale`` and ``windows_locale`` columns, and ``get_locale()`` returns one or
|
|
34
|
+
the other depending on the build target. Verified via ``mkvmerge --ui-language list``.
|
|
35
|
+
"""
|
|
36
|
+
assert MKVFile.DEFAULT_UI_LANGUAGE == "en_US"
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
@pytest.mark.skipif(sys.platform != "win32", reason="Windows mkvmerge expects short locale codes")
|
|
40
|
+
def test_default_ui_language_is_en_on_windows() -> None:
|
|
41
|
+
"""Windows builds of mkvmerge accept ``en`` (short); ``en_US`` is rejected.
|
|
42
|
+
|
|
43
|
+
The Windows column of mkvmerge's translation table stores ``en`` for English. Passing
|
|
44
|
+
``en_US`` produces ``Error: There is no translation available for 'en_US'.`` and aborts
|
|
45
|
+
the mux. Verified via ``mkvmerge --ui-language list`` on the Windows runner.
|
|
46
|
+
"""
|
|
47
|
+
assert MKVFile.DEFAULT_UI_LANGUAGE == "en"
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def test_command_explicit_ui_language_override(get_path_test_file: Path) -> None:
|
|
51
|
+
"""An explicit ``ui_language`` kwarg replaces the default in the argv."""
|
|
52
|
+
mkv = MKVFile(get_path_test_file)
|
|
53
|
+
cmd = mkv.command("output.mkv", subprocess=True, ui_language="ja_JP")
|
|
54
|
+
|
|
55
|
+
assert isinstance(cmd, list)
|
|
56
|
+
prefix_len = len(mkv.mkvmerge_path)
|
|
57
|
+
assert cmd[prefix_len : prefix_len + 2] == ["--ui-language", "ja_JP"]
|
|
58
|
+
assert MKVFile.DEFAULT_UI_LANGUAGE not in cmd[prefix_len + 2 :]
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def test_command_subclass_default_ui_language(get_path_test_file: Path) -> None:
|
|
62
|
+
"""Subclasses can override ``DEFAULT_UI_LANGUAGE`` and the new value is honoured."""
|
|
63
|
+
|
|
64
|
+
class FrenchMKVFile(MKVFile):
|
|
65
|
+
DEFAULT_UI_LANGUAGE = "fr_FR"
|
|
66
|
+
|
|
67
|
+
mkv = FrenchMKVFile(get_path_test_file)
|
|
68
|
+
cmd = mkv.command("output.mkv", subprocess=True)
|
|
69
|
+
|
|
70
|
+
assert isinstance(cmd, list)
|
|
71
|
+
prefix_len = len(mkv.mkvmerge_path)
|
|
72
|
+
assert cmd[prefix_len : prefix_len + 2] == ["--ui-language", "fr_FR"]
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def test_command_explicit_overrides_subclass_default(get_path_test_file: Path) -> None:
|
|
76
|
+
"""An explicit kwarg beats the subclass-level default."""
|
|
77
|
+
|
|
78
|
+
class FrenchMKVFile(MKVFile):
|
|
79
|
+
DEFAULT_UI_LANGUAGE = "fr_FR"
|
|
80
|
+
|
|
81
|
+
mkv = FrenchMKVFile(get_path_test_file)
|
|
82
|
+
cmd = mkv.command("output.mkv", subprocess=True, ui_language="ja_JP")
|
|
83
|
+
|
|
84
|
+
assert isinstance(cmd, list)
|
|
85
|
+
prefix_len = len(mkv.mkvmerge_path)
|
|
86
|
+
assert cmd[prefix_len : prefix_len + 2] == ["--ui-language", "ja_JP"]
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def test_command_empty_ui_language_falls_back_to_default(get_path_test_file: Path) -> None:
|
|
90
|
+
"""Empty string is treated as "use default" rather than forwarded as ``--ui-language ''``."""
|
|
91
|
+
mkv = MKVFile(get_path_test_file)
|
|
92
|
+
cmd = mkv.command("output.mkv", subprocess=True, ui_language="")
|
|
93
|
+
|
|
94
|
+
assert isinstance(cmd, list)
|
|
95
|
+
prefix_len = len(mkv.mkvmerge_path)
|
|
96
|
+
assert cmd[prefix_len : prefix_len + 2] == ["--ui-language", MKVFile.DEFAULT_UI_LANGUAGE]
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def test_command_explicit_none_uses_default(get_path_test_file: Path) -> None:
|
|
100
|
+
"""Explicitly passing ``ui_language=None`` resolves to ``DEFAULT_UI_LANGUAGE``."""
|
|
101
|
+
mkv = MKVFile(get_path_test_file)
|
|
102
|
+
cmd = mkv.command("output.mkv", subprocess=True, ui_language=None)
|
|
103
|
+
|
|
104
|
+
assert isinstance(cmd, list)
|
|
105
|
+
prefix_len = len(mkv.mkvmerge_path)
|
|
106
|
+
assert cmd[prefix_len : prefix_len + 2] == ["--ui-language", MKVFile.DEFAULT_UI_LANGUAGE]
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def test_command_string_form_includes_ui_language(get_path_test_file: Path) -> None:
|
|
110
|
+
"""The non-subprocess (joined-string) return path must also carry the flag."""
|
|
111
|
+
mkv = MKVFile(get_path_test_file)
|
|
112
|
+
cmd_str = mkv.command("output.mkv")
|
|
113
|
+
|
|
114
|
+
assert isinstance(cmd_str, str)
|
|
115
|
+
assert f"--ui-language {MKVFile.DEFAULT_UI_LANGUAGE}" in cmd_str
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import subprocess as sp
|
|
2
|
-
import sys
|
|
3
|
-
from unittest.mock import MagicMock, patch
|
|
4
|
-
|
|
5
|
-
from pymkv import MKVFile
|
|
6
|
-
|
|
7
|
-
# pymkv.MKVFile is a class, effectively hiding the module of the same name.
|
|
8
|
-
# We need the module to patch 'verify_mkvmerge' which is a global in that module.
|
|
9
|
-
MKVFileModule = sys.modules["pymkv.MKVFile"]
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
def test_mux_progress_handler() -> None:
|
|
13
|
-
# Setup mock Popen instance
|
|
14
|
-
process_mock = MagicMock()
|
|
15
|
-
# Support context manager
|
|
16
|
-
process_mock.__enter__.return_value = process_mock
|
|
17
|
-
process_mock.__exit__.return_value = None
|
|
18
|
-
|
|
19
|
-
# Configure stdout to be an iterator yielding progress lines
|
|
20
|
-
process_mock.stdout = iter(
|
|
21
|
-
[
|
|
22
|
-
"mkvmerge v1.0.0",
|
|
23
|
-
"Progress: 10%",
|
|
24
|
-
"Something else",
|
|
25
|
-
"Progress: 50%",
|
|
26
|
-
"Progress: 100%",
|
|
27
|
-
]
|
|
28
|
-
)
|
|
29
|
-
process_mock.communicate.return_value = (None, None)
|
|
30
|
-
process_mock.returncode = 0
|
|
31
|
-
|
|
32
|
-
# Setup callback
|
|
33
|
-
progress_values = []
|
|
34
|
-
|
|
35
|
-
def callback(percent: int) -> None:
|
|
36
|
-
progress_values.append(percent)
|
|
37
|
-
|
|
38
|
-
# Patch 'verify_mkvmerge' locally to avoid initialization running a subprocess
|
|
39
|
-
with (
|
|
40
|
-
patch.object(MKVFileModule, "verify_mkvmerge", return_value=True),
|
|
41
|
-
patch("subprocess.Popen", return_value=process_mock) as mock_popen,
|
|
42
|
-
):
|
|
43
|
-
mkv = MKVFile()
|
|
44
|
-
# Mock command generation
|
|
45
|
-
with patch.object(MKVFile, "command", return_value=["mkvmerge", "-o", "out.mkv"]):
|
|
46
|
-
mkv.mux("out.mkv", progress_handler=callback)
|
|
47
|
-
|
|
48
|
-
# Verify
|
|
49
|
-
assert progress_values == [10, 50, 100]
|
|
50
|
-
|
|
51
|
-
# Verify Popen was called with text=True and stdout=PIPE
|
|
52
|
-
_, kwargs = mock_popen.call_args
|
|
53
|
-
assert kwargs["text"] is True
|
|
54
|
-
assert kwargs["stdout"] == sp.PIPE
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
def test_mux_progress_handler_no_progress() -> None:
|
|
58
|
-
# Test with no progress lines
|
|
59
|
-
process_mock = MagicMock()
|
|
60
|
-
# Support context manager
|
|
61
|
-
process_mock.__enter__.return_value = process_mock
|
|
62
|
-
process_mock.__exit__.return_value = None
|
|
63
|
-
|
|
64
|
-
process_mock.stdout = iter(["No progress here", "Just logs"])
|
|
65
|
-
process_mock.communicate.return_value = (None, None)
|
|
66
|
-
process_mock.returncode = 0
|
|
67
|
-
|
|
68
|
-
progress_values = []
|
|
69
|
-
|
|
70
|
-
def callback(percent: int) -> None:
|
|
71
|
-
progress_values.append(percent)
|
|
72
|
-
|
|
73
|
-
with (
|
|
74
|
-
patch.object(MKVFileModule, "verify_mkvmerge", return_value=True),
|
|
75
|
-
patch("subprocess.Popen", return_value=process_mock),
|
|
76
|
-
):
|
|
77
|
-
mkv = MKVFile()
|
|
78
|
-
with patch.object(MKVFile, "command", return_value=["mkvmerge", "-o", "out.mkv"]):
|
|
79
|
-
mkv.mux("out.mkv", progress_handler=callback)
|
|
80
|
-
|
|
81
|
-
assert progress_values == []
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|