Skip to content

Commit

Permalink
Merge pull request #29 from con/test-win
Browse files Browse the repository at this point in the history
Get tests to pass on Windows and macOS
  • Loading branch information
yarikoptic authored Feb 22, 2021
2 parents 11f339d + 7f63dbd commit c715dea
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ on:

jobs:
test:
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- macos-latest
- ubuntu-latest
- windows-latest
python-version:
- '3.6'
- '3.7'
Expand Down
18 changes: 9 additions & 9 deletions src/fscacher/tests/test_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,15 +191,15 @@ def check_new_memoread(arg, content, expect_new=False):
assert len(calls) == 2

path.mkdir()
(path / "a.txt").write_text("Alpha\n")
(path / "b.txt").write_text("Beta\n")
(path / "a.txt").write_text("Alpha")
(path / "b.txt").write_text("Beta")

t0 = time.time()
try:
# unless this computer is too slow -- there should be less than
# cache._min_dtime between our creating the file and testing,
# so we would force a direct read:
check_new_memoread(0, 11, True)
check_new_memoread(0, 9, True)
except AssertionError: # pragma: no cover
# if computer is indeed slow (happens on shared CIs) we might fail
# because distance is too short
Expand All @@ -209,17 +209,17 @@ def check_new_memoread(arg, content, expect_new=False):

# but if we sleep - should memoize
time.sleep(cache._min_dtime * 1.1)
check_new_memoread(1, 11)
check_new_memoread(1, 9)

# and if we modify the file -- a new read
time.sleep(cache._min_dtime * 1.1)
(path / "c.txt").write_text("Gamma\n")
(path / "c.txt").write_text("Gamma")
ncalls = len(calls)
assert memoread(path, 1) == 17
assert memoread(path, 1) == 14
assert len(calls) == ncalls + 1

time.sleep(cache._min_dtime * 1.1)
check_new_memoread(0, 17)
check_new_memoread(0, 14)

# Check that symlinks should be dereferenced
if not on_windows or sys.version_info[:2] >= (3, 8):
Expand All @@ -232,12 +232,12 @@ def check_new_memoread(arg, content, expect_new=False):
pass
if op.islink(symlink1): # hopefully would just skip Windows if not supported
ncalls = len(calls)
assert memoread(symlink1, 0) == 17
assert memoread(symlink1, 0) == 14
assert len(calls) == ncalls # no new call

# and if we "clear", would it still work?
cache.clear()
check_new_memoread(1, 17)
check_new_memoread(1, 14)


def test_memoize_path_persist(tmp_path):
Expand Down

0 comments on commit c715dea

Please sign in to comment.