Skip to content

Commit

Permalink
Actually fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
barneygale committed Oct 4, 2023
1 parent 8403085 commit d0068cc
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions Lib/test/test_pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -1672,9 +1672,8 @@ class DummyPath(pathlib._PathBase):
Simple implementation of PathBase that keeps files and directories in
memory.
"""
pathmod = posixpath
_files = {}
_directories = {'/': set()}
_directories = {}
_symlinks = {}

def stat(self, *, follow_symlinks=True):
Expand Down Expand Up @@ -1731,17 +1730,21 @@ def iterdir(self):
raise FileNotFoundError(errno.ENOENT, "File not found", path)

def mkdir(self, mode=0o777, parents=False, exist_ok=False):
path = str(self.resolve())
if path in self._directories:
if exist_ok:
return
else:
raise FileExistsError(errno.EEXIST, "File exists", path)
try:
self._directories[str(self.parent)].add(self.name)
self._directories[str(self)] = set()
if self.name:
self._directories[str(self.parent)].add(self.name)
self._directories[path] = set()
except KeyError:
if not parents or self.parent == self:
if not parents:
raise FileNotFoundError(errno.ENOENT, "File not found", str(self.parent)) from None
self.parent.mkdir(parents=True, exist_ok=True)
self.mkdir(mode, parents=False, exist_ok=exist_ok)
except FileExistsError:
if not exist_ok:
raise


class DummyPathTest(unittest.TestCase):
Expand Down Expand Up @@ -1802,7 +1805,6 @@ def tearDown(self):
cls._files.clear()
cls._directories.clear()
cls._symlinks.clear()
cls._directories['/'] = set()

def tempdir(self):
path = self.cls(BASE).with_name('tmp-dirD')
Expand Down

0 comments on commit d0068cc

Please sign in to comment.