sissaschool / elementpath

XPath 1.0/2.0/3.0/3.1 parsers and selectors for ElementTree and lxml
MIT License
72 stars 20 forks source link

Test failures when de_DE.UTF-8 locale is not available #32

Closed mgorny closed 3 years ago

mgorny commented 3 years ago

I think the tests should check whether the needed locale is available. While I suppose relying on en_US.UTF-8 is pretty reasonable for the time being, many Gentoo users don't have German locales they're never going to use installed.

======================================================================
ERROR: test_use_locale_context_manager (tests.test_xpath_token.XPath1TokenTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/portage/dev-python/elementpath-2.1.0/work/elementpath-2.1.0/tests/test_xpath_token.py", line 185, in test_use_locale_context_manager
    with token.use_locale('de_DE.UTF-8'):
  File "/usr/lib/pypy3.7/lib-python/3/contextlib.py", line 112, in __enter__
    return next(self.gen)
  File "/tmp/portage/dev-python/elementpath-2.1.0/work/elementpath-2.1.0/elementpath/xpath_token.py", line 584, in use_locale
    raise self.error('FOCH0002', 'Unsupported collation %r' % collation) from None
elementpath.exceptions.ElementPathLocaleError: [FOCH0002] Unsupported collation 'de_DE.UTF-8'

======================================================================
ERROR: test_use_locale_context_manager (tests.test_xpath_token.XPath2TokenTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/portage/dev-python/elementpath-2.1.0/work/elementpath-2.1.0/tests/test_xpath_token.py", line 185, in test_use_locale_context_manager
    with token.use_locale('de_DE.UTF-8'):
  File "/usr/lib/pypy3.7/lib-python/3/contextlib.py", line 112, in __enter__
    return next(self.gen)
  File "/tmp/portage/dev-python/elementpath-2.1.0/work/elementpath-2.1.0/elementpath/xpath_token.py", line 584, in use_locale
    raise self.error('FOCH0002', 'Unsupported collation %r' % collation) from None
elementpath.exceptions.ElementPathLocaleError: [err:FOCH0002] Unsupported collation 'de_DE.UTF-8'
brunato commented 3 years ago

I'm sorry, it was an oversight, I've already other tests with the proper protection in case of locale error. I've just published a new release containing a fix for this.

mgorny commented 3 years ago

Thank you for the quick fix!