Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
joshua-auchincloss committed Apr 28, 2024
1 parent 52359eb commit ced23fc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/hatch_cython/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
def stale(src: str, dest: str):
if not os.path.exists(src) or not os.path.exists(dest):
return True
return (os.path.getmtime(src) > os.path.getmtime(dest)) or (os.path.getctime(src) > os.path.getctime(dest))
return (os.path.getmtime(src) >= os.path.getmtime(dest)) or (os.path.getctime(src) >= os.path.getctime(dest))


def memo(func: CallableT[P, T]) -> CallableT[P, T]:
Expand Down
12 changes: 12 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from time import sleep

import pytest

from src.hatch_cython.utils import memo, stale
Expand Down Expand Up @@ -47,6 +49,11 @@ def test_stale(new_tmp_dir):
src.write_text("hello world")
dest.write_text("hello world")

# mtime may not be within resolution to run tests consistently, so we need to wait for sys
# to reflect the modification times
# https://stackoverflow.com/questions/19059877/python-os-path-getmtime-time-not-changing
sleep(5)

assert not stale(
str(src),
str(dest),
Expand All @@ -55,12 +62,17 @@ def test_stale(new_tmp_dir):
with src.open("w") as f:
f.write("now stale")

sleep(5)

assert stale(
str(src),
str(dest),
)

dest.unlink()

sleep(5)

assert stale(
str(src),
str(dest),
Expand Down

0 comments on commit ced23fc

Please sign in to comment.