-
Notifications
You must be signed in to change notification settings - Fork 91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support pathlib.Path parameter in create_dir() #409
Comments
Thanks for the report! Currently, |
I have converted to a def test_determine_labels(fs): #fs is the fake filesystem fixture
"""test the function that determines what labels exist in a directory"""
from pyfakefs.fake_filesystem_unittest import Patcher
with Patcher(use_dynamic_patch=True) as patcher:
import pathlib
base_dir = pathlib.Path('/tmp/corpus_data')
label_dir = base_dir / "label"
fs.create_dir(str(base_dir))
fs.create_dir(str(label_dir))
test_1_phonemes = 'ɖ ɯ ɕ i k v̩'
test_1_phonemes_and_tones = 'ɖ ɯ ˧ ɕ i ˧ k v̩ ˧˥'
test_2_phonemes = 'g v̩ tsʰ i g v̩ k v̩'
test_2_phonemes_and_tones = 'g v̩ ˧ tsʰ i ˩ g v̩ ˩ k v̩ ˩'
fs.create_file(str(label_dir / "test1.phonemes"), contents=test_1_phonemes)
fs.create_file(str(label_dir / "test1.phonemes_and_tones"), contents=test_1_phonemes_and_tones)
fs.create_file(str(label_dir / "test2.phonemes"), contents=test_2_phonemes)
fs.create_file(str(label_dir / "test2.phonemes_and_tones"), contents=test_1_phonemes_and_tones)
assert base_dir.exists()
assert label_dir.exists() This fails with the following: _________________________________ test_determine_labels _________________________________
fs = <pyfakefs.fake_filesystem.FakeFilesystem object at 0x7f3706e3ff28>
> ???
E AssertionError: assert False
E + where False = <bound method Path.exists of PosixPath('/tmp/corpus_data')>()
E + where <bound method Path.exists of PosixPath('/tmp/corpus_data')> = PosixPath('/tmp/corpus_data').exists
home/janis/persephone/persephone/tests/test_corpus.py:42: AssertionError Also I notice the stacktrace is not quite right here either with the Does this imply that pathlib operations can't be relied upon? |
Is the stacktrace issue related to #381? |
Exactly. This should be fixed in master for Python 3. |
The following works fine for me: # -*- coding: utf-8 -*-
import pathlib
def test_determine_labels(fs):
base_dir = pathlib.Path('/tmp/corpus_data')
label_dir = base_dir / "label"
fs.create_dir(str(base_dir))
fs.create_dir(str(label_dir))
test_1_phonemes = 'ɖ ɯ ɕ i k v̩'
fs.create_file(str(label_dir / "test1.phonemes"),
contents=test_1_phonemes, encoding='utf-8')
assert base_dir.exists()
assert label_dir.exists() Note that I had to add the utf-8 stuff because I tested this under Windows, where UTF-8 is not the default encoding - under Linux it should not be needed (though it would make the code more compatible). |
- concerns create_file(), create_dir(), create_symlink(), add_real_file() and add_real_directory() - closes pytest-dev#409
- concerns create_file(), create_dir(), create_symlink(), add_real_file() and add_real_directory() - closes #409
Thanks for the patch! |
I created a repository here to show the bug I am getting:
https://github.com/shuttle1987/pyfakefs-pathlib-fail
Essentially when this test is run:
The failure is as follows:
As far as I can tell from reading the documentation this library is supposed to patch
pathlib.Path
.The text was updated successfully, but these errors were encountered: