Skip to content

Commit

Permalink
Additional OS-specific path ZipFile path tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zaneselvans committed Oct 7, 2020
1 parent 59c638d commit 186b99e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
9 changes: 4 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#!/usr/bin/env python
import os
import sys
from pathlib import Path

from setuptools import find_packages, setup
Expand All @@ -9,6 +7,7 @@
"coverage",
"pytest",
"pytest-cov",
"zipp",
]

doc_requires = [
Expand All @@ -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",
Expand Down
30 changes: 23 additions & 7 deletions tests/test_dbf.py
Original file line number Diff line number Diff line change
@@ -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"

Expand Down Expand Up @@ -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"))
Expand All @@ -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:
Expand All @@ -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])

0 comments on commit 186b99e

Please sign in to comment.