Skip to content

Commit

Permalink
Merge pull request #16 from pauldmccarthy/test/windows
Browse files Browse the repository at this point in the history
TST: Try and avoid file errors on windows
  • Loading branch information
pauldmccarthy authored Nov 22, 2018
2 parents 3180f90 + 3861815 commit 16554e6
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions indexed_gzip/tests/ctest_indexed_gzip.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import tempfile
import shutil
import hashlib
import textwrap
import contextlib

import numpy as np

Expand All @@ -35,19 +34,6 @@ from libc.stdio cimport (SEEK_SET,
SEEK_END)


@contextlib.contextmanager
def tempdir():
testdir = tempfile.mkdtemp()
prevdir = os.getcwd()
try:
os.chdir(testdir)
yield testdir

finally:
shutil.rmtree(testdir)
os.chdir(prevdir)


def read_element(gzf, element, seek=True):

if seek:
Expand Down Expand Up @@ -689,22 +675,31 @@ def test_size_multiple_of_readbuf():

fname = 'test.gz'

with tempdir():
testdir = tempfile.mkdtemp()
prevdir = os.getcwd()
os.chdir(testdir)

try:
data = np.random.randint(1, 1000, 10000, dtype=np.uint32)

with gzip.open(fname, 'wb') as f:
f.write(data.tobytes())
del f
f = None

fsize = op.getsize(fname)
bufsz = fsize

with igzip.IndexedGzipFile(fname, readbuf_size=bufsz) as f:
assert f.seek(fsize) == fsize
del f
f = None

with igzip.IndexedGzipFile(fname, readbuf_size=bufsz) as f:
read = np.ndarray(shape=10000, dtype=np.uint32, buffer=f.read())
assert np.all(read == data)
del f
f = None

# we're screwed if the
# file size is prime
Expand All @@ -716,7 +711,14 @@ def test_size_multiple_of_readbuf():

with igzip.IndexedGzipFile(fname, readbuf_size=bufsz) as f:
assert f.seek(fsize) == fsize
del f
f = None

with igzip.IndexedGzipFile(fname, readbuf_size=bufsz) as f:
read = np.ndarray(shape=10000, dtype=np.uint32, buffer=f.read())
assert np.all(read == data)
del f
f = None
finally:
os.chdir(prevdir)
shutil.rmtree(testdir)

0 comments on commit 16554e6

Please sign in to comment.