コード例 #1
0
ファイル: test_eval.py プロジェクト: mikewaters/pipeline
def test_custom_matcher():
    """Test that a custom criteria matcher functions."""
    class TestMatcher(Matcher):
        __id = "test_matcher"
        def __call__(self, data):
            return data == 'qwerty'

    source = Source()
    setattr(source, 'test', 'qwerty')

    assert evaluate_single_criterion(
        {'source': source},
        ['source.test', 'matches', 'test_matcher']
    )
コード例 #2
0
ファイル: test_eval.py プロジェクト: mikewaters/pipeline
def test_config_eval():
    """Tests for the evaluate_single_criterion function."""
    source = Source()
    setattr(source, 'test', 'qwerty')
    assert evaluate_single_criterion(
        {'source': source},
        ['source.test', 'is', 'qwerty']
    )
    assert not evaluate_single_criterion(
        {'source': source},
        ['source.test', 'is', 'sqwerty']
    )
    assert evaluate_single_criterion(
        {'source': source},
        ['source.test', 'in', ['qwerty']]
    )
    assert evaluate_single_criterion(
        {'source': source},
        ['source.test', 'in', ['qwerty', 'uiop']]
    )
    assert not evaluate_single_criterion(
        {'source': source},
        ['source.test', 'in', ['qwert', 'uiop']]
    )
    assert evaluate_single_criterion(
        {'source': source},
        ['source.test', 'like', 'qwerty']
    )
    assert evaluate_single_criterion(
        {'source': source},
        ['source.test', 'like', '.werty']
    )
    assert evaluate_single_criterion(
        {'source': source},
        ['source.test', 'like', '.*wert.*']
    )
    assert evaluate_single_criterion(
        {'source': source},
        ['source.test', 'like', '.wert.']
    )
    assert evaluate_single_criterion(
        {'source': source},
        ['source.test', 'like', '[q]werty']
    )
    assert evaluate_single_criterion(
        {'source': source},
        ['source.test', 'like', '^qwerty$']
    )
    assert not  evaluate_single_criterion(
        {'source': source},
        ['source.test', 'like', '^qwert$']
    )
    assert not  evaluate_single_criterion(
        {'source': source},
        ['source.test', 'like', '..werty']
    )
    with pytest.raises(NotImplementedError):
        evaluate_single_criterion(
            {'source': source},
            ['source.test', 'boom', 'x']
        )