Beispiel #1
0
def test_compile_state(pattern, pickle_proto):
    from polymatch import pattern_registry
    compiled_pattern = pattern_registry.pattern_from_string(pattern)
    compiled_pattern.compile()

    assert compiled_pattern.is_compiled()

    uncompiled_pattern = pattern_registry.pattern_from_string(pattern)

    assert not uncompiled_pattern.is_compiled()

    pat1, pat2 = cycle_pickle((compiled_pattern, uncompiled_pattern),
                              pickle_proto)

    assert pat1.is_compiled() is compiled_pattern.is_compiled()

    assert pat2.is_compiled() is uncompiled_pattern.is_compiled()
Beispiel #2
0
def test_properties(pattern, pickle_proto):
    from polymatch import pattern_registry
    pat = pattern_registry.pattern_from_string(pattern)
    pat.compile()

    inv_pat = pattern_registry.pattern_from_string('~' + pattern)
    inv_pat.compile()

    assert not pat.inverted
    assert inv_pat.inverted

    new_pat = cycle_pickle(pat, pickle_proto)
    new_inv_pat = cycle_pickle(inv_pat, pickle_proto)

    assert not new_pat.inverted
    assert new_inv_pat.inverted

    for _pat in cycle_pickle([pat], pickle_proto):
        assert not _pat.inverted

    for _pat in cycle_pickle(C(pat), pickle_proto).patterns:
        assert not _pat.inverted
Beispiel #3
0
def test_version_checks(pattern, pickle_proto):
    from polymatch import pattern_registry
    import polymatch
    pat = pattern_registry.pattern_from_string(pattern)
    pat.compile()

    assert pat.is_compiled()

    data = pickle.dumps(pat, pickle_proto)

    # Change version
    polymatch.__version__ = polymatch.__version__[:2] + (
        polymatch.__version__[2] + 1, )

    new_pat = pickle.loads(data)

    assert new_pat.is_compiled()
Beispiel #4
0
def test_patterns():
    from polymatch import pattern_registry
    for pattern, text, result in data:
        matcher = pattern_registry.pattern_from_string(pattern)
        matcher.compile()
        assert bool(matcher == text) is result
Beispiel #5
0
def test_invert():
    from polymatch import pattern_registry
    pattern = pattern_registry.pattern_from_string("~glob::beep")
    pattern.compile()
    assert pattern.inverted