openzim / python-scraperlib

Collection of Python code to re-use across Python-based scrapers
GNU General Public License v3.0
19 stars 16 forks source link

unchanged project has two test failures #157

Closed richterdavid closed 2 months ago

richterdavid commented 5 months ago

On slack, asking about this got this response from rgaudin:

it’s testing locales and you don’t have them on the system testing it. Open a
ticket but it will be a duplicate. We already have a ticket to switch to a bundled approach (babel)

Full test logs:

github/python-scraperlib$ invoke coverage
================================================= test session starts ==================================================
platform linux -- Python 3.11.2, pytest-8.1.1, pluggy-1.5.0
rootdir: /home/david/github/python-scraperlib
configfile: pyproject.toml
testpaths: tests
plugins: mock-3.12.0, anyio-4.3.0
collected 374 items

tests/download/test_download.py .....sssssssssssss......                                                         [  6%]
tests/filesystem/test_filesystem.py ......                                                                       [  8%]
tests/html/test_html.py ......                                                                                   [  9%]
tests/i18n/test_i18n.py .......................FF                                                                [ 16%]
tests/image/test_image.py ..............................................................................         [ 37%]
tests/inputs/test_inputs.py ......................                                                               [ 43%]
tests/logging/test_logging.py .................                                                                  [ 47%]
tests/misc/test_misc.py ....                                                                                     [ 48%]
tests/ogvjs/test_ogvjs.py ..ss                                                                                   [ 49%]
tests/types/test_types.py ..............                                                                         [ 53%]
tests/uri/test_uri.py ..............                                                                             [ 57%]
tests/video/test_encoding.py ....                                                                                [ 58%]
tests/video/test_video.py ...ssss......ssssssssss                                                                [ 64%]
tests/zim/test_archive.py ......ss...                                                                            [ 67%]
tests/zim/test_fs.py ..........                                                                                  [ 70%]
tests/zim/test_libkiwix.py .................                                                                     [ 74%]
tests/zim/test_metadata.py .......                                                                               [ 76%]
tests/zim/test_zim_creator.py .................................................................................. [ 98%]
......                                                                                                           [100%]

======================================================= FAILURES =======================================================
_________________________________________ test_translation[fr-Bonjour monde !] _________________________________________

lang = 'fr', expected = 'Bonjour monde !'

    @pytest.mark.parametrize(
        "lang,expected",
        [("en", "Hello World!"), ("fr", "Bonjour monde !"), ("pt_BR.utf8", "Olá Mundo!")],
    )
    def test_translation(lang, expected):
>       setlocale(pathlib.Path(__file__).parent, lang)

tests/i18n/test_i18n.py:215:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
src/zimscraperlib/i18n.py:59: in setlocale
    return Locale.setup(root_dir / "locale", locale_name)
src/zimscraperlib/i18n.py:39: in setup
    computed = locale.setlocale(locale.LC_ALL, (cls.lang, cls.encoding))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

category = 6, locale = 'fr_FR.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

/usr/lib/python3.11/locale.py:626: Error
______________________________________ test_translation[pt_BR.utf8-Ol\xe1 Mundo!] ______________________________________

lang = 'pt_BR.utf8', expected = 'Olá Mundo!'

    @pytest.mark.parametrize(
        "lang,expected",
        [("en", "Hello World!"), ("fr", "Bonjour monde !"), ("pt_BR.utf8", "Olá Mundo!")],
    )
    def test_translation(lang, expected):
>       setlocale(pathlib.Path(__file__).parent, lang)

tests/i18n/test_i18n.py:215:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
src/zimscraperlib/i18n.py:59: in setlocale
    return Locale.setup(root_dir / "locale", locale_name)
src/zimscraperlib/i18n.py:39: in setup
    computed = locale.setlocale(locale.LC_ALL, (cls.lang, cls.encoding))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

category = 6, locale = 'pt_BR.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

/usr/lib/python3.11/locale.py:626: Error
=============================================== short test summary info ================================================
FAILED tests/i18n/test_i18n.py::test_translation[fr-Bonjour monde !] - locale.Error: unsupported locale setting
FAILED tests/i18n/test_i18n.py::test_translation[pt_BR.utf8-Ol\xe1 Mundo!] - locale.Error: unsupported locale setting
====================================== 2 failed, 341 passed, 31 skipped in 37.22s ======================================
benoit74 commented 3 months ago

Indeed it is more or less mentioned in the README:

Nota: i18n features do not work on Alpine, see https://github.com/openzim/python-scraperlib/issues/134 ; there is one corresponding test which is failing.

Looks like there are two tests in your case, not sure why but anyway strongly related to this locale problem. In your case it looks like locale is available but it misses the fr and pt_BR.utf8 locales.

Could you precise which locales are installed on your system, and what is your OS?

richterdavid commented 3 months ago

I'm running the Microsoft Windows Subsystem for Linux flavor of Debian.

$ locale -a
C
C.utf8
en_US.utf8
POSIX
benoit74 commented 3 months ago

OK, so it is "normal" the tests are failing. Could you please add fr and pt_BR.utf8 locales and check if the tests are still failing?

richterdavid commented 3 months ago

They pass after rerunning locale-gen. One possible small change is to add an error message along the lines of "If $LOCALE is not installed, please install it and rerun this test." If that's not needed after some larger changes, fine, it's not a lot of lost work.

root:~# locale-gen
Generating locales (this might take a while)...
  en_US.UTF-8... done
  fr_FR.UTF-8... done
  pt_BR.UTF-8... done
Generation complete.
root:~# locale -a
C
C.utf8
en_US.utf8
fr_FR.utf8
POSIX
pt_BR.utf8