Skip to content
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

CreateDirectory with fake directory content #347

Closed
gsemet opened this issue Feb 8, 2018 · 3 comments
Closed

CreateDirectory with fake directory content #347

gsemet opened this issue Feb 8, 2018 · 3 comments

Comments

@gsemet
Copy link

gsemet commented Feb 8, 2018

Hello

Is it possible to have a mix of CreateDirectory and add_real_directory, where I can define a fake directory but matching the content of an existing directory (but not with the same path)?

I am looking for an equivalent of this code:

def map_directory(fs, real_dir: Union[str, Path], fake_path: Union[str, Path]):
    if isinstance(real_dir, str):
        real_dir = Path(real_dir)
    if isinstance(fake_path, str):
        fake_path = Path(fake_path)
    fs.CreateDirectory(str(real_dir))
    for fil in real_dir.iterdir():
        if not fil.is_file():
            continue
        with fil.open() as f:
            fake_fil = fake_path / fil.name
            log.debug("Mapping fake file", real_path=str(fil), fake_path=str(fake_fil))
            fs.CreateFile(str(fake_fil), contents=f.read())

thanks

@mrbean-bremen
Copy link
Member

No, that is not possible directly.
We could add an additional destination argument to add_real_directory() and add_real_file() (but probably not to add_real_paths()).

mrbean-bremen added a commit to mrbean-bremen/pyfakefs that referenced this issue Feb 8, 2018
- allows to map real file system files and directories
  to another location in the fake file system
- see pytest-dev#347
mrbean-bremen added a commit that referenced this issue Feb 8, 2018
- allows to map real file system files and directories
  to another location in the fake file system
- see #347
@mrbean-bremen
Copy link
Member

Ok, I added a new argument target_path in master - please check, if this is what you need.

@gsemet
Copy link
Author

gsemet commented Feb 8, 2018

looks great !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants