jensengroup / propka

PROPKA predicts the pKa values of ionizable groups in proteins and protein-ligand complexes based in the 3D structure.
http://propka.org
GNU Lesser General Public License v2.1
256 stars 58 forks source link

test_open_file_for_reading fails on Windows #181

Closed sobolevnrm closed 8 months ago

sobolevnrm commented 8 months ago

https://github.com/jensengroup/propka/blob/5a00d059b2c29dc514dd77ee4e214c2029f6f260/tests/test_input.py#L22

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 commented 8 months ago

@speleo3 FYI.

sobolevnrm commented 8 months ago

Looking at https://github.com/jensengroup/propka/blob/5a00d059b2c29dc514dd77ee4e214c2029f6f260/propka/input.py#L43

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 .