示例#1
0
def test_can_handle_race_between_exist_and_create(monkeypatch):
    x = cm.charmap()
    cm._charmap = None
    monkeypatch.setattr(os.path, "exists", lambda p: False)
    y = cm.charmap()
    assert x is not y
    assert x == y
示例#2
0
def test_can_handle_race_between_exist_and_create(monkeypatch):
    x = cm.charmap()
    cm._charmap = None
    monkeypatch.setattr(os.path, 'exists', lambda p: False)
    y = cm.charmap()
    assert x is not y
    assert x == y
示例#3
0
def test_reload_charmap():
    x = cm.charmap()
    assert x is cm.charmap()
    cm._charmap = None
    y = cm.charmap()
    assert x is not y
    assert x == y
示例#4
0
def run():
    warnings.filterwarnings('error', category=UnicodeWarning)
    warnings.filterwarnings('error', category=HypothesisDeprecationWarning)

    set_hypothesis_home_dir(mkdtemp())

    charmap()
    assert os.path.exists(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))

    settings.register_profile('speedy', settings(max_examples=5, ))

    settings.load_profile(os.getenv('HYPOTHESIS_PROFILE', 'default'))
示例#5
0
def test_reload_charmap():
    x = cm.charmap()
    assert x is cm.charmap()
    cm._charmap = None
    y = cm.charmap()
    assert x is not y
    assert x == y
示例#6
0
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')

    # 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,
                 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.register_profile('debug', settings(verbosity=Verbosity.debug))

    settings.load_profile(os.getenv('HYPOTHESIS_PROFILE', 'default'))
示例#7
0
def test_recreate_charmap():
    x = cm.charmap()
    assert x is cm.charmap()
    cm._charmap = None
    os.unlink(cm.charmap_file())
    y = cm.charmap()
    assert x is not y
    assert x == y
示例#8
0
def test_recreate_charmap():
    x = cm.charmap()
    assert x is cm.charmap()
    cm._charmap = None
    os.unlink(cm.charmap_file())
    y = cm.charmap()
    assert x is not y
    assert x == y
示例#9
0
def test_regenerate_broken_charmap_file():
    cm.charmap()
    file_loc = cm.charmap_file()

    with open(file_loc, 'wb'):
        pass

    cm._charmap = None
    cm.charmap()
示例#10
0
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'))
示例#11
0
def test_regenerate_broken_charmap_file():
    cm.charmap()
    file_loc = cm.charmap_file()

    with open(file_loc, "wb"):
        pass

    cm._charmap = None
    cm.charmap()
示例#12
0
def test_exception_in_write_does_not_lead_to_broken_charmap(monkeypatch):
    def broken(*args, **kwargs):
        raise ValueError()

    cm._charmap = None
    monkeypatch.setattr(os.path, 'exists', lambda p: False)
    monkeypatch.setattr(os, 'rename', broken)

    cm.charmap()
    cm.charmap()
示例#13
0
def test_exception_in_write_does_not_lead_to_broken_charmap(monkeypatch):
    def broken(*args, **kwargs):
        raise ValueError()

    cm._charmap = None
    monkeypatch.setattr(os.path, "exists", lambda p: False)
    monkeypatch.setattr(os, "rename", broken)

    cm.charmap()
    cm.charmap()
示例#14
0
def test_exception_in_write_does_not_lead_to_broken_charmap(monkeypatch):
    def broken(*args, **kwargs):
        raise ValueError()

    cm._charmap = None
    monkeypatch.setattr(os.path, 'exists', lambda p: False)
    monkeypatch.setattr(os, 'rename', broken)
    with pytest.raises(ValueError):
        cm.charmap()

    with pytest.raises(ValueError):
        cm.charmap()
示例#15
0
def test_uses_cached_charmap():
    cm.charmap()

    # Reset the last-modified time of the cache file to a point in the past.
    mtime = int(time.time() - 1000)
    os.utime(cm.charmap_file(), (mtime, mtime))
    statinfo = os.stat(cm.charmap_file())
    assert statinfo.st_mtime == mtime

    # Force reload of charmap from cache file and check that mtime is unchanged.
    cm._charmap = None
    cm.charmap()
    statinfo = os.stat(cm.charmap_file())
    assert statinfo.st_mtime == mtime
def test_charmap_has_right_categories():
    for cat, intervals in cm.charmap().items():
        for u, v in intervals:
            for i in range(u, v + 1):
                real = unicodedata.category(hunichr(i))
                assert real == cat, \
                    '%d is %s but reported in %s' % (i, real, cat)
示例#17
0
def test_charmap_has_right_categories():
    for cat, intervals in cm.charmap().items():
        for u, v in intervals:
            for i in range(u, v + 1):
                real = unicodedata.category(hunichr(i))
                assert real == cat, \
                    '%d is %s but reported in %s' % (i, real, cat)
示例#18
0
def test_error_writing_charmap_file_is_suppressed(monkeypatch):
    def broken_mkstemp(dir):
        raise RuntimeError()

    monkeypatch.setattr(tempfile, 'mkstemp', broken_mkstemp)

    try:
        # Cache the charmap to avoid a performance hit the next time
        # somebody tries to use it.
        saved = cm._charmap
        cm._charmap = None
        os.unlink(cm.charmap_file())

        cm.charmap()
    finally:
        cm._charmap = saved
示例#19
0
def test_error_writing_charmap_file_is_suppressed(monkeypatch):
    def broken_mkstemp(dir):
        raise RuntimeError()

    monkeypatch.setattr(tempfile, "mkstemp", broken_mkstemp)

    try:
        # Cache the charmap to avoid a performance hit the next time
        # somebody tries to use it.
        saved = cm._charmap
        cm._charmap = None
        os.unlink(cm.charmap_file())

        cm.charmap()
    finally:
        cm._charmap = saved
示例#20
0
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'))
示例#21
0
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'))
示例#22
0
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'))
示例#23
0
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'))
示例#24
0
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'))
示例#25
0
def test_charmap_has_right_categories():
    for cat, intervals in cm.charmap().items():
        for u, v in intervals:
            for i in range(u, v + 1):
                real = unicodedata.category(chr(i))
                assert real == cat, f"{i} is {real} but reported in {cat}"
示例#26
0
def test_charmap_contains_all_unicode():
    n = 0
    for vs in cm.charmap().values():
        for u, v in vs:
            n += v - u + 1
    assert n == sys.maxunicode + 1
示例#27
0
def test_successive_union():
    x = []
    for v in cm.charmap().values():
        x = cm._union_intervals(x, v)
    assert x == ((0, sys.maxunicode),)
示例#28
0
def test_charmap_contains_all_unicode():
    n = 0
    for vs in cm.charmap().values():
        for u, v in vs:
            n += (v - u + 1)
    assert n == sys.maxunicode + 1
示例#29
0
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,
            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'))
示例#30
0
def test_successive_union():
    x = []
    for v in cm.charmap().values():
        x = cm._union_intervals(x, v)
    assert x == ((0, sys.maxunicode), )
示例#31
0
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"))
示例#32
0
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"))