use Pathlib instead of path splitting
This commit is contained in:
parent
ee30bf45c9
commit
c4c666cbc4
|
@ -13,11 +13,10 @@ import attr
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
import json
|
import json
|
||||||
from os.path import sep as _sep, altsep as _altsep
|
|
||||||
import shutil
|
import shutil
|
||||||
|
|
||||||
from . import paths
|
from . import paths
|
||||||
from .compat import _PY2 as PY2
|
from .compat import _PY2 as PY2, Path
|
||||||
|
|
||||||
README_CONTENT = u"""\
|
README_CONTENT = u"""\
|
||||||
# pytest cache directory #
|
# pytest cache directory #
|
||||||
|
@ -62,14 +61,15 @@ class Cache(object):
|
||||||
Make sure the name contains your plugin or application
|
Make sure the name contains your plugin or application
|
||||||
identifiers to prevent clashes with other cache users.
|
identifiers to prevent clashes with other cache users.
|
||||||
"""
|
"""
|
||||||
if _sep in name or _altsep is not None and _altsep in name:
|
name = Path(name)
|
||||||
|
if len(name.parts) > 1:
|
||||||
raise ValueError("name is not allowed to contain path separators")
|
raise ValueError("name is not allowed to contain path separators")
|
||||||
res = self._cachedir.joinpath("d", name)
|
res = self._cachedir.joinpath("d", name)
|
||||||
res.mkdir(exist_ok=True, parents=True)
|
res.mkdir(exist_ok=True, parents=True)
|
||||||
return py.path.local(res)
|
return py.path.local(res)
|
||||||
|
|
||||||
def _getvaluepath(self, key):
|
def _getvaluepath(self, key):
|
||||||
return self._cachedir.joinpath("v", *key.split("/"))
|
return self._cachedir.joinpath("v", Path(key))
|
||||||
|
|
||||||
def get(self, key, default):
|
def get(self, key, default):
|
||||||
""" return cached value for the given key. If no value
|
""" return cached value for the given key. If no value
|
||||||
|
|
Loading…
Reference in New Issue