openzim / python-scraperlib

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

3 failed tests on Alpine Linux #114

Closed OTLabs closed 4 months ago

OTLabs commented 7 months ago

While building a package for Alpine Linux, musl, I got 3 failed tests:

=========================== short test summary info ============================
FAILED tests/i18n/test_i18n.py::test_selocale_unsupported - Failed: DID NOT RAISE <class 'locale.Error'>
FAILED tests/ogvjs/test_ogvjs.py::test_installed_script - FileNotFoundError: [Errno 2] No such file or directory: 'fix_ogvjs_dist'
FAILED tests/video/test_video.py::test_get_media_info[mp4-video.mp4-expected1] - AssertionError: assert {'bitrate': 3...'duration': 2} == {'bitrate': 3...'duration': 2}
  Omitting 2 identical items, use -vv to show
  Differing items:
  {'bitrate': 3837275} != {'bitrate': 3818365}
  Full diff:
  - {'bitrate': 3818365, 'codecs': ['h264', 'aac'], 'duration': 2}
  ?               -- ^
  + {'bitrate': 3837275, 'codecs': ['h264', 'aac'], 'duration': 2}
  ?                ^^^
================= 3 failed, 321 passed, 31 warnings in 59.12s ==================

How critical are these tests? Could I ignore them?

rgaudin commented 7 months ago

Those tests are not part of python libzim. Looks like python-scraperlib. I'll move the ticket but those are all environment related (version of ffmpeg installed, locales installed) so not critical

kelson42 commented 6 months ago

How critical is that? Sounds blocking for Alpine packaging.

rgaudin commented 6 months ago

Will change the tests very soon ; this is happening on various platforms

benoit74 commented 5 months ago

@rgaudin did you achieved to reproduce this on alpine? How?

I tried to start an alpine container but tests are failing due to a problem with libmagic linking - even if I installed it

Start container (from repo base folder):

docker run -it --rm -v $PWD:/src python:3.11-alpine /bin/sh

Inside container:

apk add libmagic
cd src
pip install -U pip tox
tox -e py311

Errors I get:

ERROR tests/filesystem/test_filesystem.py - AttributeError: Symbol not found: magic_open
ERROR tests/zim/test_archive.py - AttributeError: Symbol not found: magic_open
ERROR tests/zim/test_fs.py - AttributeError: Symbol not found: magic_open
ERROR tests/zim/test_zim_creator.py - AttributeError: Symbol not found: magic_open
rgaudin commented 5 months ago

I've already switched another project from file-magic to python-magic. Despite it being from the upstream team, they don't seem to put much effort in the binding. python-magic is better maintained IMO.

Just tested that it works fine on Alpine 👍

benoit74 commented 4 months ago

I've made the transition to python-magic successfully, and it has indeed a better support of Alpine. I still don't get why it wasn't reported as an issue as well by @OTLabs .

I now struggle with the locale test. It looks like locales are not really implemented, at least setting a locale always succeed.

If I make a simple test on a Debian, it fails if locale setting is not supported locally:

docker run -it --rm -v $PWD:/src python:3.11-slim-bookworm python -c "exec(\"import locale\nlocale.setlocale(locale.LC_ALL, ('bam', 'UTF-8'))\")"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "<string>", line 2, in <module>
  File "/usr/local/lib/python3.11/locale.py", line 627, in setlocale
    return _setlocale(category, locale)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
locale.Error: unsupported locale setting

If I do the same on Alpine, it always succeed (it returns nothing):

docker run -it --rm -v $PWD:/src python:3.11-alpine python -c "exec(\"import locale\nlocale.setlocale(locale.LC_ALL, ('bam', 'UTF-8'))\")"       

I searched online but found no relevant hint on what to do. Is someone more successful?

rgaudin commented 4 months ago

Not fixing your problem but I don't understand your exec here.

❯ docker run -it --rm -v $PWD:/src python:3.11-alpine python -c 'import locale ; print(locale.setlocale(locale.LC_ALL, ("nopnopop", "UTF-8")))'
nopnopop.UTF-8

This returns although it's not failing due to missing locale as you would expect…

benoit74 commented 4 months ago

I'm just not as used as you are to write Python one-liners, but it is almost the same thing, I just didn't googled enough about how to write one-liners 😉

benoit74 commented 4 months ago

@OTLabs

Few things:

Once #133 is merged I will close this issue since we will have answered your concerns, please track #134 progress if you want to be informed of the next steps.