当前位置: 首页>>代码示例>>Python>>正文


Python test_utils.patch_open函数代码示例

本文整理汇总了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)
开发者ID:BillTheBest,项目名称:hyper-c,代码行数:7,代码来源:test_nova_cc_utils.py

示例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)
开发者ID:BillTheBest,项目名称:hyper-c,代码行数:7,代码来源:test_nova_cc_utils.py

示例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)
开发者ID:openstack,项目名称:charm-neutron-openvswitch,代码行数:32,代码来源:test_pci.py

示例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'])
开发者ID:ryan-beisner,项目名称:charm-nova-compute-ppc64el,代码行数:7,代码来源:test_nova_compute_utils.py

示例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)
开发者ID:chrisglass,项目名称:charm-swift-storage,代码行数:8,代码来源:test_swift_storage_relations.py

示例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')
开发者ID:openstack,项目名称:charm-neutron-openvswitch,代码行数:8,代码来源:test_pci.py

示例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')
开发者ID:gnuoy,项目名称:charm-neutron-openvswitch,代码行数:8,代码来源:test_neutron_ovs_context.py

示例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')
开发者ID:openstack,项目名称:charm-neutron-openvswitch,代码行数:8,代码来源:test_pci.py

示例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)
开发者ID:chrisglass,项目名称:charm-swift-storage,代码行数:9,代码来源:test_swift_storage_relations.py

示例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)
开发者ID:chrisglass,项目名称:charm-swift-storage,代码行数:9,代码来源:test_swift_storage_relations.py

示例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)
开发者ID:CiscoSystems,项目名称:jujucharm-n1k,代码行数:9,代码来源:test_swift_storage_utils.py

示例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')
开发者ID:gnuoy,项目名称:charm-neutron-openvswitch,代码行数:9,代码来源:test_neutron_ovs_context.py

示例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)
开发者ID:chrisglass,项目名称:charm-swift-storage,代码行数:9,代码来源:test_swift_storage_relations.py

示例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')
开发者ID:BillTheBest,项目名称:hyper-c,代码行数:9,代码来源:test_nova_cc_utils.py

示例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')
开发者ID:chrisglass,项目名称:charm-swift-storage,代码行数:9,代码来源:test_swift_storage_context.py


注:本文中的test_utils.patch_open函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。