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
9 changes: 9 additions & 0 deletions tests/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import functools
import importlib.machinery
import importlib.util
import locale
import os
import pathlib
import shutil
Expand Down Expand Up @@ -103,6 +104,14 @@ def read_shebang(command: str) -> str | None:
return first_line.decode().split(" ", 1)[0][2:]


@contextlib.contextmanager
def restore_locale(category: int) -> Generator[None]:
"""Restore locale after leaving this context manager."""
orig_locale = locale.getlocale(category)
yield
locale.setlocale(category, orig_locale)


@contextlib.contextmanager
def restore_os_environ() -> Generator[None]:
"""Restore os.environ after leaving this context manager."""
Expand Down
5 changes: 4 additions & 1 deletion 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,7 +18,7 @@
import pytest

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

if shutil.which("dpkg") is None:
Expand Down Expand Up @@ -348,10 +349,12 @@ def test_install_packages_system(


@pytest.mark.skipif(not has_internet(), reason="online test")
@restore_locale(locale.LC_MESSAGES)
def test_install_packages_error(
configdir: str, cachedir: str, rootdir: str, apt_style: AptStyle
) -> None:
"""install_packages() with errors"""
locale.setlocale(locale.LC_MESSAGES, "C.UTF-8")
# sources.list with invalid format
release = _setup_foonux_config(configdir, apt_style)
with open(
Expand Down
Loading