def set_up_hypothesis() -> None: default_settings = settings( # Turn off the health checks because setUp/tearDown are too slow suppress_health_check=[HealthCheck.too_slow], # Turn off the example database; we don't have a way to persist this # or share this across runs, so we don't derive any benefit from it at # this time. database=None, ) # Configure Hypothesis to run faster when iterating locally settings.register_profile( "dev", settings(default_settings, max_examples=5, timeout=0) ) # ... and use the defaults (which have more combinations) when running # on CI, which we want to be more deterministic. settings.register_profile( "ci", settings(default_settings, derandomize=True, timeout=120) ) # Use the dev profile by default, but use the ci profile on sandcastle. settings.load_profile( "ci" if is_sandcastle() else os.getenv("HYPOTHESIS_PROFILE", "dev") ) # We need to set a global (but non-conflicting) path to store some state # during hypothesis example runs. We want to avoid putting this state in # the repo. set_hypothesis_home_dir(tempfile.mkdtemp(prefix="eden_hypothesis.")) atexit.register(cleanup_tmp_dir, pathlib.Path(hypothesis_home_dir()))
def run(): filterwarnings('error') filterwarnings('ignore', category=ImportWarning) filterwarnings('ignore', category=FutureWarning, module='pandas._version') # Fixed in recent versions but allowed by pytest=3.0.0; see #1630 filterwarnings('ignore', category=DeprecationWarning, module='pluggy') # See https://github.com/numpy/numpy/pull/432 filterwarnings('ignore', message='numpy.dtype size changed') filterwarnings('ignore', message='numpy.ufunc size changed') # Imported by Pandas in version 1.9, but fixed in later versions. filterwarnings( 'ignore', message='Importing from numpy.testing.decorators is deprecated') filterwarnings( 'ignore', message='Importing from numpy.testing.nosetester is deprecated') new_home = mkdtemp() set_hypothesis_home_dir(new_home) assert settings.default.database.path.startswith(new_home) charmap() assert os.path.exists(charmap_file()), charmap_file() assert isinstance(settings, type) # We do a smoke test here before we mess around with settings. x = settings() import hypothesis._settings as settings_module for s in settings_module.all_settings.values(): v = getattr(x, s.name) # Check if it has a dynamically defined default and if so skip # comparison. if getattr(settings, s.name).show_default: assert v == s.default, '%r == x.%s != s.%s == %r' % ( v, s.name, s.name, s.default, ) settings.register_profile( 'default', settings( max_examples=10 if IN_COVERAGE_TESTS else not_set, timeout=unlimited, )) settings.register_profile('speedy', settings(max_examples=5, )) settings.register_profile('debug', settings(verbosity=Verbosity.debug)) settings.load_profile(os.getenv('HYPOTHESIS_PROFILE', 'default'))
def run(): filterwarnings('error') filterwarnings('ignore', category=ImportWarning) filterwarnings('ignore', category=FutureWarning, module='pandas._version') # Fixed in recent versions but allowed by pytest=3.0.0; see #1630 filterwarnings('ignore', category=DeprecationWarning, module='pluggy') # See https://github.com/numpy/numpy/pull/432 filterwarnings('ignore', message='numpy.dtype size changed') filterwarnings('ignore', message='numpy.ufunc size changed') # Imported by Pandas in version 1.9, but fixed in later versions. filterwarnings( 'ignore', message='Importing from numpy.testing.decorators is deprecated' ) filterwarnings( 'ignore', message='Importing from numpy.testing.nosetester is deprecated' ) new_home = mkdtemp() set_hypothesis_home_dir(new_home) assert settings.default.database.path.startswith(new_home) charmap() assert os.path.exists(charmap_file()), charmap_file() assert isinstance(settings, type) # We do a smoke test here before we mess around with settings. x = settings() import hypothesis._settings as settings_module for s in settings_module.all_settings.values(): v = getattr(x, s.name) # Check if it has a dynamically defined default and if so skip # comparison. if getattr(settings, s.name).show_default: assert v == s.default, '%r == x.%s != s.%s == %r' % ( v, s.name, s.name, s.default, ) settings.register_profile('default', settings( max_examples=10 if IN_COVERAGE_TESTS else not_set, timeout=unlimited, )) settings.register_profile( 'speedy', settings( max_examples=5, )) settings.register_profile('debug', settings(verbosity=Verbosity.debug)) settings.load_profile(os.getenv('HYPOTHESIS_PROFILE', 'default'))
def run(): filterwarnings('error') filterwarnings('ignore', category=ImportWarning) filterwarnings('ignore', category=FutureWarning, module='pandas._version') # Only applies to Django 1.8, so this filter will go very soon! filterwarnings('ignore', category=DeprecationWarning, module='tests.django.toystore.models') set_hypothesis_home_dir(mkdtemp()) charmap() assert os.path.exists(charmap_file()), charmap_file() assert isinstance(settings, type) # We do a smoke test here before we mess around with settings. x = settings() import hypothesis._settings as settings_module for s in settings_module.all_settings.values(): v = getattr(x, s.name) # Check if it has a dynamically defined default and if so skip # comparison. if getattr(settings, s.name).show_default: assert v == s.default, '%r == x.%s != s.%s == %r' % ( v, s.name, s.name, s.default, ) settings.register_profile( 'default', settings(timeout=unlimited, use_coverage=not IN_COVERAGE_TESTS)) settings.register_profile('with_coverage', settings( timeout=unlimited, use_coverage=True, )) settings.register_profile('speedy', settings(max_examples=5, )) settings.load_profile(os.getenv('HYPOTHESIS_PROFILE', 'default'))
def run(): filterwarnings('error') filterwarnings('ignore', category=ImportWarning) filterwarnings('ignore', category=FutureWarning, module='pandas._version') # See https://github.com/numpy/numpy/pull/432 filterwarnings('ignore', message='numpy.dtype size changed') filterwarnings('ignore', message='numpy.ufunc size changed') new_home = mkdtemp() set_hypothesis_home_dir(new_home) assert settings.default.database.path.startswith(new_home) charmap() assert os.path.exists(charmap_file()), charmap_file() assert isinstance(settings, type) # We do a smoke test here before we mess around with settings. x = settings() import hypothesis._settings as settings_module for s in settings_module.all_settings.values(): v = getattr(x, s.name) # Check if it has a dynamically defined default and if so skip # comparison. if getattr(settings, s.name).show_default: assert v == s.default, '%r == x.%s != s.%s == %r' % ( v, s.name, s.name, s.default, ) settings.register_profile('default', settings( timeout=unlimited, use_coverage=not IN_COVERAGE_TESTS)) settings.register_profile('with_coverage', settings( timeout=unlimited, use_coverage=True, )) settings.register_profile( 'speedy', settings( max_examples=5, )) settings.load_profile(os.getenv('HYPOTHESIS_PROFILE', 'default'))
def run(): warnings.filterwarnings(u'error', category=UnicodeWarning) set_hypothesis_home_dir(mkdtemp()) charmap() assert os.path.exists(charmap_file()) assert isinstance(settings, type) settings.register_profile('default', settings(timeout=-1, strict=True)) settings.register_profile('speedy', settings( timeout=1, max_examples=5, )) settings.register_profile('nonstrict', settings(strict=False)) settings.load_profile(os.getenv('HYPOTHESIS_PROFILE', 'default'))
def run(deprecations_as_errors=True): warnings.filterwarnings('error', category=UnicodeWarning) # This catches deprecations in our dependencies, as well as internally # (because HypothesisDeprecationWarning subclasses DeprecationWarning) if deprecations_as_errors: # disabled for old versions of Django warnings.filterwarnings('error', category=DeprecationWarning) set_hypothesis_home_dir(mkdtemp()) charmap() assert os.path.exists(charmap_file()), charmap_file() assert isinstance(settings, type) # We do a smoke test here before we mess around with settings. x = settings() import hypothesis._settings as settings_module for s in settings_module.all_settings.values(): v = getattr(x, s.name) # Check if it has a dynamically defined default and if so skip # comparison. if getattr(settings, s.name).show_default: assert v == s.default, '%r == x.%s != s.%s == %r' % ( v, s.name, s.name, s.default, ) settings.register_profile( 'default', settings(timeout=unlimited, use_coverage=not IN_COVERAGE_TESTS)) settings.register_profile('with_coverage', settings( timeout=unlimited, use_coverage=True, )) settings.register_profile('speedy', settings(max_examples=5, )) settings.load_profile(os.getenv('HYPOTHESIS_PROFILE', 'default'))
def run(): warnings.filterwarnings(u'error', category=UnicodeWarning) set_hypothesis_home_dir(mkdtemp()) charmap() assert os.path.exists(charmap_file()) assert isinstance(settings, type) settings.register_profile( 'default', settings(timeout=-1, strict=True) ) settings.register_profile( 'speedy', settings( timeout=1, max_examples=5, )) settings.register_profile( 'nonstrict', settings(strict=False) ) settings.load_profile(os.getenv('HYPOTHESIS_PROFILE', 'default'))
def run(): warnings.filterwarnings('error', category=UnicodeWarning) warnings.filterwarnings('error', category=HypothesisDeprecationWarning) set_hypothesis_home_dir(mkdtemp()) charmap() assert os.path.exists(charmap_file()), charmap_file() assert isinstance(settings, type) # We do a smoke test here before we mess around with settings. x = settings() import hypothesis._settings as settings_module for s in settings_module.all_settings.values(): v = getattr(x, s.name) # Check if it has a dynamically defined default and if so skip # comparison. if getattr(settings, s.name).show_default: assert v == s.default, '%r == x.%s != s.%s == %r' % ( v, s.name, s.name, s.default, ) settings.register_profile('default', settings( timeout=unlimited, use_coverage=not (IN_COVERAGE_TESTS or PYPY))) settings.register_profile('with_coverage', settings( timeout=unlimited, use_coverage=True, )) settings.register_profile( 'speedy', settings( max_examples=5, )) settings.load_profile(os.getenv('HYPOTHESIS_PROFILE', 'default'))
def test_can_set_homedir_and_it_will_exist(tmpdir): fs.set_hypothesis_home_dir(str(tmpdir.mkdir(u'kittens'))) d = fs.hypothesis_home_dir() assert u'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)
import inspect import os import sys import warnings from tempfile import mkdtemp import unicodenazi from hypothesis.configuration import set_hypothesis_home_dir from hypothesis.errors import HypothesisDeprecationWarning warnings.filterwarnings("error", category=UnicodeWarning) warnings.filterwarnings("error", category=HypothesisDeprecationWarning) unicodenazi.enable() set_hypothesis_home_dir(mkdtemp()) TESTS = ["test_testdecorators"] sys.path.append(os.path.join("tests", "cover")) def main(): for t in TESTS: module = __import__(t) for k, v in sorted(module.__dict__.items(), key=lambda x: x[0]): if k.startswith("test_") and inspect.isfunction(v): print(k) v()
def test_storage_directories_are_created_automatically(tmpdir): fs.set_hypothesis_home_dir(str(tmpdir)) assert os.path.exists(fs.storage_directory(u'badgers'))
import traceback try: # hypothesis 2.x from hypothesis.configuration import set_hypothesis_home_dir from hypothesis import settings except ImportError: # hypothesis 1.x from hypothesis.settings import set_hypothesis_home_dir from hypothesis import Settings as settings import hypothesis.strategies as st from hypothesis import given # 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: with settings(max_examples=2000): given(*args, **kwargs)(f)() except Exception: traceback.print_exc(file=sys.stdout)
import subprocess from hypothesis.errors import HypothesisException from hypothesis.stateful import ( rule, RuleBasedStateMachine, Bundle, precondition) from hypothesis import settings, note, strategies as st from hypothesis.configuration import set_hypothesis_home_dir from hypothesis.database import ExampleDatabase testdir = os.path.abspath(os.environ["TESTDIR"]) # We store Hypothesis examples here rather in the temporary test directory # so that when rerunning a failing test this always results in refinding the # previous failure. This directory is in .hgignore and should not be checked in # but is useful to have for development. set_hypothesis_home_dir(os.path.join(testdir, ".hypothesis")) runtests = os.path.join(os.environ["RUNTESTDIR"], "run-tests.py") testtmp = os.environ["TESTTMP"] assert os.path.isdir(testtmp) generatedtests = os.path.join(testdir, "hypothesis-generated") try: os.makedirs(generatedtests) except OSError: pass # We write out generated .t files to a file in order to ease debugging and to # give a starting point for turning failures Hypothesis finds into normal # tests. In order to ensure that multiple copies of this test can be run in
import sys import traceback try: # hypothesis 2.x from hypothesis.configuration import set_hypothesis_home_dir from hypothesis import settings except ImportError: # hypothesis 1.x from hypothesis.settings import set_hypothesis_home_dir from hypothesis import Settings as settings import hypothesis.strategies as st from hypothesis import given # 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: with settings(max_examples=2000): given(*args, **kwargs)(f)() except Exception: traceback.print_exc(file=sys.stdout)
def test_can_set_homedir_and_it_will_exist(tmpdir): fs.set_hypothesis_home_dir(str(tmpdir.mkdir("kittens"))) d = fs.storage_directory() assert "kittens" in d assert os.path.exists(d)
def run(): filterwarnings("error") filterwarnings("ignore", category=ImportWarning) filterwarnings("ignore", category=FutureWarning, module="pandas._version") # Fixed in recent versions but allowed by pytest=3.0.0; see #1630 filterwarnings("ignore", category=DeprecationWarning, module="pluggy") # See https://github.com/numpy/numpy/pull/432 filterwarnings("ignore", message="numpy.dtype size changed") filterwarnings("ignore", message="numpy.ufunc size changed") # See https://github.com/HypothesisWorks/hypothesis/issues/1674 filterwarnings( "ignore", message=( "The virtualenv distutils package at .+ appears to be in the " "same location as the system distutils?" ), category=UserWarning, ) # Imported by Pandas in version 1.9, but fixed in later versions. filterwarnings( "ignore", message="Importing from numpy.testing.decorators is deprecated" ) filterwarnings( "ignore", message="Importing from numpy.testing.nosetester is deprecated" ) new_home = mkdtemp() set_hypothesis_home_dir(new_home) assert settings.default.database.path.startswith(new_home) charmap() assert os.path.exists(charmap_file()), charmap_file() assert isinstance(settings, type) # We do a smoke test here before we mess around with settings. x = settings() import hypothesis._settings as settings_module for s in settings_module.all_settings.values(): v = getattr(x, s.name) # Check if it has a dynamically defined default and if so skip # comparison. if getattr(settings, s.name).show_default: assert v == s.default, "%r == x.%s != s.%s == %r" % ( v, s.name, s.name, s.default, ) settings.register_profile( "default", settings(max_examples=10 if IN_COVERAGE_TESTS else not_set) ) settings.register_profile("speedy", settings(max_examples=5)) settings.register_profile("debug", settings(verbosity=Verbosity.debug)) settings.load_profile(os.getenv("HYPOTHESIS_PROFILE", "default"))
# # END HEADER from __future__ import division, print_function, absolute_import import warnings from tempfile import mkdtemp import unicodenazi warnings.filterwarnings('error', category=UnicodeWarning) unicodenazi.enable() from hypothesis import settings from hypothesis.configuration import set_hypothesis_home_dir set_hypothesis_home_dir(mkdtemp()) assert isinstance(settings, type) settings.register_profile( 'default', settings(timeout=-1, strict=True) ) settings.load_profile('default') import inspect import os TESTS = [ 'test_testdecorators', ]
# Use the dev profile by default, but use the ci profile on sandcastle. settings.load_profile( 'ci' if is_sandcastle() else os.getenv('HYPOTHESIS_PROFILE', 'dev')) # Some helpers for Hypothesis decorators FILENAME_STRATEGY = st.text(st.characters( min_codepoint=1, max_codepoint=1000, blacklist_characters="/:\\", ), min_size=1) # We need to set a global (but non-conflicting) path to store some state # during hypothesis example runs. We want to avoid putting this state in # the repo. set_hypothesis_home_dir(tempfile.mkdtemp(prefix='eden_hypothesis.')) atexit.register(shutil.rmtree, hypothesis_home_dir()) if is_sandcastle() and not edenclient.can_run_eden(): # This is avoiding a reporting noise issue in our CI that files # tasks about skipped tests. Let's just skip defining most of them # to avoid the noise if we know that they won't work anyway. TestParent = object else: TestParent = unittest.TestCase @unittest.skipIf(not edenclient.can_run_eden(), "unable to run edenfs") class EdenTestCase(TestParent): ''' Base class for eden integration test cases.
def run(): filterwarnings("error") filterwarnings("ignore", category=ImportWarning) filterwarnings("ignore", category=FutureWarning, module="pandas._version") # Fixed in recent versions but allowed by pytest=3.0.0; see #1630 filterwarnings("ignore", category=DeprecationWarning, module="pluggy") # See https://github.com/numpy/numpy/pull/432 filterwarnings("ignore", message="numpy.dtype size changed") filterwarnings("ignore", message="numpy.ufunc size changed") # See https://github.com/HypothesisWorks/hypothesis/issues/1674 filterwarnings( "ignore", message=( "The virtualenv distutils package at .+ appears to be in the " "same location as the system distutils?" ), category=UserWarning, ) # Imported by Pandas in version 1.9, but fixed in later versions. filterwarnings( "ignore", message="Importing from numpy.testing.decorators is deprecated" ) filterwarnings( "ignore", message="Importing from numpy.testing.nosetester is deprecated" ) # User-facing warning which does not apply to our own tests filterwarnings("ignore", category=NonInteractiveExampleWarning) new_home = mkdtemp() set_hypothesis_home_dir(new_home) assert settings.default.database.path.startswith(new_home) # Remove the cache because we might have saved this before setting the new home dir charmap._charmap = None charmap.charmap() assert os.path.exists(charmap.charmap_file()), charmap.charmap_file() assert isinstance(settings, type) # We do a smoke test here before we mess around with settings. x = settings() from hypothesis import _settings as settings_module for s in settings_module.all_settings.values(): v = getattr(x, s.name) # Check if it has a dynamically defined default and if so skip comparison. if getattr(settings, s.name).show_default: assert v == s.default, "({!r} == x.{}) != (s.{} == {!r})".format( v, s.name, s.name, s.default ) settings.register_profile( "default", settings(max_examples=20 if IN_COVERAGE_TESTS else not_set) ) settings.register_profile("speedy", settings(max_examples=5)) settings.register_profile("debug", settings(verbosity=Verbosity.debug)) settings.load_profile(os.getenv("HYPOTHESIS_PROFILE", "default"))
import subprocess from hypothesis.errors import HypothesisException from hypothesis.stateful import (rule, RuleBasedStateMachine, Bundle, precondition) from hypothesis import settings, note, strategies as st from hypothesis.configuration import set_hypothesis_home_dir from hypothesis.database import ExampleDatabase testdir = os.path.abspath(os.environ["TESTDIR"]) # We store Hypothesis examples here rather in the temporary test directory # so that when rerunning a failing test this always results in refinding the # previous failure. This directory is in .hgignore and should not be checked in # but is useful to have for development. set_hypothesis_home_dir(os.path.join(testdir, ".hypothesis")) runtests = os.path.join(os.environ["RUNTESTDIR"], "run-tests.py") testtmp = os.environ["TESTTMP"] assert os.path.isdir(testtmp) generatedtests = os.path.join(testdir, "hypothesis-generated") try: os.makedirs(generatedtests) except OSError: pass # We write out generated .t files to a file in order to ease debugging and to # give a starting point for turning failures Hypothesis finds into normal # tests. In order to ensure that multiple copies of this test can be run in
from profiles.factory import create_app from profiles.models import Date, Name, OrcidToken, Profile, db from profiles.orcid import OrcidClient from profiles.repositories import SQLAlchemyOrcidTokens, SQLAlchemyProfiles from profiles.utilities import expires_at BUILD_PATH = os.path.dirname(os.path.dirname( os.path.realpath(__file__))) + '/build/' TEST_DATABASE_NAME = 'test.db' TEST_DATABASE_PATH = BUILD_PATH + TEST_DATABASE_NAME TEST_DATABASE_URI = 'sqlite:///' + TEST_DATABASE_PATH logging.disable(logging.CRITICAL) set_hypothesis_home_dir(BUILD_PATH + 'hypothesis/home') hyp_settings.register_profile( 'default', hyp_settings(database_file=BUILD_PATH + 'hypothesis/db')) hyp_settings.load_profile('default') @fixture(scope='session') def app(request: FixtureRequest) -> Flask: app = create_app( DevConfig( orcid={ 'api_uri': 'http://www.example.com/api', 'authorize_uri': 'http://www.example.com/oauth/authorize', 'token_uri': 'http://www.example.com/oauth/token', 'client_id': 'server_client_id', 'client_secret': 'server_client_secret',