Пример #1
0
def test_builtin_types():
    encoder = Encoder()
    values = [
        1,
        1.1,
        b"\x00\x01\x02",
        "\N{SNOWMAN}",
        ("a", "b", "c"),
        ["a", "b", "c"],
        {
            "a": 1,
            "b": 2,
            "c": 3
        },
        set(["a", "b", "c"]),
        frozenset(["a", "b", "c"]),
        [{
            "a": 1
        }, set("b"), ["c"], "text"],
    ]

    try:
        values.append(long(1))  # noqa
    except NameError:
        pass

    for value in values:
        encoded = encoder.dumps(value)
        assert isinstance(encoded, six.binary_type)

    with pytest.raises(TypeError):
        encoder.dumps(object())
Пример #2
0
def test_builtin_types():
    encoder = Encoder()
    values = [
        1,
        1.1,
        b'\x00\x01\x02',
        u'\N{SNOWMAN}',
        ('a', 'b', 'c'),
        ['a', 'b', 'c'],
        {
            'a': 1,
            'b': 2,
            'c': 3
        },
        set(['a', 'b', 'c']),
        frozenset(['a', 'b', 'c']),
        [{
            'a': 1
        }, set('b'), ['c'], u'text'],
    ]

    try:
        values.append(long(1))  # noqa
    except NameError:
        pass

    for value in values:
        encoded = encoder.dumps(value)
        assert isinstance(encoded, six.binary_type)

    with pytest.raises(TypeError):
        encoder.dumps(object())
Пример #3
0
def test_builtin_types():
    encoder = Encoder()
    values = [
        1,
        1.1,
        b'\x00\x01\x02',
        u'\N{SNOWMAN}',
        ('a', 'b', 'c'),
        ['a', 'b', 'c'],
        {'a': 1, 'b': 2, 'c': 3},
        set(['a', 'b', 'c']),
        frozenset(['a', 'b', 'c']),
        [{'a': 1}, set('b'), ['c'], u'text'],
    ]

    try:
        values.append(long(1))  # noqa
    except NameError:
        pass

    for value in values:
        encoded = encoder.dumps(value)
        assert isinstance(encoded, six.binary_type)

    with pytest.raises(TypeError):
        encoder.dumps(object())
Пример #4
0
def test_custom_types():
    class Widget(object):
        def __init__(self, color):
            self.color = color

    encoder = Encoder({Widget: lambda i: {"color": i.color}})

    assert encoder.dumps(Widget("red")) == encoder.dumps({"color": "red"})
Пример #5
0
def test_custom_types():
    class Widget(object):
        def __init__(self, color):
            self.color = color

    encoder = Encoder({
        Widget: lambda i: {
            'color': i.color,
        },
    })

    assert encoder.dumps(Widget('red'), ) == encoder.dumps({
        'color': 'red',
    })
Пример #6
0
def test_custom_types():
    class Widget(object):
        def __init__(self, color):
            self.color = color

    encoder = Encoder({
        Widget: lambda i: {
            'color': i.color, },
    })

    assert encoder.dumps(
        Widget('red'),
    ) == encoder.dumps({
        'color': 'red',
    })
Пример #7
0
    def __init__(self, index, configurations=None):
        self.index = index

        if configurations is None:
            configurations = settings.SENTRY_SIMILARITY_GROUPING_CONFIGURATIONS_TO_INDEX

        self.configurations = configurations

        # This is intentionally non-configurable and only exists because we
        # subclass from FeatureSet. TODO: Remove FeatureSet subclassing!
        # eg: Replace with ABC hierarchy or kill old similarity.
        self.encoder = Encoder()
        self.expected_extraction_errors = ()
        self.expected_encoding_errors = ()

        self.features = {
            (config_id, component_id, shingle_label): None
            for config_id in self.configurations
            for component_id, shingle_label in _KNOWN_COMPONENT_LABEL_SUFFIXES
        }

        self.aliases = {
            (config_id, component_id, shingle_label): "{}:{}".format(
                self.configurations[config_id],
                _KNOWN_COMPONENT_LABEL_SUFFIXES[component_id, shingle_label],
            )
            for config_id, component_id, shingle_label in self.features
        }
Пример #8
0
    return MetricsWrapper(
        RedisScriptMinHashIndexBackend(cluster, namespace,
                                       MinHashSignatureBuilder(16, 0xFFFF), 8,
                                       60 * 60 * 24 * 30, 3, 5000),
        scope_tag_name=None,
    )


features = FeatureSet(
    _make_index_backend(
        getattr(settings, "SENTRY_SIMILARITY_INDEX_REDIS_CLUSTER", None)
        or "similarity",
        namespace="sim:1",
    ),
    Encoder({Frame: get_frame_attributes}),
    BidirectionalMapping({
        "exception:message:character-shingles": "a",
        "exception:stacktrace:application-chunks": "b",
        "exception:stacktrace:pairs": "c",
        "message:message:character-shingles": "d",
    }),
    {
        "exception:message:character-shingles":
        ExceptionFeature(lambda exception: text_shingle(5, exception.value)),
        "exception:stacktrace:application-chunks":
        ExceptionFeature(lambda exception: get_application_chunks(exception)),
        "exception:stacktrace:pairs":
        ExceptionFeature(
            lambda exception: shingle(2, exception.stacktrace.frames)),
        "message:message:character-shingles":