コード例 #1
0
def pytest_report_header(config):
    profile = config.getoption(LOAD_PROFILE_OPTION)
    if not profile:
        profile = settings._current_profile
    settings_str = settings.get_profile(profile).show_changed()
    if settings_str != "":
        settings_str = " -> %s" % (settings_str)
    return "hypothesis profile %r%s" % (profile, settings_str)
コード例 #2
0
def pytest_report_header(config):
    profile = config.getoption(LOAD_PROFILE_OPTION)
    if not profile:
        profile = 'default'
    settings_str = settings.get_profile(profile).show_changed()
    if settings_str != '':
        settings_str = ' -> %s' % (settings_str)
    return 'hypothesis profile %r%s' % (profile, settings_str)
コード例 #3
0
def pytest_report_header(config):
    profile = config.getoption(LOAD_PROFILE_OPTION)
    if not profile:
        profile = settings._current_profile
    settings_str = settings.get_profile(profile).show_changed()
    if settings_str != "":
        settings_str = " -> %s" % (settings_str)
    return "hypothesis profile %r%s" % (profile, settings_str)
コード例 #4
0
def pytest_report_header(config):
    profile = config.getoption(LOAD_PROFILE_OPTION)
    if not profile:
        profile = 'default'
    settings_str = settings.get_profile(profile).show_changed()
    if settings_str != '':
        settings_str = ' -> %s' % (settings_str)
    return 'hypothesis profile %r%s' % (profile, settings_str)
コード例 #5
0
def _modify_hypothesis_settings(settings, name, parent):
    hp_settings.register_profile(
        name,
        parent=hp_settings.get_profile(parent),
        database=DirectoryBasedExampleDatabase(
            _get_data_folder().joinpath("hypothesis")),
        **settings,
    )
    hp_settings.load_profile(name)
コード例 #6
0
ファイル: pytestplugin.py プロジェクト: szTheory/hypothesis
 def pytest_report_header(config):
     profile = config.getoption(LOAD_PROFILE_OPTION)
     if not profile:
         profile = settings._current_profile
     settings_str = settings.get_profile(profile).show_changed()
     if settings_str != "":
         settings_str = " -> %s" % (settings_str)
     if (config.option.verbose >= 1
             or settings.default.verbosity >= Verbosity.verbose):
         return "hypothesis profile %r%s" % (profile, settings_str)
コード例 #7
0
 def pytest_report_header(config):
     if config.option.verbose < 1 and settings.default.verbosity < Verbosity.verbose:
         return None
     profile = config.getoption(LOAD_PROFILE_OPTION)
     if not profile:
         profile = settings._current_profile
     settings_str = settings.get_profile(profile).show_changed()
     if settings_str != "":
         settings_str = f" -> {settings_str}"
     return f"hypothesis profile {profile!r}{settings_str}"
コード例 #8
0
ファイル: _config.py プロジェクト: asa-Q/brownie
def _modify_hypothesis_settings(settings, name, parent=None):
    settings = settings.copy()
    if parent is None:
        parent = hp_settings._current_profile

    if "phases" in settings:
        try:
            settings["phases"] = [getattr(Phase, k) for k, v in settings["phases"].items() if v]
        except AttributeError as exc:
            raise ValueError(f"'{exc.args[0]}' is not a valid hypothesis phase setting")

    hp_settings.register_profile(
        name,
        parent=hp_settings.get_profile(parent),
        database=DirectoryBasedExampleDatabase(_get_data_folder().joinpath("hypothesis")),
        **settings,
    )
    hp_settings.load_profile(name)
コード例 #9
0
# XXX: https://github.com/pimutils/vdirsyncer/issues/617
@pytest.mark.skipif(sys.platform == "darwin",
                    reason="This test inexplicably fails")
@pytest.mark.parametrize(
    "collections",
    [
        ("persönlich", ),
        (
            "a",
            "A",
        ),
        ("\ufffe", ),
    ] + [
        collections_strategy.example() for _ in range(
            settings.get_profile(settings._current_profile).max_examples)
    ],
)
def test_create_collections(collections, tmpdir, runner):
    # Hypothesis calls this tests in a way that fixtures are not reset, to tmpdir is the
    # same for each call.
    # This horrible hack creates a new subdirectory on each run, effectively giving us a
    # new tmpdir each run.

    runner.write_with_general(
        dedent("""
    [pair foobar]
    a = "foo"
    b = "bar"
    collections = {colls}
コード例 #10
0
ファイル: conftest.py プロジェクト: lenskit/csr
    """
    Fixture for variable CSR kernels.  This fixture is parameterized, so if you
    write a test function with a parameter ``kernel`` as its first parameter, it
    will be called once for each kernel under active test.
    """
    if request.param in DISABLED_KERNELS:
        skip(f'kernel {request.param} is disabled')

    with use_kernel(request.param):
        k = get_kernel()
        # warm-up the kernel
        m = CSR.empty(1, 1)
        h = k.to_handle(m)
        k.release_handle(h)
        del h, m
        yield k


# set up profiles
settings.register_profile('default', deadline=2500)
settings.register_profile('large',
                          settings.get_profile('default'),
                          max_examples=5000,
                          deadline=None)
settings.register_profile('fast', max_examples=50)
settings.register_profile('nojit',
                          settings.get_profile('fast'),
                          deadline=None,
                          suppress_health_check=HealthCheck.all())
settings.load_profile('default')
コード例 #11
0
class StorageTests:
    storage_class = None
    supports_collections = True
    supports_metadata = True

    @pytest.fixture(params=["VEVENT", "VTODO", "VCARD"])
    def item_type(self, request):
        """Parametrize with all supported item types."""
        return request.param

    @pytest.fixture
    def get_storage_args(self):
        """
        Return a function with the following properties:

        :param collection: The name of the collection to create and use.
        """
        raise NotImplementedError()

    @pytest.fixture
    def s(self, get_storage_args):
        return self.storage_class(**get_storage_args())

    @pytest.fixture
    def get_item(self, item_type):
        template = {
            "VEVENT": EVENT_TEMPLATE,
            "VTODO": TASK_TEMPLATE,
            "VCARD": VCARD_TEMPLATE,
        }[item_type]

        return lambda **kw: format_item(template, **kw)

    @pytest.fixture
    def requires_collections(self):
        if not self.supports_collections:
            pytest.skip("This storage does not support collections.")

    @pytest.fixture
    def requires_metadata(self):
        if not self.supports_metadata:
            pytest.skip("This storage does not support metadata.")

    def test_generic(self, s, get_item):
        items = [get_item() for i in range(1, 10)]
        hrefs = []
        for item in items:
            href, etag = s.upload(item)
            if etag is None:
                _, etag = s.get(href)
            hrefs.append((href, etag))
        hrefs.sort()
        assert hrefs == sorted(s.list())
        for href, etag in hrefs:
            assert isinstance(href, (str, bytes))
            assert isinstance(etag, (str, bytes))
            assert s.has(href)
            item, etag2 = s.get(href)
            assert etag == etag2

    def test_empty_get_multi(self, s):
        assert list(s.get_multi([])) == []

    def test_get_multi_duplicates(self, s, get_item):
        href, etag = s.upload(get_item())
        if etag is None:
            _, etag = s.get(href)
        ((href2, item, etag2), ) = s.get_multi([href] * 2)
        assert href2 == href
        assert etag2 == etag

    def test_upload_already_existing(self, s, get_item):
        item = get_item()
        s.upload(item)
        with pytest.raises(exceptions.PreconditionFailed):
            s.upload(item)

    def test_upload(self, s, get_item):
        item = get_item()
        href, etag = s.upload(item)
        assert_item_equals(s.get(href)[0], item)

    def test_update(self, s, get_item):
        item = get_item()
        href, etag = s.upload(item)
        if etag is None:
            _, etag = s.get(href)
        assert_item_equals(s.get(href)[0], item)

        new_item = get_item(uid=item.uid)
        new_etag = s.update(href, new_item, etag)
        if new_etag is None:
            _, new_etag = s.get(href)
        # See https://github.com/pimutils/vdirsyncer/issues/48
        assert isinstance(new_etag, (bytes, str))
        assert_item_equals(s.get(href)[0], new_item)

    def test_update_nonexisting(self, s, get_item):
        item = get_item()
        with pytest.raises(exceptions.PreconditionFailed):
            s.update("huehue", item, '"123"')

    def test_wrong_etag(self, s, get_item):
        item = get_item()
        href, etag = s.upload(item)
        with pytest.raises(exceptions.PreconditionFailed):
            s.update(href, item, '"lolnope"')
        with pytest.raises(exceptions.PreconditionFailed):
            s.delete(href, '"lolnope"')

    def test_delete(self, s, get_item):
        href, etag = s.upload(get_item())
        s.delete(href, etag)
        assert not list(s.list())

    def test_delete_nonexisting(self, s, get_item):
        with pytest.raises(exceptions.PreconditionFailed):
            s.delete("1", '"123"')

    def test_list(self, s, get_item):
        assert not list(s.list())
        href, etag = s.upload(get_item())
        if etag is None:
            _, etag = s.get(href)
        assert list(s.list()) == [(href, etag)]

    def test_has(self, s, get_item):
        assert not s.has("asd")
        href, etag = s.upload(get_item())
        assert s.has(href)
        assert not s.has("asd")
        s.delete(href, etag)
        assert not s.has(href)

    def test_update_others_stay_the_same(self, s, get_item):
        info = {}
        for _ in range(4):
            href, etag = s.upload(get_item())
            if etag is None:
                _, etag = s.get(href)
            info[href] = etag

        assert {
            href: etag
            for href, item, etag in s.get_multi(
                href for href, etag in info.items())
        } == info

    def test_repr(self, s, get_storage_args):
        assert self.storage_class.__name__ in repr(s)
        assert s.instance_name is None

    def test_discover(self, requires_collections, get_storage_args, get_item):
        collections = set()
        for i in range(1, 5):
            collection = f"test{i}"
            s = self.storage_class(**get_storage_args(collection=collection))
            assert not list(s.list())
            s.upload(get_item())
            collections.add(s.collection)

        actual = {
            c["collection"]
            for c in self.storage_class.discover(**get_storage_args(
                collection=None))
        }

        assert actual >= collections

    def test_create_collection(self, requires_collections, get_storage_args,
                               get_item):
        if getattr(self, "dav_server",
                   "") in ("icloud", "fastmail", "davical"):
            pytest.skip("Manual cleanup would be necessary.")
        if getattr(self, "dav_server", "") == "radicale":
            pytest.skip("Radicale does not support collection creation")

        args = get_storage_args(collection=None)
        args["collection"] = "test"

        s = self.storage_class(**self.storage_class.create_collection(**args))

        href = s.upload(get_item())[0]
        assert href in {href for href, etag in s.list()}

    def test_discover_collection_arg(self, requires_collections,
                                     get_storage_args):
        args = get_storage_args(collection="test2")
        with pytest.raises(TypeError) as excinfo:
            list(self.storage_class.discover(**args))

        assert "collection argument must not be given" in str(excinfo.value)

    def test_collection_arg(self, get_storage_args):
        if self.storage_class.storage_name.startswith("etesync"):
            pytest.skip("etesync uses UUIDs.")

        if self.supports_collections:
            s = self.storage_class(**get_storage_args(collection="test2"))
            # Can't do stronger assertion because of radicale, which needs a
            # fileextension to guess the collection type.
            assert "test2" in s.collection
        else:
            with pytest.raises(ValueError):
                self.storage_class(collection="ayy", **get_storage_args())

    def test_case_sensitive_uids(self, s, get_item):
        if s.storage_name == "filesystem":
            pytest.skip("Behavior depends on the filesystem.")

        uid = str(uuid.uuid4())
        s.upload(get_item(uid=uid.upper()))
        s.upload(get_item(uid=uid.lower()))
        items = list(href for href, etag in s.list())
        assert len(items) == 2
        assert len(set(items)) == 2

    def test_specialchars(self, monkeypatch, requires_collections,
                          get_storage_args, get_item):
        if getattr(self, "dav_server", "") == "radicale":
            pytest.skip("Radicale is fundamentally broken.")
        if getattr(self, "dav_server", "") in ("icloud", "fastmail"):
            pytest.skip("iCloud and FastMail reject this name.")

        monkeypatch.setattr("vdirsyncer.utils.generate_href", lambda x: x)

        uid = "test @ foo ät bar град сатану"
        collection = "test @ foo ät bar"

        s = self.storage_class(**get_storage_args(collection=collection))
        item = get_item(uid=uid)

        href, etag = s.upload(item)
        item2, etag2 = s.get(href)
        if etag is not None:
            assert etag2 == etag
            assert_item_equals(item2, item)

        ((_, etag3), ) = s.list()
        assert etag2 == etag3

        # etesync uses UUIDs for collection names
        if self.storage_class.storage_name.startswith("etesync"):
            return

        assert collection in urlunquote(s.collection)
        if self.storage_class.storage_name.endswith("dav"):
            assert urlquote(uid, "/@:") in href

    def test_metadata(self, requires_metadata, s):
        if not getattr(self, "dav_server", ""):
            assert not s.get_meta("color")
            assert not s.get_meta("displayname")

        try:
            s.set_meta("color", None)
            assert not s.get_meta("color")
            s.set_meta("color", "#ff0000")
            assert s.get_meta("color") == "#ff0000"
        except exceptions.UnsupportedMetadataError:
            pass

        for x in ("hello world", "hello wörld"):
            s.set_meta("displayname", x)
            rv = s.get_meta("displayname")
            assert rv == x
            assert isinstance(rv, str)

    @pytest.mark.parametrize(
        "value",
        [None] + [
            printable_characters_strategy.example() for _ in range(
                settings.get_profile(settings._current_profile).max_examples)
        ],
    )
    def test_metadata_normalization(self, requires_metadata, s, value):
        x = s.get_meta("displayname")
        assert x == normalize_meta_value(x)

        if not getattr(self, "dav_server", None):
            # ownCloud replaces "" with "unnamed"
            s.set_meta("displayname", value)
            assert s.get_meta("displayname") == normalize_meta_value(value)

    def test_recurring_events(self, s, item_type):
        if item_type != "VEVENT":
            pytest.skip("This storage instance doesn't support iCalendar.")

        uid = str(uuid.uuid4())
        item = Item(
            textwrap.dedent("""
        BEGIN:VCALENDAR
        VERSION:2.0
        BEGIN:VEVENT
        DTSTART;TZID=UTC:20140325T084000Z
        DTEND;TZID=UTC:20140325T101000Z
        DTSTAMP:20140327T060506Z
        UID:{uid}
        RECURRENCE-ID;TZID=UTC:20140325T083000Z
        CREATED:20131216T033331Z
        DESCRIPTION:
        LAST-MODIFIED:20140327T060215Z
        LOCATION:
        SEQUENCE:1
        STATUS:CONFIRMED
        SUMMARY:test Event
        TRANSP:OPAQUE
        END:VEVENT
        BEGIN:VEVENT
        DTSTART;TZID=UTC:20140128T083000Z
        DTEND;TZID=UTC:20140128T100000Z
        RRULE:FREQ=WEEKLY;UNTIL=20141208T213000Z;BYDAY=TU
        DTSTAMP:20140327T060506Z
        UID:{uid}
        CREATED:20131216T033331Z
        DESCRIPTION:
        LAST-MODIFIED:20140222T101012Z
        LOCATION:
        SEQUENCE:0
        STATUS:CONFIRMED
        SUMMARY:Test event
        TRANSP:OPAQUE
        END:VEVENT
        END:VCALENDAR
        """.format(uid=uid)).strip())

        href, etag = s.upload(item)

        item2, etag2 = s.get(href)
        assert normalize_item(item) == normalize_item(item2)
コード例 #12
0
ファイル: strategies.py プロジェクト: monperrus/swh-web
                                   characters)

from swh.model.hashutil import hash_to_hex, hash_to_bytes
from swh.model.identifiers import directory_identifier
from swh.storage.algos.revisions_walker import get_revisions_walker
from swh.storage.tests.algos.test_snapshot import (  # noqa
    origins as new_origin_strategy, snapshots as new_snapshot)
from swh.web.tests.data import get_tests_data

# Module dedicated to the generation of input data for tests through
# the use of hypothesis.
# Some of these data are sampled from a test archive created and populated
# in the swh.web.tests.data module.

# Set the swh-web hypothesis profile if none has been explicitly set
hypothesis_default_settings = settings.get_profile('default')
if repr(settings()) == repr(hypothesis_default_settings):
    settings.load_profile('swh-web')

# Import tests data
tests_data = get_tests_data()
storage = tests_data['storage']

# The following strategies exploit the hypothesis capabilities

_generated_checksums = set()


def _filter_checksum(cs):
    if not int.from_bytes(cs, byteorder='little') or \
            cs in _generated_checksums: