本文整理汇总了Python中test_utils.patch_open函数的典型用法代码示例。如果您正苦于以下问题:Python patch_open函数的具体用法?Python patch_open怎么用?Python patch_open使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了patch_open函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_add_known_host_exists_outdated
def test_add_known_host_exists_outdated(
self, check_output, host_key, rm, known_hosts):
check_output.return_value = '|1|= fookey'
host_key.return_value = '|1|= fookey_old'
with patch_open() as (_open, _file):
utils.add_known_host('foohost', None, None)
rm.assert_called_with('foohost', None, None)
示例2: test_add_known_host_exists
def test_add_known_host_exists(self, check_output, host_key, rm):
check_output.return_value = '|1|= fookey'
host_key.return_value = '|1|= fookey'
with patch_open() as (_open, _file):
utils.add_known_host('foohost')
self.assertFalse(rm.called)
self.assertFalse(_file.write.called)
示例3: test__set_sriov_numvfs
def test__set_sriov_numvfs(self, mock_sysnet_ints):
mock_sysnet_ints.side_effect = [{
'interface': 'eth2',
'mac_address': 'a8:9d:21:cf:93:fc',
'pci_address': '0000:10:00.0',
'state': 'up',
'sriov': True,
'sriov_totalvfs': 7,
'sriov_numvfs': 0
}], [{
'interface': 'eth2',
'mac_address': 'a8:9d:21:cf:93:fc',
'pci_address': '0000:10:00.0',
'state': 'up',
'sriov': True,
'sriov_totalvfs': 7,
'sriov_numvfs': 4
}]
dev = pci.PCINetDevice('0000:10:00.0')
self.assertEqual('eth2', dev.interface_name)
self.assertTrue(dev.sriov)
self.assertEqual(7, dev.sriov_totalvfs)
self.assertEqual(0, dev.sriov_numvfs)
with patch_open() as (mock_open, mock_file):
dev._set_sriov_numvfs(4)
mock_open.assert_called_with(
'/sys/class/net/eth2/device/sriov_numvfs', 'w')
mock_file.write.assert_called_with("4")
self.assertTrue(dev.sriov)
self.assertEqual(7, dev.sriov_totalvfs)
self.assertEqual(4, dev.sriov_numvfs)
示例4: test_import_keystone_cert
def test_import_keystone_cert(self, check_call):
self.relation_get.return_value = 'Zm9vX2NlcnQK'
with patch_open() as (_open, _file):
utils.import_keystone_ca_cert()
_open.assert_called_with(utils.CA_CERT_PATH, 'wb')
_file.write.assert_called_with('foo_cert\n')
check_call.assert_called_with(['update-ca-certificates'])
示例5: test_config_changed_upgrade_available
def test_config_changed_upgrade_available(self):
self.openstack_upgrade_available.return_value = True
self.relations_of_type.return_value = False
with patch_open() as (_open, _file):
_file.read.return_value = "foo"
hooks.config_changed()
self.assertTrue(self.do_openstack_upgrade.called)
self.assertTrue(self.CONFIGS.write_all.called)
示例6: test_get_sysnet_mac
def test_get_sysnet_mac(self, _update):
with patch_open() as (_open, _file):
super_fh = mocked_filehandle()
_file.readlines = MagicMock()
_open.side_effect = super_fh._setfilename
_file.read.side_effect = super_fh._getfilecontents_read
macaddr = pci.get_sysnet_mac('/sys/class/net/eth3')
self.assertEqual(macaddr, 'a8:9d:21:cf:93:fd')
示例7: test_secret_retrieved
def test_secret_retrieved(self, _path):
_path.exists.return_value = True
with patch_open() as (_open, _file):
_file.read.return_value = 'secret_thing\n'
self.assertEquals(context.get_shared_secret(),
'secret_thing')
_open.assert_called_with(
context.SHARED_SECRET.format('quantum'), 'r')
示例8: test_get_sysnet_device_state
def test_get_sysnet_device_state(self, _update):
with patch_open() as (_open, _file):
super_fh = mocked_filehandle()
_file.readlines = MagicMock()
_open.side_effect = super_fh._setfilename
_file.read.side_effect = super_fh._getfilecontents_read
state = pci.get_sysnet_device_state('/sys/class/net/eth3')
self.assertEqual(state, 'down')
示例9: test_config_changed_nrpe_master
def test_config_changed_nrpe_master(self):
self.openstack_upgrade_available.return_value = False
self.relations_of_type.return_value = True
with patch_open() as (_open, _file):
_file.read.return_value = "foo"
hooks.config_changed()
self.assertTrue(self.CONFIGS.write_all.called)
self.assertTrue(self.setup_rsync.called)
self.assertTrue(self.update_nrpe_config.called)
示例10: test_config_changed_ipv6
def test_config_changed_ipv6(self, mock_assert_charm_supports_ipv6):
self.test_config.set('prefer-ipv6', True)
self.openstack_upgrade_available.return_value = False
self.relations_of_type.return_value = False
with patch_open() as (_open, _file):
_file.read.return_value = "foo"
hooks.config_changed()
self.assertTrue(self.CONFIGS.write_all.called)
self.assertTrue(self.setup_rsync.called)
示例11: test_find_block_devices
def test_find_block_devices(self):
self.is_block_device.return_value = True
with patch_open() as (_open, _file):
_file.read.return_value = PROC_PARTITIONS
_file.readlines = MagicMock()
_file.readlines.return_value = PROC_PARTITIONS.split('\n')
result = swift_utils.find_block_devices()
ex = ['/dev/sdb', '/dev/vdb', '/dev/cciss/c1d0']
self.assertEquals(ex, result)
示例12: test_secret_created_stored
def test_secret_created_stored(self, _uuid4, _path):
_path.exists.return_value = False
_uuid4.return_value = 'secret_thing'
with patch_open() as (_open, _file):
self.assertEquals(context.get_shared_secret(),
'secret_thing')
_open.assert_called_with(
context.SHARED_SECRET.format('quantum'), 'w')
_file.write.assert_called_with('secret_thing')
示例13: test_config_changed_with_openstack_upgrade_action
def test_config_changed_with_openstack_upgrade_action(self):
self.openstack_upgrade_available.return_value = True
self.test_config.set('action-managed-upgrade', True)
with patch_open() as (_open, _file):
_file.read.return_value = "foo"
hooks.config_changed()
self.assertFalse(self.do_openstack_upgrade.called)
示例14: test_add_known_host_exists_added
def test_add_known_host_exists_added(
self, check_output, host_key, rm, known_hosts):
check_output.return_value = '|1|= fookey'
host_key.return_value = None
with patch_open() as (_open, _file):
_file.write = MagicMock()
utils.add_known_host('foohost')
self.assertFalse(rm.called)
_file.write.assert_called_with('|1|= fookey\n')
示例15: test_rsync_enable_rsync
def test_rsync_enable_rsync(self):
with patch_open() as (_open, _file):
ctxt = swift_context.RsyncContext()
_file.read.return_value = 'RSYNC_ENABLE=false'
ctxt.enable_rsyncd()
_file.write.assert_called_with('RSYNC_ENABLE=true')
_file.read.return_value = '#foo'
ctxt.enable_rsyncd()
_file.write.assert_called_with('RSYNC_ENABLE=true\n')