Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zip tests fail on Python 3.13 #1688

Closed
QuLogic opened this issue Sep 23, 2024 · 3 comments · Fixed by #1689
Closed

Zip tests fail on Python 3.13 #1688

QuLogic opened this issue Sep 23, 2024 · 3 comments · Fixed by #1689

Comments

@QuLogic
Copy link
Contributor

QuLogic commented Sep 23, 2024

With Python 3.13, 8 tests in test_zip.py fail:

FAILED fsspec/implementations/tests/test_zip.py::test_find_returns_expected_result_detail_true
FAILED fsspec/implementations/tests/test_zip.py::test_find_returns_expected_result_detail_false
FAILED fsspec/implementations/tests/test_zip.py::test_find_returns_expected_result_detail_true_include_dirs
FAILED fsspec/implementations/tests/test_zip.py::test_find_returns_expected_result_detail_false_include_dirs
FAILED fsspec/implementations/tests/test_zip.py::test_find_returns_expected_result_path_set
FAILED fsspec/implementations/tests/test_zip.py::test_find_with_and_without_slash_should_return_same_result
FAILED fsspec/implementations/tests/test_zip.py::test_find_should_return_file_if_exact_match
FAILED fsspec/implementations/tests/test_zip.py::test_find_returns_expected_result_recursion_depth_set

and they are all similar to:

________________ test_find_returns_expected_result_detail_true _________________
zip_file = PosixPath('/tmp/pytest-of-mockbuild/pytest-0/test_find_returns_expected_res0/test.zip')
    def test_find_returns_expected_result_detail_true(zip_file):
>       zip_file_system = ZipFileSystem(zip_file)
fsspec/implementations/tests/test_zip.py:182: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
fsspec/spec.py:81: in __call__
    obj = super().__call__(*args, **kwargs)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
self = <Archive-like object ZipFileSystem at 139926732063376>
fo = PosixPath('/tmp/pytest-of-mockbuild/pytest-0/test_find_returns_expected_res0/test.zip')
mode = 'r', target_protocol = None, target_options = None, compression = 0
allowZip64 = True, compresslevel = None, kwargs = {}
    def __init__(
        self,
        fo="",
        mode="r",
        target_protocol=None,
        target_options=None,
        compression=zipfile.ZIP_STORED,
        allowZip64=True,
        compresslevel=None,
        **kwargs,
    ):
        """
        Parameters
        ----------
        fo: str or file-like
            Contains ZIP, and must exist. If a str, will fetch file using
            :meth:`~fsspec.open_files`, which must return one file exactly.
        mode: str
            Accept: "r", "w", "a"
        target_protocol: str (optional)
            If ``fo`` is a string, this value can be used to override the
            FS protocol inferred from a URL
        target_options: dict (optional)
            Kwargs passed when instantiating the target FS, if ``fo`` is
            a string.
        compression, allowZip64, compresslevel: passed to ZipFile
            Only relevant when creating a ZIP
        """
        super().__init__(self, **kwargs)
        if mode not in set("rwa"):
            raise ValueError(f"mode '{mode}' no understood")
        self.mode = mode
        if isinstance(fo, str):
            if mode == "a":
                m = "r+b"
            else:
                m = mode + "b"
            fo = fsspec.open(
                fo, mode=m, protocol=target_protocol, **(target_options or {})
            )
        self.force_zip_64 = allowZip64
        self.of = fo
>       self.fo = fo.__enter__()  # the whole instance is a context
E       AttributeError: 'PosixPath' object has no attribute '__enter__'. Did you mean: '__bytes__'?
fsspec/implementations/zip.py:61: AttributeError
@QuLogic
Copy link
Contributor Author

QuLogic commented Sep 23, 2024

I just noticed this warning on Python 3.12:

filesystem_spec/fsspec/implementations/zip.py:61: DeprecationWarning: pathlib.Path.__enter__() is deprecated and scheduled for removal in Python 3.13; Path objects as a context manager is a no-op
    self.fo = fo.__enter__()  # the whole instance is a context

QuLogic added a commit to QuLogic/filesystem_spec that referenced this issue Sep 23, 2024
@martindurant
Copy link
Member

In this location, fo is supposed to be a file-like object, not a path object. I guess the isinstance(path, str) above ought to pick up path objects too.

@martindurant
Copy link
Member

OK, I see #1689 is already waiting

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants