Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion tests/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
import contextlib
import importlib.machinery
import importlib.util
import locale
import os
import pathlib
import shutil
import subprocess
import time
import unittest.mock
from collections.abc import Callable, Generator, Iterator, Sequence, Set
from collections.abc import Callable, Generator, Iterable, Iterator, Sequence, Set
from typing import Any
from unittest.mock import MagicMock

Expand Down Expand Up @@ -109,6 +110,17 @@ def _id(obj: Any) -> Any:
return obj


@contextlib.contextmanager
def set_locale(
category: int, new_locale: Iterable[str | None] | None
) -> Generator[None]:
"""Set locale and restore it after leaving this context manager."""
orig_locale = locale.getlocale(category)
locale.setlocale(category, new_locale)
yield
locale.setlocale(category, orig_locale)


def skip_if_command_is_missing(cmd: str) -> Callable:
"""Skip a test if the command is not found."""
if shutil.which(cmd) is None:
Expand Down
3 changes: 3 additions & 0 deletions tests/system/test_packaging_apt_dpkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import glob
import gzip
import locale
import os
import pathlib
import shutil
Expand All @@ -17,6 +18,7 @@
import pytest

from apport.packaging_impl.apt_dpkg import _parse_deb822_sources, impl
from tests.helper import set_locale
from tests.paths import get_test_data_directory

if shutil.which("dpkg") is None:
Expand Down Expand Up @@ -347,6 +349,7 @@ def test_install_packages_system(


@pytest.mark.requires_internet
@set_locale(locale.LC_MESSAGES, "C.UTF-8")
def test_install_packages_error(
configdir: str, cachedir: str, rootdir: str, apt_style: AptStyle
) -> None:
Expand Down
Loading