How to use the pyfakefs.fake_filesystem.FakeFileOpen function in pyfakefs

To help you get started, we’ve selected a few pyfakefs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github SUSE / DeepSea / tests / unit / _modules / test_rgw.py View on Github external
import pytest
import salt.client
import os
import sys
sys.path.insert(0, 'srv/salt/_modules')
from pyfakefs import fake_filesystem, fake_filesystem_glob
from mock import patch, MagicMock
from srv.salt._modules import rgw

fs = fake_filesystem.FakeFilesystem()
f_glob = fake_filesystem_glob.FakeGlobModule(fs)
f_os = fake_filesystem.FakeOsModule(fs)
f_open = fake_filesystem.FakeFileOpen(fs)

class TestRadosgw():

    pass
github googleapis / artman / test / utils / test_github_utils.py View on Github external
@mock.patch.object(github_utils, 'open', side_effect=fake_fs.FakeFileOpen(fs))
@mock.patch('os.access', side_effect=os_module.access)
@mock.patch('os.path.isfile', side_effect=os_module.path.isfile)
@mock.patch('os.path.isdir', side_effect=os_module.path.isdir)
@mock.patch('os.listdir', side_effect=os_module.listdir)
@mock.patch('requests.patch', return_value=_PATCH_RETURN_VAL)
@mock.patch('requests.post', side_effect=_POST_SIDE_EFFECT)
@mock.patch('requests.get', side_effect=_GET_SIDE_EFFECT)
def test_github_utils_task(mock_get, mock_post, mock_patch, mock_listdir,
                           mock_isdir, mock_isfile, mock_access, mock_open):
    github_utils.push_dir_to_github('/', _USERNAME, _PASSWORD, _OWNER,
                                    _REPO, _BRANCH, _MESSAGE)
    mock_get.assert_has_calls(_EXPECTED_GET_ARGS)
    mock_post.assert_has_calls(_EXPECTED_POST_ARGS)
    mock_patch.assert_has_calls(_EXPECTED_PATCH_ARGS)
github SUSE / DeepSea / tests / unit / _modules / test_subvolume.py View on Github external
import pytest
import salt.client
import os
import sys
sys.path.insert(0, 'srv/salt/_modules')
from pyfakefs import fake_filesystem, fake_filesystem_glob
from mock import patch, MagicMock, mock
from srv.salt._modules import subvolume

fs = fake_filesystem.FakeFilesystem()
f_glob = fake_filesystem_glob.FakeGlobModule(fs)
f_os = fake_filesystem.FakeOsModule(fs)
f_open = fake_filesystem.FakeFileOpen(fs)

class Testsubvolume():

    @patch('srv.salt._modules.subvolume._btrfs')
    def test_check_mounted(self, mockb):
        mockb.return_value = [True, True]
        state, msg = subvolume.check()
        assert state == True
        assert msg == "/var/lib/ceph subvolume mounted"

    @patch('srv.salt._modules.subvolume._btrfs')
    def test_check_not_btrfs(self, mockb):
        mockb.return_value = [False, False]
        state, msg = subvolume.check()
        assert state == True
        assert msg == "/ is not btrfs"
github jmcgeheeiv / pyfakefs / tests / test_utils.py View on Github external
def setUp(self):
        self.cwd = os.getcwd()
        if not self.use_real_fs():
            self.filesystem = fake_filesystem.FakeFilesystem(
                path_separator=self.path_separator())
            self.open = fake_filesystem.FakeFileOpen(self.filesystem)
            self.os = fake_filesystem.FakeOsModule(self.filesystem)
            self.create_basepath()
        self.setUpFileSystem()
github KanoComputing / kano-settings / features / steps / boot_config.py View on Github external
def ensure_only_change(ctx, edid):
    with open(BOOT_CONFIG_FILEPATH, 'r') as f:
        new_boot_config = f.readlines()

    original_fs = fake_fs.FakeFileOpen(ctx.backup_fs)
    original_boot_config = [l for l in original_fs(BOOT_CONFIG_FILEPATH)]

    diff = Diff(original_boot_config, new_boot_config)

    assert ctx.new_res.get('mode_line') in diff.added
    assert ctx.original_res.get('mode_line') in diff.removed
github jmcgeheeiv / pyfakefs / pyfakefs / fake_pathlib.py View on Github external
def read_text(self, encoding=None, errors=None):
        """
        Open the fake file in text mode, read it, and close the file.
        """
        with FakeFileOpen(self.filesystem)(self._path(), mode='r',
                                           encoding=encoding,
                                           errors=errors) as f:
            return f.read()
github kobayashi / s3monkey / s3monkey / pyfakefs / fake_pathlib.py View on Github external
def read_text(self, encoding=None, errors=None):
            """
            Open the fake file in text mode, read it, and close the file.
            """
            with FakeFileOpen(self.filesystem)(self._path(), mode='r', encoding=encoding,
                                               errors=errors) as f:
                return f.read()
github kobayashi / s3monkey / s3monkey / pyfakefs / fake_pathlib.py View on Github external
def open(self, mode='r', buffering=-1, encoding=None,
             errors=None, newline=None):
        """Open the file pointed by this path and return a fake file object.

        Raises:
            IOError: if the target object is a directory, the path is invalid or
                permission is denied.
        """
        if self._closed:
            self._raise_closed()
        return FakeFileOpen(self.filesystem)(
            self._path(), mode, buffering, encoding, errors, newline)
github jmcgeheeiv / pyfakefs / pyfakefs / fake_pathlib.py View on Github external
def read_bytes(self):
        """Open the fake file in bytes mode, read it, and close the file.

        Raises:
            IOError: if the target object is a directory, the path is
                invalid or permission is denied.
        """
        with FakeFileOpen(self.filesystem)(self._path(), mode='rb') as f:
            return f.read()