Example #1
0
def test_set_locale():
    # First, test if the required locales are available
    current = locale.setlocale(locale.LC_ALL)
    try:
        locale.setlocale(locale.LC_ALL, str('en_US'))
        locale.setlocale(locale.LC_ALL, str('de_DE'))
    except locale.Error as e:
        pytest.skip('Locale error: {}'.format(e))
    finally:
        locale.setlocale(locale.LC_ALL, current)

    date = datetime(2000, 10, 1, 0, 0, 0)
    day_mon = date.strftime('%a, %b')

    with misc.set_locale('en_US'):
        assert date.strftime('%a, %b') == 'Sun, Oct'

    with misc.set_locale('de_DE'):
        assert date.strftime('%a, %b') == 'So, Okt'

    # Back to original
    assert date.strftime('%a, %b') == day_mon

    with misc.set_locale(current):
        assert date.strftime('%a, %b') == day_mon
Example #2
0
def test_set_locale():
    # First, test if the required locales are available
    current = locale.setlocale(locale.LC_ALL)
    try:
        locale.setlocale(locale.LC_ALL, 'en_US')
        locale.setlocale(locale.LC_ALL, 'de_DE')
    except locale.Error as e:
        pytest.skip('Locale error: {}'.format(e))
    finally:
        locale.setlocale(locale.LC_ALL, current)

    date = datetime(2000, 10, 1, 0, 0, 0)
    day_mon = date.strftime('%a, %b')

    with misc.set_locale('en_US'):
        assert date.strftime('%a, %b') == 'Sun, Oct'

    with misc.set_locale('de_DE'):
        assert date.strftime('%a, %b') == 'So, Okt'

    # Back to original
    assert date.strftime('%a, %b') == day_mon

    with misc.set_locale(current):
        assert date.strftime('%a, %b') == day_mon
Example #3
0
def test_locale():
    try:
        with set_locale('fr_FR'):
            header = get_pkg_data_contents('data/locale.hdr',
                                           encoding='binary')
            w = _wcs.Wcsprm(header)
            assert re.search("[0-9]+,[0-9]*", w.to_header()) is None
    except locale.Error:
        pytest.xfail(
            "Can't set to 'fr_FR' locale, perhaps because it is not installed "
            "on this system")
#files    = glob.glob(dir_data + '/*orders*.csv')
file_csv  = 'uwingu-orders-export_all.csv'
file_pickle = file_csv.replace('.csv', '.pkl')
file_coupons = 'Uwingu03-Oct-2016_15_15_06 Coupon History.csv'

if (DO_READ_PICKLE):
    print('Reading pickle file: ' + dir_data + '/' + file_pickle)
    lun = open(dir_data + '/' + file_pickle, 'rb')
    t = pickle.load(lun)
    lun.close()

else:            

    # Read the main table from csv (which is very very slow)
    
    with set_locale('en_US.UTF-8'):
        print("Reading CSV file " + dir_data + "/" + file_csv)
        t = Table.read(dir_data + '/' + file_csv, format='ascii') 
        # This is really slow. Several minutes to read 23K-line file.
        # Format must be 'ascii', not 'csv', in order to read unicode properly.

# Sort it in place (overwrites existing)

t.sort(keys='order_id')

# Read the coupons table

tc = Table.read(dir_data + '/' + file_coupons, format='ascii.csv')

# Make a list of all of the promo coupons. I assmbled this manually from the list of codes actually used
#files    = glob.glob(dir_data + '/*orders*.csv')
file_csv = 'uwingu-orders-export_all.csv'
file_pickle = file_csv.replace('.csv', '.pkl')
file_coupons = 'Uwingu03-Oct-2016_15_15_06 Coupon History.csv'

if (DO_READ_PICKLE):
    print('Reading pickle file: ' + dir_data + '/' + file_pickle)
    lun = open(dir_data + '/' + file_pickle, 'rb')
    t = pickle.load(lun)
    lun.close()

else:

    # Read the main table from csv (which is very very slow)

    with set_locale('en_US.UTF-8'):
        print("Reading CSV file " + dir_data + "/" + file_csv)
        t = Table.read(dir_data + '/' + file_csv, format='ascii')
        # This is really slow. Several minutes to read 23K-line file.
        # Format must be 'ascii', not 'csv', in order to read unicode properly.

# Sort it in place (overwrites existing)

t.sort(keys='order_id')

# Read the coupons table

tc = Table.read(dir_data + '/' + file_coupons, format='ascii.csv')

# Make a list of all of the promo coupons. I assmbled this manually from the list of codes actually used