sissaschool/elementpath

test_compare_strings_function does not handle missing locales gracefully

mgorny opened this issue · 2 comments

The tests fail on systems not having all tested locales installed. Instead, I think the particular parts of tests should be skipped if locale in question is not available.

Example error:

======================================================================
ERROR: test_compare_strings_function (tests.test_xpath2_parser.LxmlXPath2ParserTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/elementpath-1.3.1/tests/test_xpath2_parser.py", line 362, in test_compare_strings_function
    self.check_value(u"fn:compare('Strasse', 'Straße', 'it_IT')", -1)
  File "/tmp/elementpath-1.3.1/tests/test_xpath1_parser.py", line 145, in check_value
    root_token = self.parser.parse(path)
  File "/tmp/elementpath-1.3.1/elementpath/xpath2_parser.py", line 348, in parse
    root_token.evaluate()  # Static context evaluation
  File "/tmp/elementpath-1.3.1/elementpath/xpath1_parser.py", line 350, in evaluate
    return self[1].evaluate(context)
  File "/tmp/elementpath-1.3.1/elementpath/xpath2_functions.py", line 640, in evaluate
    with self.use_locale(collation=self.get_argument(context, 2)):
  File "/usr/lib64/python2.7/contextlib.py", line 17, in __enter__
    return self.gen.next()
  File "/tmp/elementpath-1.3.1/elementpath/xpath_token.py", line 469, in use_locale
    raise self.error('FOCH0002', 'Unsupported collation %r' % collation)
ElementPathLocaleError: 'compare' function: [err:FOCH0002] Unsupported collation u'it_IT'.

Ok, I will skip tests for not installed locales in next release v1.3.2 (this release will maybe also the last version with Python 2.7 support, the release v1.4.0 will be only Python 3.5+ compatible).
Thanks

Now locales related test should fail gracefully in release v1.3.2.
Thanks