blob: 273bb2e27179ca036da46956aaa8ce4387395982 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
import os
from conftest import create_filesystem, assertdir
from organize.cli import main
def test_file_content(tmp_path):
# inspired by https://github.com/tfeldmann/organize/issues/43
create_filesystem(
tmp_path,
files=[
("Test1.txt", "Lorem MegaCorp Ltd. ipsum\nInvoice 12345\nMore text\nID: 98765"),
("Test2.txt", "Tests"),
("Test3.txt", "My Homework ...")
],
config=r"""
rules:
- folders: files
filters:
- filecontent: 'MegaCorp Ltd.+^Invoice (?P<number>\w+)$.+^ID: 98765$'
actions:
- rename: "MegaCorp_Invoice_{filecontent.number}.txt"
- folders: files
filters:
- filecontent: '.*Homework.*'
actions:
- rename: "Homework.txt"
""",
)
main(["run", "--config-file=%s" % (tmp_path / "config.yaml")])
assertdir(tmp_path, "Homework.txt", "MegaCorp_Invoice_12345.txt", "Test2.txt")
|