Beispiel #1
0
def setUpModule():
    global candidate_locales
    if sys.platform == 'sunos5':
        old_locale = locale.setlocale(locale.LC_ALL)
        try:
            locales = []
            for loc in candidate_locales:
                try:
                    locale.setlocale(locale.LC_ALL, loc)
                except Error:
                    continue
                encoding = locale.getpreferredencoding(False)
                try:
                    localeconv()
                except Exception as err:
                    print('WARNING: Skip locale %s (encoding %s): [%s] %s' %
                          (loc, encoding, type(err), err))
                else:
                    locales.append(loc)
            candidate_locales = locales
        finally:
            locale.setlocale(locale.LC_ALL, old_locale)
    if 'MSC v.1200' in sys.version:

        def accept(loc):
            a = loc.split('.')
            return not (len(a) == 2 and len(a[-1]) >= 9)

        candidate_locales = [loc for loc in candidate_locales if accept(loc)]
Beispiel #2
0
def setUpModule():
    global candidate_locales
    # Issue #13441: Skip some locales (e.g. cs_CZ and hu_HU) on Solaris to
    # workaround a mbstowcs() bug. For example, on Solaris, the hu_HU locale uses
    # the locale encoding ISO-8859-2, the thousauds separator is b'\xA0' and it is
    # decoded as U+30000020 (an invalid character) by mbstowcs().
    if sys.platform == 'sunos5':
        old_locale = locale.setlocale(locale.LC_ALL)
        try:
            locales = []
            for loc in candidate_locales:
                try:
                    locale.setlocale(locale.LC_ALL, loc)
                except Error:
                    continue
                encoding = locale.getpreferredencoding(False)
                try:
                    localeconv()
                except Exception as err:
                    print("WARNING: Skip locale %s (encoding %s): [%s] %s"
                        % (loc, encoding, type(err), err))
                else:
                    locales.append(loc)
            candidate_locales = locales
        finally:
            locale.setlocale(locale.LC_ALL, old_locale)

    # Workaround for MSVC6(debug) crash bug
    if "MSC v.1200" in sys.version:
        def accept(loc):
            a = loc.split(".")
            return not(len(a) == 2 and len(a[-1]) >= 9)
        candidate_locales = [loc for loc in candidate_locales if accept(loc)]
    def test_float_parsing(self):
        # Bug #1391872: Test whether float parsing is okay on European
        # locales.
        tested = False
        for loc in candidate_locales:
            try:
                setlocale(LC_NUMERIC, loc)
            except Error:
                continue

            # Ignore buggy locale databases. (Mac OS 10.4 and some other BSDs)
            if loc == 'eu_ES' and localeconv()['decimal_point'] == "' ":
                continue

            self.assertEqual(int(eval('3.14') * 100), 314,
                             "using eval('3.14') failed for %s" % loc)
            self.assertEqual(int(float('3.14') * 100), 314,
                             "using float('3.14') failed for %s" % loc)
            if localeconv()['decimal_point'] != '.':
                self.assertRaises(
                    ValueError, float,
                    localeconv()['decimal_point'].join(['1', '23']))
            tested = True
        if not tested:
            self.skipTest('no suitable locales')
Beispiel #4
0
def setUpModule():
    global candidate_locales
    # Issue #13441: Skip some locales (e.g. cs_CZ and hu_HU) on Solaris to
    # workaround a mbstowcs() bug. For example, on Solaris, the hu_HU locale uses
    # the locale encoding ISO-8859-2, the thousands separator is b'\xA0' and it is
    # decoded as U+30000020 (an invalid character) by mbstowcs().
    if sys.platform == 'sunos5':
        old_locale = locale.setlocale(locale.LC_ALL)
        try:
            locales = []
            for loc in candidate_locales:
                try:
                    locale.setlocale(locale.LC_ALL, loc)
                except Error:
                    continue
                encoding = locale.getpreferredencoding(False)
                try:
                    localeconv()
                except Exception as err:
                    print("WARNING: Skip locale %s (encoding %s): [%s] %s" %
                          (loc, encoding, type(err), err))
                else:
                    locales.append(loc)
            candidate_locales = locales
        finally:
            locale.setlocale(locale.LC_ALL, old_locale)

    # Workaround for MSVC6(debug) crash bug
    if "MSC v.1200" in sys.version:

        def accept(loc):
            a = loc.split(".")
            return not (len(a) == 2 and len(a[-1]) >= 9)

        candidate_locales = [loc for loc in candidate_locales if accept(loc)]
Beispiel #5
0
    def test_float_parsing(self):
        # Bug #1391872: Test whether float parsing is okay on European
        # locales.
        tested = False
        for loc in candidate_locales:
            try:
                setlocale(LC_NUMERIC, loc)
                setlocale(LC_CTYPE, loc)
            except Error:
                continue

            # Ignore buggy locale databases. (Mac OS 10.4 and some other BSDs)
            if loc == 'eu_ES' and localeconv()['decimal_point'] == "' ":
                continue

            self.assertEqual(int(eval('3.14') * 100), 314,
                                "using eval('3.14') failed for %s" % loc)
            self.assertEqual(int(float('3.14') * 100), 314,
                                "using float('3.14') failed for %s" % loc)
            if localeconv()['decimal_point'] != '.':
                self.assertRaises(ValueError, float,
                                  localeconv()['decimal_point'].join(['1', '23']))
            tested = True
        if not tested:
            self.skipTest('no suitable locales')
Beispiel #6
0
    def test_localeconv(self):
        import _locale

        lconv_c = {
            "currency_symbol": "",
            "decimal_point": ".",
            "frac_digits": 127,
            "grouping": [],
            "int_curr_symbol": "",
            "int_frac_digits": 127,
            "mon_decimal_point": "",
            "mon_grouping": [],
            "mon_thousands_sep": "",
            "n_cs_precedes": 127,
            "n_sep_by_space": 127,
            "n_sign_posn": 127,
            "negative_sign": "",
            "p_cs_precedes": 127,
            "p_sep_by_space": 127,
            "p_sign_posn": 127,
            "positive_sign": "",
            "thousands_sep": "" }

        _locale.setlocale(_locale.LC_ALL, "C")

        lconv = _locale.localeconv()
        for k, v in lconv_c.items():
            assert lconv[k] == v
Beispiel #7
0
 def test_lc_numeric_basic(self):
     # Test nl_langinfo against localeconv
     tested = False
     for loc in candidate_locales:
         try:
             setlocale(LC_NUMERIC, loc)
             setlocale(LC_CTYPE, loc)
         except Error:
             continue
         for li, lc in ((RADIXCHAR, "decimal_point"), (THOUSEP,
                                                       "thousands_sep")):
             nl_radixchar = nl_langinfo(li)
             li_radixchar = localeconv()[lc]
             try:
                 set_locale = setlocale(LC_NUMERIC)
             except Error:
                 set_locale = "<not able to determine>"
             self.assertEqual(
                 nl_radixchar, li_radixchar,
                 "%s (nl_langinfo) != %s (localeconv) "
                 "(set to %s, using %s)" %
                 (nl_radixchar, li_radixchar, loc, set_locale))
             tested = True
     if not tested:
         self.skipTest('no suitable locales')
Beispiel #8
0
 def test_lc_numeric_basic(self):
     # Test nl_langinfo against localeconv
     tested = False
     for loc in candidate_locales:
         try:
             setlocale(LC_NUMERIC, loc)
             setlocale(LC_CTYPE, loc)
         except Error:
             continue
         for li, lc in ((RADIXCHAR, "decimal_point"),
                         (THOUSEP, "thousands_sep")):
             nl_radixchar = nl_langinfo(li)
             li_radixchar = localeconv()[lc]
             try:
                 set_locale = setlocale(LC_NUMERIC)
             except Error:
                 set_locale = "<not able to determine>"
             self.assertEqual(nl_radixchar, li_radixchar,
                             "%s (nl_langinfo) != %s (localeconv) "
                             "(set to %s, using %s)" % (
                                             nl_radixchar, li_radixchar,
                                             loc, set_locale))
             tested = True
     if not tested:
         self.skipTest('no suitable locales')
Beispiel #9
0
    def test_localeconv(self):
        import _locale

        lconv_c = {
            "currency_symbol": "",
            "decimal_point": ".",
            "frac_digits": 127,
            "grouping": [],
            "int_curr_symbol": "",
            "int_frac_digits": 127,
            "mon_decimal_point": "",
            "mon_grouping": [],
            "mon_thousands_sep": "",
            "n_cs_precedes": 127,
            "n_sep_by_space": 127,
            "n_sign_posn": 127,
            "negative_sign": "",
            "p_cs_precedes": 127,
            "p_sep_by_space": 127,
            "p_sign_posn": 127,
            "positive_sign": "",
            "thousands_sep": ""
        }

        _locale.setlocale(_locale.LC_ALL, "C")

        lconv = _locale.localeconv()
        for k, v in lconv_c.items():
            assert lconv[k] == v
Beispiel #10
0
    def test_float_parsing(self):
        # Bug #1391872: Test whether float parsing is okay on European
        # locales.
        for loc in candidate_locales:
            try:
                setlocale(LC_NUMERIC, loc)
            except Error:
                continue

            # Ignore buggy locale databases. (Mac OS 10.4 and some other BSDs)
            if loc == "eu_ES" and localeconv()["decimal_point"] == "' ":
                continue

            self.assertEquals(int(eval("3.14") * 100), 314, "using eval('3.14') failed for %s" % loc)
            self.assertEquals(int(float("3.14") * 100), 314, "using float('3.14') failed for %s" % loc)
            if localeconv()["decimal_point"] != ".":
                self.assertRaises(ValueError, float, localeconv()["decimal_point"].join(["1", "23"]))
Beispiel #11
0
 def test_lc_numeric_localeconv(self):
     # Test localeconv against known values
     for loc in candidate_locales:
         try:
             setlocale(LC_NUMERIC, loc)
         except Error:
             continue
         for lc in ("decimal_point", "thousands_sep"):
             self.numeric_tester('localeconv', localeconv()[lc], lc, loc)
Beispiel #12
0
 def test_lc_numeric_localeconv(self):
     # Test localeconv against known values
     for loc in candidate_locales:
         try:
             setlocale(LC_NUMERIC, loc)
         except Error:
             continue
         for li, lc in ((RADIXCHAR, "decimal_point"), (THOUSEP, "thousands_sep")):
             self.numeric_tester("localeconv", localeconv()[lc], lc, loc)
 def test_lc_numeric_localeconv(self):
     # Test localeconv against known values
     for loc in candidate_locales:
         try:
             setlocale(LC_NUMERIC, loc)
         except Error:
             continue
         for lc in ("decimal_point", "thousands_sep"):
             self.numeric_tester('localeconv', localeconv()[lc], lc, loc)
 def test_lc_numeric_localeconv(self):
     # Test localeconv against known values
     for loc in candidate_locales:
         try:
             setlocale(LC_NUMERIC, loc)
             setlocale(LC_CTYPE, loc)
         except Error:
             continue
         for li, lc in ((RADIXCHAR, "decimal_point"),
                         (THOUSEP, "thousands_sep")):
             self.numeric_tester('localeconv', localeconv()[lc], lc, loc)
Beispiel #15
0
 def test_float_parsing(self):
     tested = False
     for loc in candidate_locales:
         try:
             setlocale(LC_NUMERIC, loc)
             setlocale(LC_CTYPE, loc)
         except Error:
             continue
         if loc == 'eu_ES' and localeconv()['decimal_point'] == "' ":
             continue
         self.assertEqual(int(eval('3.14') * 100), 314,
                          "using eval('3.14') failed for %s" % loc)
         self.assertEqual(int(float('3.14') * 100), 314,
                          "using float('3.14') failed for %s" % loc)
         if localeconv()['decimal_point'] != '.':
             self.assertRaises(
                 ValueError, float,
                 localeconv()['decimal_point'].join(['1', '23']))
         tested = True
     if not tested:
         self.skipTest('no suitable locales')
 def test_lc_numeric_localeconv(self):
     # Test localeconv against known values
     tested = False
     for loc in candidate_locales:
         try:
             setlocale(LC_NUMERIC, loc)
         except Error:
             continue
         formatting = localeconv()
         for lc in ("decimal_point", "thousands_sep"):
             if self.numeric_tester('localeconv', formatting[lc], lc, loc):
                 tested = True
     if not tested:
         self.skipTest('no suitable locales')
 def test_lc_numeric_localeconv(self):
     # Test localeconv against known values
     tested = False
     for loc in candidate_locales:
         try:
             setlocale(LC_NUMERIC, loc)
         except Error:
             continue
         formatting = localeconv()
         for lc in ("decimal_point", "thousands_sep"):
             if self.numeric_tester('localeconv', formatting[lc], lc, loc):
                 tested = True
     if not tested:
         self.skipTest('no suitable locales')
Beispiel #18
0
 def test_lc_numeric(self):
     for loc in candidate_locales:
         try:
             setlocale(LC_NUMERIC, loc)
         except Error:
             continue
         for li, lc in ((RADIXCHAR, "decimal_point"), (THOUSEP,
                                                       "thousands_sep")):
             nl_radixchar = nl_langinfo(li)
             li_radixchar = localeconv()[lc]
             # Both with seeing what the locale is set to in order to detect
             # when setlocale lies and says it accepted the locale setting
             # but in actuality didn't use it (as seen in OS X 10.3)
             try:
                 set_locale = setlocale(LC_NUMERIC)
             except Error:
                 set_locale = "<not able to determine>"
             self.assertEquals(
                 nl_radixchar, li_radixchar, "%s != %s (%s); "
                 "supposed to be %s, set to %s" %
                 (nl_radixchar, li_radixchar, lc, loc, set_locale))
Beispiel #19
0
    def test_lc_numeric_basic(self):
        import _locale
        if sys.platform == 'win32':
            skip("No nl_langinfo to test")
        from _locale import (setlocale, nl_langinfo, Error, LC_NUMERIC,
                             LC_CTYPE, RADIXCHAR, THOUSEP, localeconv)
        # Test nl_langinfo against localeconv
        candidate_locales = [
            'es_UY', 'fr_FR', 'fi_FI', 'es_CO', 'pt_PT', 'it_IT', 'et_EE',
            'es_PY', 'no_NO', 'nl_NL', 'lv_LV', 'el_GR', 'be_BY', 'fr_BE',
            'ro_RO', 'ru_UA', 'ru_RU', 'es_VE', 'ca_ES', 'se_NO', 'es_EC',
            'id_ID', 'ka_GE', 'es_CL', 'wa_BE', 'hu_HU', 'lt_LT', 'sl_SI',
            'hr_HR', 'es_AR', 'es_ES', 'oc_FR', 'gl_ES', 'bg_BG', 'is_IS',
            'mk_MK', 'de_AT', 'pt_BR', 'da_DK', 'nn_NO', 'cs_CZ', 'de_LU',
            'es_BO', 'sq_AL', 'sk_SK', 'fr_CH', 'de_DE', 'sr_YU', 'br_FR',
            'nl_BE', 'sv_FI', 'pl_PL', 'fr_CA', 'fo_FO', 'bs_BA', 'fr_LU',
            'kl_GL', 'fa_IR', 'de_BE', 'sv_SE', 'it_CH', 'uk_UA', 'eu_ES',
            'vi_VN', 'af_ZA', 'nb_NO', 'en_DK', 'tg_TJ', 'ps_AF', 'en_US',
            'fr_FR.ISO8859-1', 'fr_FR.UTF-8', 'fr_FR.ISO8859-15@euro',
            'ru_RU.KOI8-R', 'ko_KR.eucKR'
        ]

        tested = False
        for loc in candidate_locales:
            try:
                setlocale(LC_NUMERIC, loc)
                setlocale(LC_CTYPE, loc)
            except Error:
                continue
            for li, lc in ((RADIXCHAR, "decimal_point"), (THOUSEP,
                                                          "thousands_sep")):
                nl_radixchar = nl_langinfo(li)
                li_radixchar = localeconv()[lc]
                try:
                    set_locale = setlocale(LC_NUMERIC)
                except Error:
                    set_locale = "<not able to determine>"
                assert nl_radixchar == li_radixchar, (
                    "nl_langinfo != localeconv "
                    "(set to %s, using %s)" % (loc, set_locale))
 def test_lc_numeric(self):
     for loc in candidate_locales:
         try:
             setlocale(LC_NUMERIC, loc)
         except Error:
             continue
         for li, lc in ((RADIXCHAR, "decimal_point"),
                         (THOUSEP, "thousands_sep")):
             nl_radixchar = nl_langinfo(li)
             li_radixchar = localeconv()[lc]
             # Both with seeing what the locale is set to in order to detect
             # when setlocale lies and says it accepted the locale setting
             # but in actuality didn't use it (as seen in OS X 10.3)
             try:
                 set_locale = setlocale(LC_NUMERIC)
             except Error:
                 set_locale = "<not able to determine>"
             self.assertEquals(nl_radixchar, li_radixchar,
                                 "%s != %s (%s); "
                                 "supposed to be %s, set to %s" %
                                     (nl_radixchar, li_radixchar, lc,
                                      loc, set_locale))
Beispiel #21
0
# Issue #13441: Skip some locales (e.g. cs_CZ and hu_HU) on Solaris to
# workaround a mbstowcs() bug. For example, on Solaris, the hu_HU locale uses
# the locale encoding ISO-8859-2, the thousauds separator is b'\xA0' and it is
# decoded as U+30000020 (an invalid character) by mbstowcs().
if sys.platform == 'sunos5':
    old_locale = locale.setlocale(locale.LC_ALL)
    try:
        locales = []
        for loc in candidate_locales:
            try:
                locale.setlocale(locale.LC_ALL, loc)
            except Error:
                continue
            encoding = locale.getpreferredencoding(False)
            try:
                localeconv()
            except Exception as err:
                print("WARNING: Skip locale %s (encoding %s): [%s] %s"
                      % (loc, encoding, type(err), err))
            else:
                locales.append(loc)
        candidate_locales = locales
    finally:
        locale.setlocale(locale.LC_ALL, old_locale)

# Workaround for MSVC6(debug) crash bug
if "MSC v.1200" in sys.version:
    def accept(loc):
        a = loc.split(".")
        return not(len(a) == 2 and len(a[-1]) >= 9)
    candidate_locales = [loc for loc in candidate_locales if accept(loc)]
def test_localeconv():
    result = _locale.localeconv()
    Assert(result != None, "The method does not return the correct value")
    Assert(len(result) >= 14, "The elements in the sequence are not enough")
Beispiel #23
0
# Issue #13441: Skip some locales (e.g. cs_CZ and hu_HU) on Solaris to
# workaround a mbstowcs() bug. For example, on Solaris, the hu_HU locale uses
# the locale encoding ISO-8859-2, the thousauds separator is b'\xA0' and it is
# decoded as U+30000020 (an invalid character) by mbstowcs().
if sys.platform == 'sunos5':
    old_locale = locale.setlocale(locale.LC_ALL)
    try:
        locales = []
        for loc in candidate_locales:
            try:
                locale.setlocale(locale.LC_ALL, loc)
            except Error:
                continue
            encoding = locale.getpreferredencoding(False)
            try:
                localeconv()
            except Exception as err:
                print("WARNING: Skip locale %s (encoding %s): [%s] %s" %
                      (loc, encoding, type(err), err))
            else:
                locales.append(loc)
        candidate_locales = locales
    finally:
        locale.setlocale(locale.LC_ALL, old_locale)

# Workaround for MSVC6(debug) crash bug
if "MSC v.1200" in sys.version:

    def accept(loc):
        a = loc.split(".")
        return not (len(a) == 2 and len(a[-1]) >= 9)
 def test_localeconv(self):
     result = _locale.localeconv()
     self.assertTrue(result != None, "The method does not return the correct value")
     self.assertTrue(len(result)>=14, "The elements in the sequence are not enough")