示例#1
0
def test_regexsearcher_uses_passed_config() -> None:
    """It uses the config passed to it."""
    config = RegexConfig()
    config._predefs["test"] = regex.compile("test")
    searcher = RegexSearcher(config=config)
    assert "test" in searcher._config._predefs
示例#2
0
def test_invalid_regexfor_regex_compile_raises_error(config: RegexConfig) -> None:
    """Using an invalid type raises a RegexParseError."""
    with pytest.raises(RegexParseError):
        config.parse_regex("[")
示例#3
0
def config() -> RegexConfig:
    """It returns a default regex config."""
    return RegexConfig(empty=False)
示例#4
0
def test_parse_regex_with_new_regex(config: RegexConfig) -> None:
    """It turns the string into a regex pattern."""
    assert config.parse_regex("(?i)Test",) == regex.compile("(?i)Test")
示例#5
0
def test_parse_regex_with_predef(config: RegexConfig) -> None:
    """It returns a predefined regex pattern."""
    assert config.parse_regex("phones", predef=True) == _commonregex["phones"]
示例#6
0
def test_get_predef_raises_error_with_undefined_regex(config: RegexConfig) -> None:
    """It raises a ValueError if predef is not actually predefined."""
    with pytest.raises(ValueError):
        config.get_predef("unknown")
示例#7
0
def test_get_predef_returns_existing_regex(config: RegexConfig) -> None:
    """It returns a predefined compiled regex pattern."""
    assert config.get_predef("times") == _commonregex["times"]
示例#8
0
def test_empty_regex_config() -> None:
    """Initializes it with empty attributes."""
    empty_rc = RegexConfig(empty=True)
    assert empty_rc._predefs == {}