File: test_ExcludeFilter.py

package info (click to toggle)
graypy 2.1.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 312 kB
  • sloc: python: 1,175; sh: 114; makefile: 3
file content (40 lines) | stat: -rw-r--r-- 1,203 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""pytests for :class:`graypy.rabbitmq.ExcludeFilter`"""

import pytest

from graypy import ExcludeFilter

from tests.unit.helper import MOCK_LOG_RECORD_NAME, MOCK_LOG_RECORD


@pytest.mark.parametrize("name", [None, ""])
def test_invalid_name(name):
    """Test constructing:class:`graypy.rabbitmq.ExcludeFilter` with a
    invalid ``name`` argument"""
    with pytest.raises(ValueError):
        ExcludeFilter(name)


@pytest.mark.parametrize("name", ["foobar", ".", " "])
def test_valid_name(name):
    """Test constructing :class:`graypy.rabbitmq.ExcludeFilter` with a
    valid ``name`` argument"""
    exclude_filter = ExcludeFilter(name)
    assert exclude_filter
    assert name == exclude_filter.name
    assert len(name) == exclude_filter.nlen


def test_non_filtering_record():
    exclude_filter = ExcludeFilter("NOT" + MOCK_LOG_RECORD_NAME)
    assert exclude_filter.filter(MOCK_LOG_RECORD)
    assert MOCK_LOG_RECORD.name != exclude_filter.name


def test_filtering_record():
    exclude_filter = ExcludeFilter(MOCK_LOG_RECORD_NAME)
    assert not exclude_filter.filter(MOCK_LOG_RECORD)
    assert MOCK_LOG_RECORD.name == exclude_filter.name