Skip to content

Commit

Permalink
Make test_file.py pytest friendly
Browse files Browse the repository at this point in the history
  • Loading branch information
Peque committed Jan 6, 2017
1 parent 54533cd commit 1e1fb2c
Showing 1 changed file with 35 additions and 14 deletions.
49 changes: 35 additions & 14 deletions tests/test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@
# License: 3-clause BSD. The full license text is available at:
# - http://trac.mystic.cacr.caltech.edu/project/pathos/browser/dill/LICENSE

import dill
import random
import os
import sys
import string
import random

import pytest

import dill


dill.settings['recurse'] = True

fname = "_test_file.txt"
Expand All @@ -21,6 +26,7 @@
buffer_error = ValueError("invalid buffer size")
dne_error = FileNotFoundError("[Errno 2] No such file or directory: '%s'" % fname)


def write_randomness(number=200):
f = open(fname, "w")
for i in range(number):
Expand All @@ -45,7 +51,16 @@ def throws(op, args, exc):
return False


def test(strictio, fmode):
def teardown_module():
if os.path.exists(fname):
os.remove(fname)


def bench(strictio, fmode, skippypy):
import platform
if skippypy and platform.python_implementation() == 'PyPy':
pytest.skip('Skip for PyPy...')

# file exists, with same contents
# read

Expand Down Expand Up @@ -462,18 +477,24 @@ def test(strictio, fmode):
f2.close()


if __name__ == '__main__':
def test_nostrictio_handlefmode():
bench(False, dill.HANDLE_FMODE, False)

test(strictio=False, fmode=dill.HANDLE_FMODE)
test(strictio=False, fmode=dill.FILE_FMODE)
if not dill.dill.IS_PYPY: #FIXME: fails due to pypy/issues/1233
test(strictio=False, fmode=dill.CONTENTS_FMODE)

#test(strictio=True, fmode=dill.HANDLE_FMODE)
#test(strictio=True, fmode=dill.FILE_FMODE)
#test(strictio=True, fmode=dill.CONTENTS_FMODE)
def test_nostrictio_filefmode():
bench(False, dill.FILE_FMODE, False)

if os.path.exists(fname):
os.remove(fname)

# EOF
def test_nostrictio_contentsfmode():
bench(False, dill.CONTENTS_FMODE, True)


#bench(True, dill.HANDLE_FMODE, False)
#bench(True, dill.FILE_FMODE, False)
#bench(True, dill.CONTENTS_FMODE, True)


if __name__ == '__main__':
test_nostrictio_handlefmode()
test_nostrictio_filefmode()
test_nostrictio_contentsfmode()

0 comments on commit 1e1fb2c

Please sign in to comment.