How to use the pyfakefs.fake_filesystem.FakeOsModule 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 / runners / test_push.py View on Github external
fs.CreateFile('policy.cfg_ml_commented',
              contents=('# a line comment\n'
                        'cluster-ceph/cluster/*.sls \t# with a comment'))
fs.CreateFile('policy.cfg_leading_whitespace',
              contents=(' cluster-ceph/cluster/*.sls'))
fs.CreateFile('policy.cfg_trailing_whitespace',
              contents=('cluster-ceph/cluster/*.sls '))
fs.CreateFile('policy.cfg_trailing_and_leading_whitespace',
              contents=(' cluster-ceph/cluster/*.sls '))
fs.CreateFile('policy.cfg_trailing_and_leading_whitespace_and_leading_comment',
              contents=(' #cluster-ceph/cluster/*.sls '))
fs.CreateFile('policy.cfg_trailing_and_leading_whitespace_and_trailing_comment',
              contents=(' cluster-ceph/cluster/*.sls #'))

f_glob = fake_glob.FakeGlobModule(fs)
f_os = fake_fs.FakeOsModule(fs)
f_open = fake_fs.FakeFileOpen(fs)


class TestPush():

    @patch('glob.glob', new=f_glob.glob)
    def test_parse(self):

        parsed = push._parse('{}/*.sls'.format(proposal_dir))
        assert len(parsed) == len(nodes)

        parsed = push._parse('{}/mon*.sls'.format(proposal_dir))
        assert len(parsed) == len([n for n in nodes if n.startswith('mon')])

        parsed = push._parse('{}/mon[1,2].sls'.format(proposal_dir))
        assert len(parsed) == 2
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
github SUSE / DeepSea / tests / unit / _modules / test_osd.py View on Github external
class TestOSDInstanceMethods():
    '''
    This class contains a set of functions that test srv.salt._modules.osd
    '''
    fs = fake_fs.FakeFilesystem()
    dev_dir = '/dev'
    devices = ['sda', 'sdaa', 'sda1', 'sda10', 'sdaa1', 'sdaa10',
               'sdax', 'sdax10',
               'nvme0n1', 'nvme1n1', 'nvme100n1', 'nvme0n1p1',
               'nvme0n1p100', 'nvme0n100', 'nvme1n1p1', 'nvme100n1p1']
    for dev in devices:
        fs.CreateFile('{}/{}'.format(dev_dir, dev))

    f_glob = fake_glob.FakeGlobModule(fs)
    f_os = fake_fs.FakeOsModule(fs)
    f_open = fake_fs.FakeFileOpen(fs)

    @mock.patch('srv.salt._modules.osd.glob')
    def test_devices(self, glob):
        glob.return_value.glob = []
        ret = osd.devices()
        glob.glob.assert_called_once()
        glob.glob.assert_called_with('/var/lib/ceph/osd/*')
        assert type(ret) is list

    @mock.patch('srv.salt._modules.osd.glob')
    def test_pairs(self, glob):
        glob.return_value.glob = []
        ret = osd.pairs()
        glob.glob.assert_called_once()
        glob.glob.assert_called_with('/var/lib/ceph/osd/*')
github SUSE / DeepSea / tests / unit / runners / test_ui_rgw.py View on Github external
import pytest
import salt.client
import os
from pyfakefs import fake_filesystem, fake_filesystem_glob

from mock import patch, MagicMock
import mock
from srv.modules.runners import ui_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():

    @patch('salt.client.LocalClient', autospec=True)
    @patch('salt.utils.master.MasterPillarUtil', autospec=True)
    @patch('os.path.exists', new=f_os.path.exists)
    @patch('__builtin__.open', new=f_open)
    @patch('glob.glob', new=f_glob.glob)
    def test_admin(self, masterpillarutil, localclient):
        result = {'urls': [],
                  'access_key': '12345',
                  'secret_key': 'abcdef',
                  'user_id': 'admin',
                  'success': True}
github crempp / mdweb / tests / test_index.py View on Github external
def setUp(self):
        """Create fake filesystem and flask app."""
        self.setUpPyfakefs()
        self.fake_os = fake_filesystem.FakeOsModule(self.fs)

        self.fs.CreateFile('/my/content/robots.txt')
        self.fs.CreateFile('/my/content/humans.txt')
        self.fs.CreateFile('/my/content/favicon.ico')
        self.fs.CreateFile('/my/content/crossdomain.xml')

        self.fs.CreateFile('/my/content/index.md')
        self.fs.CreateFile('/my/content/about/index.md')
        self.fs.CreateFile('/my/content/contact/index.md')

        self.fs.CreateFile('/my/theme/assets/robots.txt')
        self.fs.CreateFile('/my/theme/assets/css/style.css')
        self.fs.CreateFile('/my/theme/assets/js/site.js')
        self.fs.CreateFile('/my/theme/templates/layout.html')
        self.fs.CreateFile('/my/theme/templates/navigation.html')
        self.fs.CreateFile('/my/theme/templates/page.html')
github crempp / mdweb / tests / test_assets.py View on Github external
def setUp(self):
        """Create fake filesystem and flask app."""
        self.setUpPyfakefs()
        self.fake_os = fake_filesystem.FakeOsModule(self.fs)

        self.fs.CreateFile('/my/content/robots.txt')
        self.fs.CreateFile('/my/content/humans.txt')
        self.fs.CreateFile('/my/content/favicon.ico')
        self.fs.CreateFile('/my/content/crossdomain.xml')

        self.fs.CreateFile('/my/content/index.md')
        self.fs.CreateFile('/my/content/about/index.md')
        self.fs.CreateFile('/my/content/contact/index.md')
        self.fs.CreateFile('/my/content/assets/logo.png')

        self.fs.CreateFile('/my/theme/assets/robots.txt')
        self.fs.CreateFile('/my/theme/assets/css/style.css')
        self.fs.CreateFile('/my/theme/assets/js/site.js')
        self.fs.CreateFile('/my/theme/templates/layout.html')
        self.fs.CreateFile('/my/theme/templates/navigation.html')
github crempp / mdweb / tests / test_mdsite.py View on Github external
def create_app(self):
        """Create fake filesystem and flask app."""
        self.setUpPyfakefs()
        self.fake_os = fake_filesystem.FakeOsModule(self.fs)

        populate_fakefs(self)

        app = MDFakeFSTestSite(
            "MDWeb",
            app_options={}
        )
        app.start()

        return app
github jmcgeheeiv / pyfakefs / pyfakefs / fake_filesystem.py View on Github external
def st_atime(self):
        return (self._st_atime if FakeOsModule.stat_float_times()
                else int(self._st_atime))