예제 #1
0
async def test_str() -> None:
    assert "foo~=^f" == str(filter.Filter({"~=": ("foo", "^f")}))
    assert "-foo=1" == str(filter.Filter({"-": {"=": ("foo", 1)}}))
    assert "foo" == str(filter.Filter({"=": ("foo", True)}))
    assert "-bar" == str(filter.Filter({"=": ("bar", False)}))
    with pytest.raises(filter.InvalidOperator):
        str(filter.Filter({">=": ("bar", False)}))
예제 #2
0
async def test_contains() -> None:
    f = filter.Filter({"=": ("foo", 1)})
    assert await f(FakePR({"foo": [1, 2]}))
    assert not await f(FakePR({"foo": [2, 3]}))
    assert await f(FakePR({"foo": (1, 2)}))
    f = filter.Filter({">": ("foo", 2)})
    assert not await f(FakePR({"foo": [1, 2]}))
    assert await f(FakePR({"foo": [2, 3]}))
예제 #3
0
def test_contains():
    f = filter.Filter({"=": ("foo", 1)})
    assert f(foo=[1, 2])
    assert not f(foo=[2, 3])
    assert f(foo=(1, 2))
    f = filter.Filter({">": ("foo", 2)})
    assert not f(foo=[1, 2])
    assert f(foo=[2, 3])
예제 #4
0
def test_str():
    assert "foo~=^f" == str(filter.Filter({
        "~=": ("foo", "^f"),
    }))
    assert "-foo=1" == str(filter.Filter({
        "-": {
            "=": ("foo", 1)
        },
    }))
예제 #5
0
def test_regexp():
    f = filter.Filter({"~=": ("foo", "^f")})
    assert f(foo="foobar")
    assert f(foo="foobaz")
    assert not f(foo="x")
    assert not f(foo=None)

    f = filter.Filter({"~=": ("foo", "^$")})
    assert f(foo="")
    assert not f(foo="x")
예제 #6
0
async def test_regexp() -> None:
    f = filter.Filter({"~=": ("foo", "^f")})
    assert await f(FakePR({"foo": "foobar"}))
    assert await f(FakePR({"foo": "foobaz"}))
    assert not await f(FakePR({"foo": "x"}))
    assert not await f(FakePR({"foo": None}))

    f = filter.Filter({"~=": ("foo", "^$")})
    assert await f(FakePR({"foo": ""}))
    assert not await f(FakePR({"foo": "x"}))
예제 #7
0
async def test_set_value_expanders() -> None:
    f = filter.Filter(
        {"=": ("foo", "@bar")},
        value_expanders={"foo": lambda x: [x.replace("@", "foo")]},
    )
    assert await f(FakePR({"foo": "foobar"}))
    assert not await f(FakePR({"foo": "x"}))
예제 #8
0
def test_set_value_expanders():
    f = filter.Filter({
        "=": ("foo", "@bar"),
    })
    f.set_value_expanders("foo", lambda x: [x.replace("@", "foo")])
    assert f(foo="foobar")
    assert not f(foo="x")
예제 #9
0
def test_does_not_contain():
    f = filter.Filter({
        "!=": ("foo", 1),
    })
    assert f(foo=[])
    assert f(foo=[2, 3])
    assert not f(foo=(1, 2))
예제 #10
0
def test_not():
    f = filter.Filter({
        "-": {
            "=": ("foo", 1)
        },
    })
    assert not f(foo=1)
    assert f(foo=2)
예제 #11
0
def test_len():
    f = filter.Filter({"=": ("#foo", 3)})
    assert f(foo="bar")
    with pytest.raises(filter.InvalidOperator):
        f(foo=2)
    assert not f(foo="a")
    assert not f(foo="abcedf")
    assert f(foo=[10, 20, 30])
    assert not f(foo=[10, 20])
    assert not f(foo=[10, 20, 40, 50])
    f = filter.Filter({">": ("#foo", 3)})
    assert f(foo="barz")
    with pytest.raises(filter.InvalidOperator):
        f(foo=2)
    assert not f(foo="a")
    assert f(foo="abcedf")
    assert f(foo=[10, "abc", 20, 30])
    assert not f(foo=[10, 20])
    assert not f(foo=[])
예제 #12
0
async def test_len() -> None:
    f = filter.Filter({"=": ("#foo", 3)})
    assert await f(FakePR({"foo": "bar"}))
    with pytest.raises(filter.InvalidOperator):
        await f(FakePR({"foo": 2}))
    assert not await f(FakePR({"foo": "a"}))
    assert not await f(FakePR({"foo": "abcedf"}))
    assert await f(FakePR({"foo": [10, 20, 30]}))
    assert not await f(FakePR({"foo": [10, 20]}))
    assert not await f(FakePR({"foo": [10, 20, 40, 50]}))
    f = filter.Filter({">": ("#foo", 3)})
    assert await f(FakePR({"foo": "barz"}))
    with pytest.raises(filter.InvalidOperator):
        await f(FakePR({"foo": 2}))
    assert not await f(FakePR({"foo": "a"}))
    assert await f(FakePR({"foo": "abcedf"}))
    assert await f(FakePR({"foo": [10, "abc", 20, 30]}))
    assert not await f(FakePR({"foo": [10, 20]}))
    assert not await f(FakePR({"foo": []}))
예제 #13
0
def test_binary():
    f = filter.Filter({
        "=": ("foo", 1),
    })
    assert f(foo=1)
    assert not f(foo=2)
예제 #14
0
async def test_string() -> None:
    f = filter.Filter({"=": ("foo", "bar")})
    assert await f(FakePR({"foo": "bar"}))
    assert not await f(FakePR({"foo": 2}))
예제 #15
0
async def test_not() -> None:
    f = filter.Filter({"-": {"=": ("foo", 1)}})
    assert not await f(FakePR({"foo": 1}))
    assert await f(FakePR({"foo": 2}))
예제 #16
0
async def test_invalid_arguments() -> None:
    with pytest.raises(filter.InvalidArguments):
        filter.Filter({"=": (1, 2, 3)})  # type: ignore[typeddict-item]
예제 #17
0
def test_set_value_expanders_does_not_contain():
    f = filter.Filter({"!=": ("foo", "@bar")})
    f.set_value_expanders("foo", lambda x: ["foobaz", "foobar"])
    assert not f(foo="foobar")
    assert not f(foo="foobaz")
    assert f(foo="foobiz")
예제 #18
0
async def test_parse_error() -> None:
    with pytest.raises(filter.ParseError):
        filter.Filter({})
예제 #19
0
async def test_unknown_operator() -> None:
    with pytest.raises(filter.UnknownOperator):
        filter.Filter({"oops": (1, 2)})  # type: ignore[typeddict-item]
예제 #20
0
def test_regexp_invalid():
    with pytest.raises(filter.InvalidArguments):
        filter.Filter({
            "~=": ("foo", "([^\s\w])(\s*\1+"),  # noqa
        })
예제 #21
0
async def test_unknown_attribute() -> None:
    f = filter.Filter({"=": ("foo", 1)})
    with pytest.raises(filter.UnknownAttribute):
        await f(FakePR({"bar": 1}))
예제 #22
0
async def test_set_value_expanders_does_not_contain() -> None:
    f = filter.Filter({"!=": ("foo", "@bar")},
                      value_expanders={"foo": lambda x: ["foobaz", "foobar"]})
    assert not await f(FakePR({"foo": "foobar"}))
    assert not await f(FakePR({"foo": "foobaz"}))
    assert await f(FakePR({"foo": "foobiz"}))
예제 #23
0
def test_unknown_attribute():
    f = filter.Filter({
        "=": ("foo", 1),
    })
    with pytest.raises(filter.UnknownAttribute):
        f(bar=1)
예제 #24
0
def test_parse_error():
    with pytest.raises(filter.ParseError):
        filter.Filter({})
예제 #25
0
def test_unknown_operator():
    with pytest.raises(filter.UnknownOperator):
        filter.Filter({
            "oops": (1, 2),
        })
예제 #26
0
def test_invalid_arguments():
    with pytest.raises(filter.InvalidArguments):
        filter.Filter({
            "=": (1, 2, 3),
        })
예제 #27
0
async def test_regexp_invalid() -> None:
    with pytest.raises(filter.InvalidArguments):
        filter.Filter({"~=": ("foo", r"([^\s\w])(\s*\1+")})
예제 #28
0
def test_string():
    f = filter.Filter({
        "=": ("foo", "bar"),
    })
    assert f(foo="bar")
    assert not f(foo=2)
예제 #29
0
async def test_does_not_contain() -> None:
    f = filter.Filter({"!=": ("foo", 1)})
    assert await f(FakePR({"foo": []}))
    assert await f(FakePR({"foo": [2, 3]}))
    assert not await f(FakePR({"foo": (1, 2)}))
예제 #30
0
def test_set_value_expanders_unset_at_init() -> None:
    f = filter.Filter({"=": ("foo", "@bar")})
    f.value_expanders = {"foo": lambda x: [x.replace("@", "foo")]}
    assert f(FakePR({"foo": "foobar"}))
    assert not f(FakePR({"foo": "x"}))