summaryrefslogtreecommitdiff
path: root/tests/conftest.py
blob: 8a7412bb478c9709deba79710f4d82740ed460da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
"""
Fixtures for pytest.
"""

import locale

import pytest


def load_locale(x):
    """Convenience to load a locale, trying ISO8859-1 first."""
    try:
        locale.setlocale(locale.LC_ALL, str("{}.ISO8859-1".format(x)))
    except locale.Error:
        locale.setlocale(locale.LC_ALL, str("{}.UTF-8".format(x)))


@pytest.fixture()
def with_locale_en_us():
    """Convenience to load the en_US locale - reset when complete."""
    orig = locale.getlocale()
    yield load_locale("en_US")
    locale.setlocale(locale.LC_ALL, orig)


@pytest.fixture()
def with_locale_de_de():
    """
    Convenience to load the de_DE locale - reset when complete - skip if missing.
    """
    orig = locale.getlocale()
    try:
        load_locale("de_DE")
    except locale.Error:
        pytest.skip("requires de_DE locale to be installed")
    else:
        yield
    finally:
        locale.setlocale(locale.LC_ALL, orig)