Support pathlib.Path parameter in create_dir()
See original GitHub issueI created a repository here to show the bug I am getting: https://github.com/shuttle1987/pyfakefs-pathlib-fail
Essentially when this test is run:
def test_pathlib(fs): #fs is the fake filesystem fixture
"""Attempt to use a pathlib path"""
import pathlib
base_dir = pathlib.Path('/tmp/corpus_data')
fs.create_dir(base_dir)
from example_lib.searcher import determine_labels
The failure is as follows:
$ python -m pytest
================================================ test session starts ================================================
platform linux -- Python 3.5.2, pytest-3.6.0, py-1.5.3, pluggy-0.6.0
rootdir: /home/janis/pyfakefs-pathlib-fail, inifile:
plugins: cov-2.5.1, pyfakefs-3.4.1
collected 1 item
tests/test_example.py F [100%]
===================================================== FAILURES ======================================================
___________________________________________________ test_pathlib ____________________________________________________
fs = <pyfakefs.fake_filesystem.FakeFilesystem object at 0x7f03fc2b9a90>
> ???
home/janis/pyfakefs-pathlib-fail/tests/test_example.py:6:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
home/janis/pyfakefs-pathlib-fail/venv/lib/python3.5/site-packages/pyfakefs/fake_filesystem.py:2137: in create_dir
???
home/janis/pyfakefs-pathlib-fail/venv/lib/python3.5/site-packages/pyfakefs/fake_filesystem.py:1362: in absnormpath
???
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pyfakefs.fake_filesystem.FakeFilesystem object at 0x7f03fc2b9a90>, file_path = PosixPath('/tmp/corpus_data')
> ???
E AttributeError: 'PosixPath' object has no attribute 'startswith'
home/janis/pyfakefs-pathlib-fail/venv/lib/python3.5/site-packages/pyfakefs/fake_filesystem.py:1578: AttributeError
============================================= 1 failed in 0.12 seconds ==============================================
As far as I can tell from reading the documentation this library is supposed to patch pathlib.Path.
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
pathlib — Object-oriented filesystem paths — Python 3.11.1 ...
Source code: Lib/pathlib.py This module offers classes representing filesystem paths with semantics appropriate for different operating systems.
Read more >python - explanation of pathlib.Path.mkdir mode argument
If mode is given, it is combined with the process' umask value to determine the file mode and access flags. import pathlib pathlib.Path("/tmp/ ......
Read more >How to use the pathlib.Path.mkdir function in pathlib - Snyk
To help you get started, we've selected a few pathlib. ... path_pre = Path.cwd() path_tmp = Path(tempfile.mkdtemp()) path_test_dir = Path(__file__).parent ...
Read more >Python Path – How to Use the Pathlib Module with Examples
According to the official documentation, the .mkdir() method takes three arguments. We will focus only at the moment on parents and exist_ok ....
Read more >pathlib — Filesystem Paths as Objects — PyMOTW 3
pathlib includes classes for managing filesystem paths formatted using either the POSIX ... If the path already exists, mkdir() raises a FileExistsError ....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Thanks for the report! Currently,
create_diris not designed to take aPathparameter, so you have to convert it to a string first, e.g.fs.create_dir (str (base_dir)). But I agree that it would make sense to support this - I will adapt it accordingly.Thanks for the patch!