64 lines
2.7 KiB
Python
64 lines
2.7 KiB
Python
"""Tests for `output_dir` routing — the app's "Pasta do projeto" promise.
|
|
|
|
The setting is documented in the UI as "everything generated is saved in
|
|
here". It used to be applied as a sandbox anchor only, while the filename
|
|
was still derived in the INPUT's directory — so any call whose output_dir
|
|
differed from the input's folder failed its own anchor check.
|
|
"""
|
|
|
|
import pytest
|
|
|
|
from server_tools._shared import _resolve_io_paths
|
|
|
|
|
|
@pytest.fixture
|
|
def project(tmp_path):
|
|
"""An .fcpxml in one folder, with a separate chosen output folder."""
|
|
source_dir = tmp_path / "media"
|
|
source_dir.mkdir()
|
|
fcpxml = source_dir / "Projeto.fcpxml"
|
|
fcpxml.write_text("<fcpxml version='1.13'/>")
|
|
chosen = tmp_path / "pasta do projeto"
|
|
chosen.mkdir()
|
|
return fcpxml, chosen
|
|
|
|
|
|
class TestOutputDirRouting:
|
|
def test_output_lands_in_the_chosen_folder(self, project):
|
|
fcpxml, chosen = project
|
|
_, output_path = _resolve_io_paths({"filepath": str(fcpxml), "output_dir": str(chosen)}, "_voice_edit")
|
|
assert output_path.startswith(str(chosen))
|
|
|
|
def test_filename_keeps_the_suffix_convention(self, project):
|
|
fcpxml, chosen = project
|
|
_, output_path = _resolve_io_paths({"filepath": str(fcpxml), "output_dir": str(chosen)}, "_voice_edit")
|
|
assert output_path.endswith("Projeto_voice_edit.fcpxml")
|
|
|
|
def test_cross_directory_call_does_not_raise(self, project):
|
|
"""The regression: output_dir different from the input folder used to
|
|
raise "output path escapes allowed directory" every single time."""
|
|
fcpxml, chosen = project
|
|
_resolve_io_paths({"filepath": str(fcpxml), "output_dir": str(chosen)}, "_dynamic_subtitles")
|
|
|
|
def test_without_output_dir_it_still_writes_beside_the_input(self, project):
|
|
fcpxml, _ = project
|
|
_, output_path = _resolve_io_paths({"filepath": str(fcpxml)}, "_modified")
|
|
assert output_path == str(fcpxml.parent / "Projeto_modified.fcpxml")
|
|
|
|
def test_explicit_output_path_still_wins(self, project):
|
|
fcpxml, chosen = project
|
|
target = chosen / "nome escolhido.fcpxml"
|
|
_, output_path = _resolve_io_paths(
|
|
{"filepath": str(fcpxml), "output_dir": str(chosen), "output_path": str(target)}, "_voice_edit"
|
|
)
|
|
assert output_path == str(target)
|
|
|
|
def test_explicit_output_path_outside_the_anchor_is_rejected(self, project, tmp_path):
|
|
"""The anchor must keep constraining explicit paths, not just names."""
|
|
fcpxml, chosen = project
|
|
with pytest.raises(ValueError):
|
|
_resolve_io_paths(
|
|
{"filepath": str(fcpxml), "output_dir": str(chosen),
|
|
"output_path": str(tmp_path / "fora.fcpxml")}, "_voice_edit"
|
|
)
|