Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tfeldmann committed Jan 12, 2024
1 parent ef71134 commit 0ebf8bd
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
3 changes: 1 addition & 2 deletions organize/filters/created.py
Expand Up @@ -25,9 +25,8 @@ def read_stat_created(path: Path) -> Optional[int]:


def read_created(path: Path) -> datetime:
stat_result = path.stat()

timestamp = None
stat_result = path.stat()

# ctime is the creation time only in Windows.
# On unix it's the datetime of the last metadata change.
Expand Down
9 changes: 8 additions & 1 deletion tests/filters/test_created.py
@@ -1,8 +1,9 @@
from datetime import timedelta
from datetime import date, timedelta

from arrow import now as arrow_now

from organize.filters import Created
from organize.filters.created import read_created


def test_min():
Expand All @@ -17,3 +18,9 @@ def test_max():
ct = Created(days=10, hours=12, mode="newer")
assert ct.matches_datetime(now - timedelta(days=10, hours=0))
assert not ct.matches_datetime(now - timedelta(days=10, hours=13))


def test_read_created(tmp_path):
f = tmp_path / "file.txt"
f.touch()
assert read_created(f).date() == date.today()
19 changes: 18 additions & 1 deletion tests/filters/test_lastmodified.py
@@ -1,5 +1,5 @@
import os
from datetime import datetime, timedelta
from datetime import date, datetime, timedelta

from arrow import now as arrow_now
from conftest import make_files, read_files
Expand Down Expand Up @@ -45,3 +45,20 @@ def test_photo_sorting(fs):
"2000": {"01": {"12": {"photo1": ""}}},
"2020": {"01": {"01": {"photo2": "", "photo3": ""}}},
}


def test_date_formatting(fs, testoutput):
make_files(["test.txt"], "/test")
config = """
rules:
- locations: /test
filters:
- lastmodified
actions:
- echo: "moving to {lastmodified.strftime('%Y%m%d - test.txt')}"
- move: "/test/moved/{lastmodified.strftime('%Y%m%d - test.txt')}"
"""
Config.from_string(config).execute(simulate=False, output=testoutput)
new_name = f"{date.today():%Y%m%d} - test.txt"
testoutput.messages == [f"Created at {new_name}"]
assert read_files("/test/moved") == {new_name: ""}

0 comments on commit 0ebf8bd

Please sign in to comment.