Skip to content

Commit

Permalink
fix locale testing on linux
Browse files Browse the repository at this point in the history
  • Loading branch information
sdementen committed Apr 16, 2018
1 parent 7edcf92 commit f7fc3bb
Showing 1 changed file with 27 additions and 13 deletions.
40 changes: 27 additions & 13 deletions tests/test_session.py
Expand Up @@ -5,6 +5,7 @@
import sys

import pytest
from decorator import contextmanager

from piecash import create_book, Account, open_book
from piecash._common import get_system_currency_mnemonic
Expand Down Expand Up @@ -69,23 +70,36 @@ def test_build_uri(self):
assert build_uri(sqlite_file=uri) == sqlite_uri


def test_get_system_currency_mnemonic():
assert get_system_currency_mnemonic() == "EUR"
@contextmanager
def locale_ctx(l):
_l = locale.getlocale()

locale.setlocale(locale.LC_ALL, l)

def test_get_system_currency_mnemonic_US():
l = locale.getlocale()
yield

if sys.platform == "win32":
# see https://docs.moodle.org/dev/Table_of_locales
locale.setlocale(locale.LC_ALL, 'English_United States.1252')
else:
locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')
locale.setlocale(locale.LC_ALL, _l)

assert get_system_currency_mnemonic() == "USD"

locale.setlocale(locale.LC_ALL, l)
if sys.platform == "win32":
locales = {
(None, None): "EUR",
'English_United States.1252': "USD",
'French_France.1252': "EUR",
}
else:
locales = {
(None, None): "EUR",
'en_US.UTF-8': "USD",
'fr_FR.UTF-8': "EUR",
}


@pytest.yield_fixture(params=locales)
def locale_set(request):
yield request.param

def test_get_system_currency_mnemonic_after():
assert get_system_currency_mnemonic() == "EUR"
def test_get_system_currency_mnemonic(locale_set):
result = locales[locale_set]
with locale_ctx(locale_set):
assert get_system_currency_mnemonic() == result

0 comments on commit f7fc3bb

Please sign in to comment.