Skip to content

Commit

Permalink
Support pathlib.Path as directory argument
Browse files Browse the repository at this point in the history
  • Loading branch information
grantjenks committed Apr 18, 2023
1 parent cffbcec commit f81160f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions diskcache/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,7 @@ def __init__(self, directory=None, timeout=60, disk=Disk, **settings):

if directory is None:
directory = tempfile.mkdtemp(prefix='diskcache-')
directory = str(directory)
directory = op.expanduser(directory)
directory = op.expandvars(directory)

Expand Down
1 change: 1 addition & 0 deletions diskcache/fanout.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def __init__(
"""
if directory is None:
directory = tempfile.mkdtemp(prefix='diskcache-')
directory = str(directory)
directory = op.expanduser(directory)
directory = op.expandvars(directory)

Expand Down
8 changes: 8 additions & 0 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import io
import os
import os.path as op
import pathlib
import pickle
import shutil
import sqlite3
Expand Down Expand Up @@ -37,6 +38,13 @@ def test_init(cache):
cache.close()


def test_init_path(cache):
path = pathlib.Path(cache.directory)
other = dc.Cache(path)
other.close()
assert cache.directory == other.directory


def test_init_disk():
with dc.Cache(disk_pickle_protocol=1, disk_min_file_size=2**20) as cache:
key = (None, 0, 'abc')
Expand Down
8 changes: 8 additions & 0 deletions tests/test_fanout.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import io
import os
import os.path as op
import pathlib
import pickle
import shutil
import subprocess as sp
Expand Down Expand Up @@ -44,6 +45,13 @@ def test_init(cache):
cache.check()


def test_init_path(cache):
path = pathlib.Path(cache.directory)
other = dc.FanoutCache(path)
other.close()
assert cache.directory == other.directory


def test_set_get_delete(cache):
for value in range(100):
cache.set(value, value)
Expand Down

0 comments on commit f81160f

Please sign in to comment.