Python pyfakefs.fake_filesystem.FakeOsModule() Examples
The following are 21
code examples of pyfakefs.fake_filesystem.FakeOsModule().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
pyfakefs.fake_filesystem
, or try the search function
.
Example #1
Source File: deploy_impl_test.py From loaner with Apache License 2.0 | 7 votes |
def setUp(self): super(DeployImplTest, self).setUp() # Save the real modules for clean up. self.real_open = builtins.open # Create a fake file system and stub out builtin modules. self.fs = fake_filesystem.FakeFilesystem() self.os = fake_filesystem.FakeOsModule(self.fs) self.open = fake_filesystem.FakeFileOpen(self.fs) self.shutil = fake_filesystem_shutil.FakeShutilModule(self.fs) self.stubs = mox3_stubout.StubOutForTesting() self.stubs.SmartSet(builtins, 'open', self.open) self.stubs.SmartSet(deploy_impl, 'os', self.os) self.stubs.SmartSet(deploy_impl, 'shutil', self.shutil) # Populate the fake file system with the expected directories and files. self.fs.CreateDirectory('/this/is/a/workspace/loaner/web_app/frontend/dist') self.fs.CreateDirectory('/this/is/a/workspace/loaner/chrome_app/dist') self.fs.CreateFile('/this/is/a/workspace/loaner/web_app/app.yaml') self.fs.CreateFile('/this/is/a/workspace/loaner/web_app/endpoints.yaml')
Example #2
Source File: utils.py From ara-archive with GNU General Public License v3.0 | 6 votes |
def playbook_treeview(playbook): """ Creates a fake filesystem with playbook files and uses generate_tree() to recurse and return a JSON structure suitable for bootstrap-treeview. """ fs = fake_filesystem.FakeFilesystem() mock_os = fake_filesystem.FakeOsModule(fs) files = models.File.query.filter(models.File.playbook_id.in_([playbook])) paths = {} for file in files: fs.CreateFile(file.path) paths[file.path] = file.id return jsonutils.dumps(generate_tree('/', paths, mock_os), sort_keys=True, indent=2)
Example #3
Source File: config_model_test.py From loaner with Apache License 2.0 | 6 votes |
def setUp(self): super(ConfigurationTest, self).setUp() # Save the real modules for clean up. self.real_open = __builtin__.open self.real_file = __builtin__.file self.fs = fake_filesystem.FakeFilesystem() self.os = fake_filesystem.FakeOsModule(self.fs) self.open = fake_filesystem.FakeFileOpen(self.fs) self.stubs = mox3_stubout.StubOutForTesting() self.stubs.SmartSet(__builtin__, 'open', self.open) self.stubs.SmartSet(os, 'path', self.os.path) config_file = constants.CONFIG_DEFAULTS_PATH self.fs.CreateFile(config_file, contents=_config_defaults_yaml) config_model.Config(id='string_config', string_value='config value 1').put() config_model.Config(id='integer_config', integer_value=1).put() config_model.Config(id='bool_config', bool_value=True).put() config_model.Config(id='list_config', list_value=['email1', 'email2']).put()
Example #4
Source File: installer_test.py From glazier with Apache License 2.0 | 6 votes |
def testBuildInfoSave(self, build_info, sv): fs = fake_filesystem.FakeFilesystem() installer.open = fake_filesystem.FakeFileOpen(fs) installer.os = fake_filesystem.FakeOsModule(fs) timer_root = r'{0}\{1}'.format(installer.constants.REG_ROOT, 'Timers') fs.CreateFile( '{}/build_info.yaml'.format(installer.constants.SYS_CACHE), contents='{BUILD: {opt 1: true, TIMER_opt 2: some value, opt 3: 12345}}\n' ) s = installer.BuildInfoSave(None, build_info) s.Run() sv.assert_has_calls([ mock.call('opt 1', True, 'HKLM', installer.constants.REG_ROOT), mock.call('TIMER_opt 2', 'some value', 'HKLM', timer_root), mock.call('opt 3', 12345, 'HKLM', installer.constants.REG_ROOT), ], any_order=True) s.Run()
Example #5
Source File: auth_test.py From loaner with Apache License 2.0 | 6 votes |
def setUp(self): super(AuthTest, self).setUp() self._test_project = 'test_project' self._test_client_id = 'test_client_id' self._test_client_secret = 'test_client_secret' self._test_config = common.ProjectConfig( 'test_key', self._test_project, self._test_client_id, self._test_client_secret, None, '/test/path.yaml') # Save the real modules for clean up. self.real_open = builtins.open # Create a fake file system and stub out builtin modules. self.fs = fake_filesystem.FakeFilesystem() self.os = fake_filesystem.FakeOsModule(self.fs) self.open = fake_filesystem.FakeFileOpen(self.fs) self.stubs = mox3_stubout.StubOutForTesting() self.stubs.SmartSet(builtins, 'open', self.open) self.stubs.SmartSet(auth, 'os', self.os)
Example #6
Source File: files_test.py From glazier with Apache License 2.0 | 5 votes |
def setUp(self): super(FilesTest, self).setUp() self.filesystem = fake_filesystem.FakeFilesystem() files.open = fake_filesystem.FakeFileOpen(self.filesystem) files.file_util.os = fake_filesystem.FakeOsModule(self.filesystem)
Example #7
Source File: common_test.py From googleads-python-lib with Apache License 2.0 | 5 votes |
def testLoadFromStorage_relativePath(self): fake_os = fake_filesystem.FakeOsModule(self.filesystem) yaml_contents = {'one': {'needed': 'd', 'keys': 'e'}} yaml_contents['one'].update(self._OAUTH_INSTALLED_APP_DICT) self.filesystem.CreateFile('/home/test/yaml/googleads.yaml', contents=yaml.dump(yaml_contents)) fake_os.chdir('/home/test') with mock.patch('googleads.oauth2.GoogleRefreshTokenClient') as mock_client: with mock.patch('googleads.common.os', fake_os): with mock.patch('googleads.common.open', self.fake_open, create=True): with mock.patch('googleads.common.ProxyConfig') as proxy_config: proxy_config.return_value = mock.Mock() rval = googleads.common.LoadFromStorage( 'yaml/googleads.yaml', 'one', ['needed', 'keys'], ['other']) proxy_config.assert_called_once_with( http_proxy=None, https_proxy=None, cafile=None, disable_certificate_validation=False) mock_client.assert_called_once_with( 'a', 'b', 'c', proxy_config=proxy_config.return_value) self.assertEqual({'oauth2_client': mock_client.return_value, 'proxy_config': proxy_config.return_value, 'needed': 'd', 'keys': 'e', googleads.common.ENABLE_COMPRESSION_KEY: False, googleads.common.CUSTOM_HEADERS_KEY: None}, rval) self.assertTrue(googleads.common._utility_registry._enabled)
Example #8
Source File: gng_impl_test.py From loaner with Apache License 2.0 | 5 votes |
def setUp(self): super(ManagerTest, self).setUp() # Save the real modules for clean up. self.real_open = builtins.open # Create a fake file system and stub out builtin modules. self.fs = fake_filesystem.FakeFilesystem() self.os = fake_filesystem.FakeOsModule(self.fs) self.open = fake_filesystem.FakeFileOpen(self.fs) self.stdout = StringIO() self.stubs = mox3_stubout.StubOutForTesting() self.stubs.SmartSet(builtins, 'open', self.open) self.stubs.SmartSet(common, 'os', self.os) self.stubs.SmartSet(sys, 'stdout', self.stdout) # Setup Testdata. self._testdata_path = '/testdata' self._valid_config_path = self._testdata_path + '/valid_config.yaml' self._blank_config_path = self._testdata_path + '/blank_config.yaml' self.fs.CreateFile(self._valid_config_path, contents=_VALID_CONFIG) self.fs.CreateFile(self._blank_config_path, contents=_BLANK_CONFIG) # Load the default config. self._valid_default_config = common.ProjectConfig.from_yaml( common.DEFAULT, self._valid_config_path) # Create test constants. self._constants = { 'test': app_constants.Constant( 'test', 'message', '', parser=utils.StringParser(allow_empty_string=False),), 'other': app_constants.Constant('other', 'other message', 'value'), } # Mock out the authentication credentials. self.auth_patcher = mock.patch.object(auth, 'CloudCredentials') self.mock_creds = self.auth_patcher.start() self.mock_creds.return_value.get_credentials.return_value = ( credentials.AnonymousCredentials())
Example #9
Source File: common_test.py From loaner with Apache License 2.0 | 5 votes |
def setUp(self): super(CommonTest, self).setUp() # Save the real modules for clean up. self.real_open = builtins.open # Create a fake file system and stub out builtin modules. self.fs = fake_filesystem.FakeFilesystem() self.os = fake_filesystem.FakeOsModule(self.fs) self.open = fake_filesystem.FakeFileOpen(self.fs) self.stubs = mox3_stubout.StubOutForTesting() self.stubs.SmartSet(builtins, 'open', self.open) self.stubs.SmartSet(common, 'os', self.os)
Example #10
Source File: autobuild_test.py From glazier with Apache License 2.0 | 5 votes |
def setUp(self, logs): super(BuildInfoTest, self).setUp() self.autobuild = autobuild.AutoBuild() autobuild.logging = logs.logging autobuild.logging.fatal.side_effect = LogFatalError() self.filesystem = fake_filesystem.FakeFilesystem() autobuild.os = fake_filesystem.FakeOsModule(self.filesystem)
Example #11
Source File: buildinfo_test.py From glazier with Apache License 2.0 | 5 votes |
def setUp(self): super(BuildInfoTest, self).setUp() # fake filesystem self.filesystem = fake_filesystem.FakeFilesystem() self.filesystem.CreateDirectory('/dev') buildinfo.os = fake_filesystem.FakeOsModule(self.filesystem) buildinfo.open = fake_filesystem.FakeFileOpen(self.filesystem) # setup mock_wmi = mock.patch.object( buildinfo.hw_info.wmi_query, 'WMIQuery', autospec=True) self.addCleanup(mock_wmi.stop) mock_wmi.start() self.buildinfo = buildinfo.BuildInfo()
Example #12
Source File: runner_test.py From glazier with Apache License 2.0 | 5 votes |
def setUp(self): super(ConfigRunnerTest, self).setUp() self.buildinfo = buildinfo.BuildInfo() constants.FLAGS.verify_urls = None # filesystem self.filesystem = fake_filesystem.FakeFilesystem() runner.os = fake_filesystem.FakeOsModule(self.filesystem) runner.open = fake_filesystem.FakeFileOpen(self.filesystem) runner.shutil = fake_filesystem_shutil.FakeShutilModule(self.filesystem) self.cr = runner.ConfigRunner(self.buildinfo) self.cr._task_list_path = '/tmp/task_list.yaml'
Example #13
Source File: chooser_test.py From glazier with Apache License 2.0 | 5 votes |
def setUp(self, tk): super(ChooserTest, self).setUp() self.ui = chooser.Chooser(_TEST_CONF, preload=False) self.tk = tk v1 = mock.Mock() v1.Value.return_value = 'value1' v2 = mock.Mock() v2.Value.return_value = 'value2' v3 = mock.Mock() v3.Value.return_value = 'value3' self.ui.fields = {'field1': v1, 'field2': v2, 'field3': v3} self.fs = fake_filesystem.FakeFilesystem() chooser.resources.os = fake_filesystem.FakeOsModule(self.fs) self.fs.CreateFile('/resources/logo.gif')
Example #14
Source File: download_test.py From glazier with Apache License 2.0 | 5 votes |
def setUp(self): super(DownloadTest, self).setUp() self._dl = download.BaseDownloader() # filesystem self.filesystem = fake_filesystem.FakeFilesystem() self.filesystem.CreateFile(r'C:\input.ini', contents=_TEST_INI) download.os = fake_filesystem.FakeOsModule(self.filesystem) download.open = fake_filesystem.FakeFileOpen(self.filesystem)
Example #15
Source File: cache_test.py From glazier with Apache License 2.0 | 5 votes |
def setUp(self): super(CacheTest, self).setUp() self.cache = cache.Cache() fs = fake_filesystem.FakeFilesystem() fs.CreateDirectory(r'C:\Directory') os_module = fake_filesystem.FakeOsModule(fs) self.mock_open = fake_filesystem.FakeFileOpen(fs) cache.os = os_module cache.open = self.mock_open
Example #16
Source File: execute_test.py From glazier with Apache License 2.0 | 5 votes |
def setUp(self): super(ExecuteTest, self).setUp() self.fs = fake_filesystem.FakeFilesystem() execute.os = fake_filesystem.FakeOsModule(self.fs) execute.open = fake_filesystem.FakeFileOpen(self.fs) self.binary = r'C:\foo.exe' self.fs.CreateFile(self.binary)
Example #17
Source File: sysprep_test.py From glazier with Apache License 2.0 | 5 votes |
def setUp(self): super(SysprepTest, self).setUp() fs = fake_filesystem.FakeFilesystem() fs.CreateDirectory('/windows/panther') fs.CreateFile('/windows/panther/unattend.xml', contents=UNATTEND_XML) self.fake_open = fake_filesystem.FakeFileOpen(fs) sysprep.os = fake_filesystem.FakeOsModule(fs) sysprep.open = self.fake_open
Example #18
Source File: beyondcorp_test.py From glazier with Apache License 2.0 | 5 votes |
def setUp(self): super(BeyondcorpTest, self).setUp() self.__saved_flags = flagsaver.save_flag_values() mock_wmi = mock.patch.object( beyondcorp.hw_info.wmi_query, 'WMIQuery', autospec=True) self.addCleanup(mock_wmi.stop) mock_wmi.start() self.filesystem = fake_filesystem.FakeFilesystem() self.filesystem.CreateFile(r'C:\seed.json', contents=_TEST_SEED) self.filesystem.CreateFile(beyondcorp.constants.USB_WIM, contents=_TEST_WIM) beyondcorp.os = fake_filesystem.FakeOsModule(self.filesystem) beyondcorp.open = fake_filesystem.FakeFileOpen(self.filesystem) self.beyondcorp = beyondcorp.BeyondCorp()
Example #19
Source File: identifier_test.py From glazier with Apache License 2.0 | 5 votes |
def setUp(self): super(IdentifierTest, self).setUp() mock_wmi = mock.patch.object( identifier.hw_info.wmi_query, 'WMIQuery', autospec=True) self.addCleanup(mock_wmi.stop) mock_wmi.start() self.fs = fake_filesystem.FakeFilesystem() identifier.open = fake_filesystem.FakeFileOpen(self.fs) identifier.os = fake_filesystem.FakeOsModule(self.fs)
Example #20
Source File: powershell_test.py From glazier with Apache License 2.0 | 5 votes |
def setUp(self): super(PowershellTest, self).setUp() self.fs = fake_filesystem.FakeFilesystem() powershell.os = fake_filesystem.FakeOsModule(self.fs) powershell.resources.os = fake_filesystem.FakeOsModule(self.fs) self.path = '/resources/bin/script.ps1' self.fs.CreateFile(self.path) self.ps = powershell.PowerShell()
Example #21
Source File: file_util_test.py From glazier with Apache License 2.0 | 5 votes |
def setUp(self): super(FileUtilTest, self).setUp() self.filesystem = fake_filesystem.FakeFilesystem() file_util.os = fake_filesystem.FakeOsModule(self.filesystem) file_util.open = fake_filesystem.FakeFileOpen(self.filesystem)