ahupp / python-magic

A python wrapper for libmagic
Other
2.6k stars 280 forks source link

0.4.25: pytest is failing #265

Closed kloczek closed 2 years ago

kloczek commented 2 years ago

I'm trying to package your module as an rpm package. So I'm using the typical PEP517 based build, install and test cycle used on building packages from non-root account.

Here is pytest output:

+ PYTHONPATH=/home/tkloczko/rpmbuild/BUILDROOT/python-magic-0.4.25-2.fc35.x86_64/usr/lib64/python3.8/site-packages:/home/tkloczko/rpmbuild/BUILDROOT/python-magic-0.4.25-2.fc35.x86_64/usr/lib/python3.8/site-packages
+ /usr/bin/pytest -ra
=========================================================================== test session starts ============================================================================
platform linux -- Python 3.8.13, pytest-7.1.1, pluggy-1.0.0
rootdir: /home/tkloczko/rpmbuild/BUILD/python-magic-0.4.25
collected 3 items

test/libmagic_test.py FFF                                                                                                                                            [100%]

================================================================================= FAILURES =================================================================================
__________________________________________________________________ MagicTestCase.test_detect_from_content __________________________________________________________________

self = <test.libmagic_test.MagicTestCase testMethod=test_detect_from_content>

    def test_detect_from_content(self):
        # differ from upstream by opening file in binary mode,
        # this avoids hitting a bug in python3+libfile bindings
        # see https://github.com/ahupp/python-magic/issues/152
        # for a similar issue
>       with open(self.filename, 'rb') as fobj:
E       FileNotFoundError: [Errno 2] No such file or directory: 'testdata/test.pdf'

test/libmagic_test.py:40: FileNotFoundError
_________________________________________________________________ MagicTestCase.test_detect_from_filename __________________________________________________________________

self = <test.libmagic_test.MagicTestCase testMethod=test_detect_from_filename>

    def test_detect_from_filename(self):
        result = magic.detect_from_filename(self.filename)
>       self.assert_result(result)

test/libmagic_test.py:23:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
test/libmagic_test.py:17: in assert_result
    self.assertEqual(result.mime_type, self.expected_mime_type)
E   AssertionError: "cannot open `testdata/test.pdf' (No such file or directory)" != 'application/pdf'
E   - cannot open `testdata/test.pdf' (No such file or directory)
E   + application/pdf
___________________________________________________________________ MagicTestCase.test_detect_from_fobj ____________________________________________________________________

self = <test.libmagic_test.MagicTestCase testMethod=test_detect_from_fobj>

    def test_detect_from_fobj(self):

        if SKIP_FROM_DESCRIPTOR:
            self.skipTest("magic_descriptor is broken in this version of libmagic")

>       with open(self.filename) as fobj:
E       FileNotFoundError: [Errno 2] No such file or directory: 'testdata/test.pdf'

test/libmagic_test.py:31: FileNotFoundError
============================================================================= warnings summary =============================================================================
test/libmagic_test.py::MagicTestCase::test_detect_from_filename
  /home/tkloczko/rpmbuild/BUILD/python-magic-0.4.25/magic/__init__.py:437: PendingDeprecationWarning: Using compatibility mode with libmagic's python binding. See https://github.com/ahupp/python-magic/blob/master/COMPAT.md for details.
    warnings.warn(

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
========================================================================= short test summary info ==========================================================================
FAILED test/libmagic_test.py::MagicTestCase::test_detect_from_content - FileNotFoundError: [Errno 2] No such file or directory: 'testdata/test.pdf'
FAILED test/libmagic_test.py::MagicTestCase::test_detect_from_filename - AssertionError: "cannot open `testdata/test.pdf' (No such file or directory)" != 'application/pdf'
FAILED test/libmagic_test.py::MagicTestCase::test_detect_from_fobj - FileNotFoundError: [Errno 2] No such file or directory: 'testdata/test.pdf'
======================================================================= 3 failed, 1 warning in 0.11s =======================================================================

I'm usimg as input sorce tar bal autogenerated by github from git tag https://github.com/ahupp/python-magic/archive/refs/tags/0.4.25.tar.gz. Those units are failing despite fact that I see in source tree that file

[tkloczko@devel-g2v python-magic-0.4.25]$ ls -l test/testdata/test.pdf
-rw-r--r--. 1 tkloczko tkloczko 2048 Feb  3 20:00 test/testdata/test.pdf
ahupp commented 2 years ago

This should be fixed in 7e760728889b3d3928310a453ebe3383adb37984, and I made the test setup use pytest and tox everywhere (51e34d2b8b84f1a582b4dbbfa3693957ddc3f48a, 585373b5d952e579a9f7bd8f6418ca0bfd6a5e35) so hopefully less surprises in the future. Can you test your build against master and if its good I'll release 0.4.26?

kloczek commented 2 years ago

Just tested that commit. pytest is no longer failing (Thank you 👍 😄 ) I see however some warnings 😋

```console + PYTHONPATH=/home/tkloczko/rpmbuild/BUILDROOT/python-magic-0.4.25-2.fc35.x86_64/usr/lib64/python3.8/site-packages:/home/tkloczko/rpmbuild/BUILDROOT/python-magic-0.4.25-2.fc35.x86_64/usr/lib/python3.8/site-packages + /usr/bin/pytest -ra =========================================================================== test session starts ============================================================================ platform linux -- Python 3.8.13, pytest-7.1.2, pluggy-1.0.0 rootdir: /home/tkloczko/rpmbuild/BUILD/python-magic-0.4.25 collected 3 items test/libmagic_test.py ... [100%] ============================================================================= warnings summary ============================================================================= test/libmagic_test.py::MagicTestCase::test_detect_from_content test/libmagic_test.py::MagicTestCase::test_detect_from_filename test/libmagic_test.py::MagicTestCase::test_detect_from_fobj /home/tkloczko/rpmbuild/BUILD/python-magic-0.4.25/magic/__init__.py:437: PendingDeprecationWarning: Using compatibility mode with libmagic's python binding. See https://github.com/ahupp/python-magic/blob/master/COMPAT.md for details. warnings.warn( -- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html ====================================================================== 3 passed, 3 warnings in 0.08s ======================================================================= ```
ahupp commented 2 years ago

Warnings are expected, they are from python-magic to let uses know it's a compatibility layer.

kloczek commented 2 years ago

OK .. we can close this ticket or still is on outstanding list? 🤔

ahupp commented 2 years ago

Ok I've uploaded 0.4.26, closing.