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.utf8') locale.setlocale(locale.LC_ALL, 'fr_FR.utf8') except locale.Error as e: pytest.skip(f'Locale error: {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.utf8'): assert date.strftime('%a, %b') == 'Sun, Oct' with misc._set_locale('fr_FR.utf8'): assert date.strftime('%a, %b') == 'dim., oct.' # Back to original assert date.strftime('%a, %b') == day_mon with misc._set_locale(current): assert date.strftime('%a, %b') == day_mon
def test_locale(): try: with _set_locale('fr_FR'): header = get_pkg_data_contents('data/locale.hdr', encoding='binary') with pytest.warns(FITSFixedWarning): 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")
def read(self, table): """ Read input data (file-like object, filename, list of strings, or single string) into a Table and return the result. """ if self.comment is not None and len(self.comment) != 1: raise core.ParameterError( "The C reader does not support a comment regex") elif self.data_start is None: raise core.ParameterError( "The C reader does not allow data_start to be None") elif self.header_start is not None and self.header_start < 0 and \ not isinstance(self, FastCommentedHeader): raise core.ParameterError( "The C reader does not allow header_start to be " "negative except for commented-header files") elif self.data_start < 0: raise core.ParameterError( "The C reader does not allow data_start to be negative") elif len(self.delimiter) != 1: raise core.ParameterError( "The C reader only supports 1-char delimiters") elif len(self.quotechar) != 1: raise core.ParameterError( "The C reader only supports a length-1 quote character") elif 'converters' in self.kwargs: raise core.ParameterError("The C reader does not support passing " "specialized converters") elif 'encoding' in self.kwargs: raise core.ParameterError( "The C reader does not use the encoding parameter") elif 'Outputter' in self.kwargs: raise core.ParameterError( "The C reader does not use the Outputter parameter") elif 'Inputter' in self.kwargs: raise core.ParameterError( "The C reader does not use the Inputter parameter") elif 'data_Splitter' in self.kwargs or 'header_Splitter' in self.kwargs: raise core.ParameterError( "The C reader does not use a Splitter class") self.strict_names = self.kwargs.pop('strict_names', False) # Process fast_reader kwarg, which may or may not exist (though ui.py will always # pass this as a dict with at least 'enable' set). fast_reader = self.kwargs.get('fast_reader', True) if not isinstance(fast_reader, dict): fast_reader = {} fast_reader.pop('enable', None) self.return_header_chars = fast_reader.pop('return_header_chars', False) # Put fast_reader dict back into kwargs. self.kwargs['fast_reader'] = fast_reader self.engine = cparser.CParser(table, self.strip_whitespace_lines, self.strip_whitespace_fields, delimiter=self.delimiter, header_start=self.header_start, comment=self.comment, quotechar=self.quotechar, data_start=self.data_start, fill_extra_cols=self.fill_extra_cols, **self.kwargs) conversion_info = self._read_header() self.check_header() if conversion_info is not None: try_int, try_float, try_string = conversion_info else: try_int = {} try_float = {} try_string = {} with _set_locale('C'): data, comments = self.engine.read(try_int, try_float, try_string) out = self.make_table(data, comments) if self.return_header_chars: out.meta[ '__ascii_fast_reader_header_chars__'] = self.engine.header_chars return out