def test_regex_return(): regex = Regex(r"^RG(?P<the_number>\d{12})-sig\.pdf$") for path, valid, result in TESTDATA: if valid: dct = regex.run(path=path) assert dct == {"regex": {"the_number": result}}
def test_regex_umlaut(): regex = Regex(r"^Erträgnisaufstellung-(?P<year>\d*)\.pdf") doc = Path("~/Documents/Erträgnisaufstellung-1998.pdf") assert regex.matches(doc) dct = regex.run(path=doc) assert dct == {"regex": {"year": "1998"}}
def test_regex_basic(): regex = Regex(r"^RG(\d{12})-sig\.pdf$") for path, match, _ in TESTDATA: assert bool(regex.matches(path)) == match
def test_regex_backslash(): regex = Regex(r"^\.pdf$") assert regex.matches(Path(".pdf")) assert not regex.matches(Path("+pdf")) assert not regex.matches(Path("/pdf")) assert not regex.matches(Path("\\pdf"))
def test_regex_return(): regex = Regex('^RG(?P<the_number>\d{12})-sig\.pdf$') for path, valid, result in TESTDATA: if valid: attrs = regex.parse(path) assert attrs['regex'].the_number == result
def test_regex_basic(): regex = Regex('^RG(\d{12})-sig\.pdf$') for path, match, _ in TESTDATA: assert regex.matches(path) == match
def test_regex_backslash(): regex = Regex('^\.pdf$') assert regex.matches(Path('.pdf')) assert not regex.matches(Path('+pdf')) assert not regex.matches(Path('/pdf')) assert not regex.matches(Path('\pdf'))