Skip to content

Commit

Permalink
tests: Improve test for top-level conversion errors
Browse files Browse the repository at this point in the history
  • Loading branch information
apyrgio committed Oct 8, 2024
1 parent 328ddbe commit 1302a1f
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@
import traceback
from pathlib import Path
from typing import Optional, Sequence
from unittest import mock

import pytest
from click.testing import CliRunner, Result
from pytest_mock import MockerFixture
from strip_ansi import strip_ansi

from dangerzone.cli import cli_main, display_banner
from dangerzone.document import ARCHIVE_SUBDIR, SAFE_EXTENSION
from dangerzone.isolation_provider.qubes import is_qubes_native_conversion
from dangerzone.util import get_resource_path

from .conftest import for_each_doc, for_each_external_doc

Expand Down Expand Up @@ -211,17 +210,20 @@ def test_output_filename_uncommon(
result.assert_success()

### Test method for swallowed exception
def test_output_filename_same_file_dummy_fails(self) -> None:
resource_path = get_resource_path("dummy_document.pdf")
# Using the same filename for both input and output should fail.
result = self.run_cli(
[
resource_path,
"--output-filename",
resource_path,
"--unsafe-dummy-conversion",
]
def test_output_filename_pokemon_handler(
self,
sample_pdf: str,
mocker: MockerFixture,
) -> None:
"""Ensure that we catch top-level errors."""
mock_conv = mocker.patch(
"dangerzone.isolation_provider.base.IsolationProvider.convert"
)
mock_conv.side_effect = Exception("It happens")
result = self.run_cli([sample_pdf])
# FIXME: The following does not work, because the log is somehow not captured by
# Click's CliRunner.
# result.assert_failure(message="It happens")
result.assert_failure()

def test_output_filename_new_dir(self, sample_pdf: str) -> None:
Expand Down

0 comments on commit 1302a1f

Please sign in to comment.