Skip to content

Commit 626af70

Browse files
DummyPath.unlink raises NotADirectoryError
1 parent 84eeea3 commit 626af70

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

Lib/test/test_pathlib/test_pathlib_abc.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1493,6 +1493,10 @@ def open(self, mode='r', buffering=-1, encoding=None,
14931493
stream = io.TextIOWrapper(stream, encoding=encoding, errors=errors, newline=newline)
14941494
return stream
14951495

1496+
def touch(self):
1497+
with self.open('w'):
1498+
pass
1499+
14961500
def iterdir(self):
14971501
path = str(self.resolve())
14981502
if path in self._files:
@@ -1524,6 +1528,9 @@ def unlink(self, missing_ok=False):
15241528
path = str(path_obj)
15251529
name = path_obj.name
15261530
parent = str(path_obj.parent)
1531+
for interim_path in self.parents:
1532+
if str(interim_path) in self._files and not missing_ok:
1533+
raise NotADirectoryError(errno.ENOTDIR, "Not a directory", path)
15271534
if path in self._directories:
15281535
raise IsADirectoryError(errno.EISDIR, "Is a directory", path)
15291536
elif path in self._files:
@@ -1535,6 +1542,7 @@ def unlink(self, missing_ok=False):
15351542
elif not missing_ok:
15361543
raise FileNotFoundError(errno.ENOENT, "File not found", path)
15371544

1545+
15381546
def rmdir(self):
15391547
path_obj = self.parent.resolve(strict=True) / self.name
15401548
path = str(path_obj)

0 commit comments

Comments
 (0)