Backblaze / b2-sdk-python

Python library to access B2 cloud storage.
Other
183 stars 61 forks source link

Locale test fails #488

Closed ezzieyguywuf closed 5 days ago

ezzieyguywuf commented 7 months ago

This is my system's locale:

$ locale
LANG=
LC_CTYPE="POSIX"
LC_NUMERIC="POSIX"
LC_TIME="POSIX"
LC_COLLATE="POSIX"
LC_MONETARY="POSIX"
LC_MESSAGES="POSIX"
LC_PAPER="POSIX"
LC_NAME="POSIX"
LC_ADDRESS="POSIX"
LC_TELEPHONE="POSIX"
LC_MEASUREMENT="POSIX"
LC_IDENTIFICATION="POSIX"
LC_ALL=

From this link it seems like this is the default locale, so it should be valid. However, here is the output from trying to run the test:

_________________________________________________ TestSetLocaleContextManager.test_set_locale_context_manager _________________________________________________                                            

self = <test.unit.b2http.test_b2http.TestSetLocaleContextManager testMethod=test_set_locale_context_manager>                                                                                               

    def test_set_locale_context_manager(self):                                                                                                                                                             
        # C.UTF-8 on Ubuntu 18.04 Bionic, C.utf8 on Ubuntu 22.04 Jammy                                                                                                                                     
        # Neither macOS nor Windows have C.UTF-8 locale, and they use `en_US.UTF-8`.                                                                                                                       
        # Since Python 3.12, locale.normalize no longer falls back                                                                                                                                         
        # to the `en_US` version, so we're providing it here manually.                                                                                                                                     
        test_locale = locale.normalize('C.UTF-8' if sys.platform == 'linux' else 'en_US.UTF-8')                                                                                                            
        other_locale = 'C'                                                                                                                                                                                 

        saved = locale.setlocale(locale.LC_ALL)                                                                                                                                                            
        if saved == test_locale:                                                                                                                                                                           
            test_locale, other_locale = other_locale, test_locale                                                                                                                                          

        locale.setlocale(locale.LC_ALL, other_locale)                                                                                                                                                      
>       with setlocale(test_locale):                                                                                                                                                                       

other_locale = 'C'                                                                                                                                                                                         
saved      = 'LC_CTYPE=C.UTF-8;LC_NUMERIC=C;LC_TIME=C;LC_COLLATE=C;LC_MONETARY=C;LC_MESSAGES=C;LC_PAPER=C;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=C;LC_IDENTIFICATION=C'                      
self       = <test.unit.b2http.test_b2http.TestSetLocaleContextManager testMethod=test_set_locale_context_manager>                                                                                         
test_locale = 'en_US.UTF-8'                                                                                                                                                                                

test/unit/b2http/test_b2http.py:374:                                                                                                                                                                       
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _                                            
/usr/lib/python3.11/contextlib.py:137: in __enter__                                                                                                                                                        
    return next(self.gen)                                                                                                                                                                                  
        self       = <contextlib._GeneratorContextManager object at 0x7f32c049d250>                                                                                                                        
b2sdk/_internal/b2http.py:75: in setlocale                                                                                                                                                                 
    yield locale.setlocale(locale.LC_ALL, name)                                                                                                                                                            
        name       = 'en_US.UTF-8'                                                                                                                                                                         
        saved      = 'C'                                                                                                                                                                                   
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _                                            

category = 6, locale = 'en_US.UTF-8'                                                                                                                                                                       

    def setlocale(category, locale=None):                                                                                                                                                                  

        """ Set the locale for the given category.  The locale can be                                                                                                                                      
            a string, an iterable of two strings (language code and encoding),                                                                                                                             
            or None.                                                                                                                                                                                       

            Iterables are converted to strings using the locale aliasing                                                                                                                                   
            engine.  Locale strings are passed directly to the C lib.                                                                                                                                      

            category may be given as one of the LC_* values.                                                                                                                                               

        """                                                                                                                                                                                                
        if locale and not isinstance(locale, _builtin_str):                                                                                                                                                
            # convert to string                                                                                                                                                                            
            locale = normalize(_build_localename(locale))                                                                                                                                                  
>       return _setlocale(category, locale)                                                                                                                                                                
E       locale.Error: unsupported locale setting 
mjurbanski-reef commented 7 months ago

Can you share information on the system you are running this on? I can only guess it is some kind of bare-bones container.

The simple solution is to just install 'en_US.UTF-8' locale before running test suite.