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

test_open_file_for_reading fails on Windows #181

Closed
sobolevnrm opened this issue Dec 28, 2023 · 2 comments · Fixed by #182
Closed

test_open_file_for_reading fails on Windows #181

sobolevnrm opened this issue Dec 28, 2023 · 2 comments · Fixed by #182

Comments

@sobolevnrm
Copy link
Collaborator

sobolevnrm commented Dec 28, 2023

def test_open_file_for_reading__zipfile(tmp_path):

When running pytest with Python 3.12.1 via Powershell on Windows 11 Enterprise, I get the following error:

collected 49 items

tests\test_basic_regression.py .......                                                                                                                                                                    [ 14%]
tests\test_hybrid36.py ..                                                                                                                                                                                 [ 18%]
tests\test_input.py .F                                                                                                                                                                                    [ 22%]
tests\test_lib.py ..                                                                                                                                                                                      [ 26%]
tests\test_molecular_container.py ..                                                                                                                                                                      [ 30%]
tests\test_protonate.py .                                                                                                                                                                                 [ 32%]
tests\test_run.py ........                                                                                                                                                                                [ 48%]
tests\test_streamio.py ........                                                                                                                                                                           [ 65%]
tests\test_vector_algebra.py ...............                                                                                                                                                              [ 95%]
tests\test_version.py ..                                                                                                                                                                                  [100%]

=================================================================================================== FAILURES ===================================================================================================
_____________________________________________________________________________________ test_open_file_for_reading__zipfile ______________________________________________________________________________________

tmp_path = WindowsPath('C:/Users/FOO/AppData/Local/Temp/pytest-of-FOO/pytest-8/test_open_file_for_reading__zi0')

    def test_open_file_for_reading__zipfile(tmp_path):
        zippath = tmp_path / "tmp.zip"
        arcname = "foo/bar.txt"
        with zipfile.ZipFile(zippath, "w") as ziphandle:
            ziphandle.writestr(arcname, "One\nTwo\nThree\n")
>       with m.open_file_for_reading(zippath / arcname) as outer:

tests\test_input.py:27:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
propka\input.py:43: in open_file_for_reading
    stream = zf.open(str(input_file.relative_to(p)))
C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.12_3.12.496.0_x64__qbz5n2kfra8p0\Lib\zipfile\__init__.py:1587: in open
    zinfo = self.getinfo(name)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <zipfile.ZipFile filename='C:\\Users\\FOO\\AppData\\Local\\Temp\\pytest-of-FOO\\pytest-8\\test_open_file_for_reading__zi0\\tmp.zip' mode='r'>, name = 'foo\\bar.txt'

    def getinfo(self, name):
        """Return the instance of ZipInfo given 'name'."""
        info = self.NameToInfo.get(name)
        if info is None:
>           raise KeyError(
                'There is no item named %r in the archive' % name)
E           KeyError: "There is no item named 'foo\\\\bar.txt' in the archive"

C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.12_3.12.496.0_x64__qbz5n2kfra8p0\Lib\zipfile\__init__.py:1516: KeyError
=========================================================================================== short test summary info ============================================================================================
FAILED tests/test_input.py::test_open_file_for_reading__zipfile - KeyError: "There is no item named 'foo\\\\bar.txt' in the archive"
========================================================================================= 1 failed, 48 passed in 7.61s =========================================================================================

@sobolevnrm
Copy link
Collaborator Author

@speleo3 FYI.

@sobolevnrm
Copy link
Collaborator Author

sobolevnrm commented Dec 28, 2023

Looking at

stream = zf.open(str(input_file.relative_to(p)))

On Windows, the path encoded by str(input_file.relative_to(p)) is "foo\bar.txt" but should be "foo/bar.txt".

This is a problem because Path-like syntax is used both in the failing test and in other parts of the code; e.g., https://github.com/jensengroup/propka/blob/5a00d059b2c29dc514dd77ee4e214c2029f6f260/propka/bonds.py#L56C1-L56C1 .

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.

1 participant