コード例 #1
0
def test_set_locale():
    if all(x is None for x in _current_locale):
        # Not sure why, but on some Travis runs with pytest,
        #  getlocale() returned (None, None).
        pytest.skip("Current locale is not set.")

    locale_override = os.environ.get("LOCALE_OVERRIDE", None)

    if locale_override is None:
        lang, enc = "it_CH", "UTF-8"
    elif locale_override == "C":
        lang, enc = "en_US", "ascii"
    else:
        lang, enc = locale_override.split(".")

    enc = codecs.lookup(enc).name
    new_locale = lang, enc

    if not can_set_locale(new_locale):
        msg = "unsupported locale setting"

        with pytest.raises(locale.Error, match=msg):
            with set_locale(new_locale):
                pass
    else:
        with set_locale(new_locale) as normalized_locale:
            new_lang, new_enc = normalized_locale.split(".")
            new_enc = codecs.lookup(enc).name

            normalized_locale = new_lang, new_enc
            assert normalized_locale == new_locale

    # Once we exit the "with" statement, locale should be back to what it was.
    current_locale = locale.getlocale()
    assert current_locale == _current_locale
コード例 #2
0
ファイル: test_localization.py プロジェクト: sjx-git/com.BBD
def test_set_locale(lang, enc):
    if all(x is None for x in _current_locale):
        # Not sure why, but on some Travis runs with pytest,
        #  getlocale() returned (None, None).
        pytest.skip("Current locale is not set.")

    enc = codecs.lookup(enc).name
    new_locale = lang, enc

    if not can_set_locale(new_locale):
        msg = "unsupported locale setting"

        with pytest.raises(locale.Error, match=msg):
            with set_locale(new_locale):
                pass
    else:
        with set_locale(new_locale) as normalized_locale:
            new_lang, new_enc = normalized_locale.split(".")
            new_enc = codecs.lookup(enc).name

            normalized_locale = new_lang, new_enc
            assert normalized_locale == new_locale

    # Once we exit the "with" statement, locale should be back to what it was.
    current_locale = locale.getlocale()
    assert current_locale == _current_locale
コード例 #3
0
def test_set_locale(lang, enc):
    before_locale = _get_current_locale()

    enc = codecs.lookup(enc).name
    new_locale = lang, enc

    if not can_set_locale(new_locale):
        msg = "unsupported locale setting"

        with pytest.raises(locale.Error, match=msg):
            with set_locale(new_locale):
                pass
    else:
        with set_locale(new_locale) as normalized_locale:
            new_lang, new_enc = normalized_locale.split(".")
            new_enc = codecs.lookup(enc).name

            normalized_locale = new_lang, new_enc
            assert normalized_locale == new_locale

    # Once we exit the "with" statement, locale should be back to what it was.
    after_locale = _get_current_locale()
    assert before_locale == after_locale