Example #1
0
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()))
Example #2
0
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()))
Example #3
0
settings.define_setting('strict',
                        default=os.getenv('HYPOTHESIS_STRICT_MODE') == 'true',
                        description="""
If set to True, anything that would cause Hypothesis to issue a warning will
instead raise an error. Note that new warnings may be added at any time, so
running with strict set to True means that new Hypothesis releases may validly
break your code.

You can enable this setting temporarily by setting the HYPOTHESIS_STRICT_MODE
environment variable to the string 'true'.
""")

settings.define_setting('database_file',
                        default=lambda:
                        (os.getenv('HYPOTHESIS_DATABASE_FILE') or os.path.join(
                            hypothesis_home_dir(), 'examples')),
                        show_default=False,
                        description="""
    database: An instance of hypothesis.database.ExampleDatabase that will be
used to save examples to and load previous examples from. May be None
in which case no storage will be used.
""")


@unique
class Phase(IntEnum):
    explicit = 0
    reuse = 1
    generate = 2
    shrink = 3
Example #4
0
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.
Example #5
0
You can enable this setting temporarily by setting the HYPOTHESIS_STRICT_MODE
environment variable to the string 'true'.
""",
    deprecation_message="""
Strict mode is deprecated and will go away in a future version of Hypothesis.
To get the same behaviour, use
warnings.simplefilter('error', HypothesisDeprecationWarning).
""",
    future_default=False,
)

settings.define_setting(
    'database_file',
    default=lambda: (
        os.getenv('HYPOTHESIS_DATABASE_FILE') or
        os.path.join(hypothesis_home_dir(), 'examples')
    ),
    show_default=False,
    description="""
    An instance of hypothesis.database.ExampleDatabase that will be
used to save examples to and load previous examples from. May be None
in which case no storage will be used.
"""
)


@unique
class Phase(IntEnum):
    explicit = 0
    reuse = 1
    generate = 2
def test_will_pick_up_location_from_env(tmpdir):
    os.environ[u'HYPOTHESIS_STORAGE_DIRECTORY'] = str(tmpdir)
    assert fs.hypothesis_home_dir() == str(tmpdir)
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 test_homedir_exists_automatically():
    assert os.path.exists(fs.hypothesis_home_dir())
def test_defaults_to_the_default():
    assert fs.hypothesis_home_dir() == fs.__hypothesis_home_directory_default
def test_will_pick_up_location_from_env(tmpdir):
    os.environ[u'HYPOTHESIS_STORAGE_DIRECTORY'] = str(tmpdir)
    assert fs.hypothesis_home_dir() == str(tmpdir)
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 test_homedir_exists_automatically():
    assert os.path.exists(fs.hypothesis_home_dir())
def setup_function(function):
    global previous_home_dir
    previous_home_dir = fs.hypothesis_home_dir()
    fs.set_hypothesis_home_dir(None)
Example #14
0
def test_will_pick_up_location_from_env(monkeypatch, tmpdir):
    tmpdir = str(tmpdir)
    monkeypatch.setattr(os, 'environ', {
        'HYPOTHESIS_STORAGE_DIRECTORY': tmpdir
    })
    assert fs.hypothesis_home_dir() == tmpdir
def test_will_pick_up_location_from_env(monkeypatch, tmpdir):
    tmpdir = str(tmpdir)
    monkeypatch.setattr(os, "environ", {"HYPOTHESIS_STORAGE_DIRECTORY": tmpdir})
    assert fs.hypothesis_home_dir() == tmpdir
Example #16
0
    description="""
If set to True, anything that would cause Hypothesis to issue a warning will
instead raise an error. Note that new warnings may be added at any time, so
running with strict set to True means that new Hypothesis releases may validly
break your code.

You can enable this setting temporarily by setting the HYPOTHESIS_STRICT_MODE
environment variable to the string 'true'.
"""
)

settings.define_setting(
    'database_file',
    default=lambda: (
        os.getenv('HYPOTHESIS_DATABASE_FILE') or
        os.path.join(hypothesis_home_dir(), 'examples')
    ),
    description="""
    database: An instance of hypothesis.database.ExampleDatabase that will be
used to save examples to and load previous examples from. May be None
in which case no storage will be used.
"""
)


@unique
class Phase(IntEnum):
    explicit = 0
    reuse = 1
    generate = 2
    shrink = 3
def setup_function(function):
    global previous_home_dir
    previous_home_dir = fs.hypothesis_home_dir()
    fs.set_hypothesis_home_dir(None)
Example #18
0
def test_defaults_to_the_default():
    assert fs.hypothesis_home_dir() == fs.__hypothesis_home_directory_default