From 186b99eef9beb2269eade9f35b13ab11b91ccfba Mon Sep 17 00:00:00 2001 From: Zane Selvans Date: Tue, 6 Oct 2020 19:26:34 -0500 Subject: [PATCH] Additional OS-specific path ZipFile path tests --- setup.py | 9 ++++----- tests/test_dbf.py | 30 +++++++++++++++++++++++------- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/setup.py b/setup.py index 3b4d0c7..8c073e1 100755 --- a/setup.py +++ b/setup.py @@ -1,6 +1,4 @@ #!/usr/bin/env python -import os -import sys from pathlib import Path from setuptools import find_packages, setup @@ -9,6 +7,7 @@ "coverage", "pytest", "pytest-cov", + "zipp", ] doc_requires = [ @@ -32,19 +31,19 @@ maintainer_email="zane.selvans@catalyst.coop", project_urls={ "Source": "https://github.com/catalyst-cooperative/dbfread", -# "Documentation": "https://catalystcoop-dbfread.readthedocs.io", + # "Documentation": "https://catalystcoop-dbfread.readthedocs.io", "Issue Tracker": "https://github.com/catalyst-cooperative/dbfread/issues", }, package_data={"": ["LICENSE"]}, package_dir={"": "src"}, - packages = find_packages("src"), + packages=find_packages("src"), include_package_data=True, zip_safe=True, install_requires=[], extras_require={ "doc": doc_requires, "test": test_requires, - }, + }, scripts=["examples/dbf2sqlite"], python_requires=">=3.6", license="MIT", diff --git a/tests/test_dbf.py b/tests/test_dbf.py index c3e44f5..00ef498 100644 --- a/tests/test_dbf.py +++ b/tests/test_dbf.py @@ -1,12 +1,13 @@ # -*- coding: utf-8 -*- import os -from pathlib import Path, PosixPath +from pathlib import Path from zipfile import ZipFile from dbfread import DBF from dbfread.memo import VFPMemoFile import pytest +import zipp TESTCASE_PATH = Path(__file__).parent.parent / "testcases" @@ -60,8 +61,8 @@ def test_file_object_open(self): self.check_alice_bob(dataset[0], dataset[1]) @pytest.mark.xfail(os.name != "posix", reason="ZipFiles use POSIX paths.") - def test_zipfile_path_open(self): - """Make sure we can open by passing OS specific zipfile paths.""" + def test_zipfile_strpath_open(self): + """Attempt to open OS specific zipfile paths.""" zf = ZipFile(TESTCASE_PATH / "testcases.zip") memotest_path_str = str(Path("testcases/memotest.dbf")) memomemo_path_str = str(Path("testcases/memotest.FPT")) @@ -75,11 +76,11 @@ def test_zipfile_path_open(self): dataset = list(data) self.check_alice_bob(dataset[0], dataset[1]) - def test_zipfile_posixpath_open(self): - """Make sure we can open by passing POSIX zipfile paths.""" + def test_zipfile_dumbpath_open(self): + """Attempt to open hard-coded POSIX paths ("/" as path separator).""" zf = ZipFile(TESTCASE_PATH / "testcases.zip") - memotest_path_str = str(PosixPath("testcases/memotest.dbf")) - memomemo_path_str = str(PosixPath("testcases/memotest.FPT")) + memotest_path_str = "testcases/memotest.dbf" + memomemo_path_str = "testcases/memotest.FPT" with zf.open(memotest_path_str) as mt: with zf.open(memomemo_path_str) as mm: @@ -89,3 +90,18 @@ def test_zipfile_posixpath_open(self): dataset = list(data) self.check_alice_bob(dataset[0], dataset[1]) + + def test_zipfile_zippath_open(self): + """Attempt to open POSIX only zipfile paths.""" + zf = ZipFile(TESTCASE_PATH / "testcases.zip") + memotest_path = zipp.Path(zf, at="testcases/memotest.dbf") + memomemo_path = zipp.Path(zf, at="testcases/memotest.FPT") + + with memotest_path.open("rb") as mt: + with memomemo_path.open("rb") as mm: + data = DBF("memotest", filedata=mt, memofile=VFPMemoFile(mm.read())) + + assert data.__class__ is DBF + + dataset = list(data) + self.check_alice_bob(dataset[0], dataset[1])