# # Copyright 2015 David R. MacIver # # For details see http://hypothesis.readthedocs.org import os import sys import traceback from hypothesis.settings import set_hypothesis_home_dir import hypothesis.strategies as st from hypothesis import given, Settings # hypothesis store data regarding generate example and code set_hypothesis_home_dir(os.path.join( os.getenv('TESTTMP'), ".hypothesis" )) def check(*args, **kwargs): """decorator to make a function a hypothesis test Decorated function are run immediately (to be used doctest style)""" def accept(f): # Workaround for https://github.com/DRMacIver/hypothesis/issues/206 # Fixed in version 1.13 (released 2015 october 29th) f.__module__ = '__anon__' try: given(*args, settings=Settings(max_examples=2000), **kwargs)(f)() except Exception: traceback.print_exc(file=sys.stdout) sys.exit(1)
# END HEADER from __future__ import division, print_function, absolute_import, \ unicode_literals import gc import warnings from tempfile import mkdtemp import pytest from hypothesis import Settings from hypothesis.settings import set_hypothesis_home_dir warnings.filterwarnings('error', category=UnicodeWarning) set_hypothesis_home_dir(mkdtemp()) Settings.default.max_examples = 1000 Settings.default.max_iterations = 1500 Settings.default.timeout = -1 Settings.default.strict = True try: import resource MAX_MEMORY = 10 resource.setrlimit(resource.RLIMIT_DATA, (MAX_MEMORY, MAX_MEMORY)) except ImportError: pass @pytest.fixture(scope='function', autouse=True)
def test_storage_directories_are_created_automatically(tmpdir): fs.set_hypothesis_home_dir(str(tmpdir)) assert os.path.exists(fs.storage_directory('badgers'))
def test_can_set_homedir_and_it_will_exist(tmpdir): fs.set_hypothesis_home_dir(str(tmpdir.mkdir('kittens'))) d = fs.hypothesis_home_dir() assert 'kittens' in d assert os.path.exists(d)
def teardown_function(function): global previous_home_dir fs.set_hypothesis_home_dir(previous_home_dir) previous_home_dir = None
def setup_function(function): global previous_home_dir previous_home_dir = fs.hypothesis_home_dir() fs.set_hypothesis_home_dir(None)
# Helper module to use the Hypothesis tool in tests # # Copyright 2015 David R. MacIver # # For details see http://hypothesis.readthedocs.org import os import sys import traceback from hypothesis.settings import set_hypothesis_home_dir import hypothesis.strategies as st from hypothesis import given, Settings # hypothesis store data regarding generate example and code set_hypothesis_home_dir(os.path.join(os.getenv('TESTTMP'), ".hypothesis")) def check(*args, **kwargs): """decorator to make a function a hypothesis test Decorated function are run immediately (to be used doctest style)""" def accept(f): # Workaround for https://github.com/DRMacIver/hypothesis/issues/206 # Fixed in version 1.13 (released 2015 october 29th) f.__module__ = '__anon__' try: given(*args, settings=Settings(max_examples=2000), **kwargs)(f)() except Exception: traceback.print_exc(file=sys.stdout) sys.exit(1)