當前位置: 首頁>>代碼示例>>Python>>正文


Python fixtures.MonkeyPatch方法代碼示例

本文整理匯總了Python中fixtures.MonkeyPatch方法的典型用法代碼示例。如果您正苦於以下問題:Python fixtures.MonkeyPatch方法的具體用法?Python fixtures.MonkeyPatch怎麽用?Python fixtures.MonkeyPatch使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在fixtures的用法示例。


在下文中一共展示了fixtures.MonkeyPatch方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: setUp

# 需要導入模塊: import fixtures [as 別名]
# 或者: from fixtures import MonkeyPatch [as 別名]
def setUp(self):
        "Run before each test method to initialize test environment."

        super(TestCase, self).setUp()
        test_timeout = os.environ.get('OS_TEST_TIMEOUT', 0)
        try:
            test_timeout = int(test_timeout)
        except ValueError:
            # If timeout value is invalid do not set a timeout.
            test_timeout = 0
        if test_timeout > 0:
            self.useFixture(fixtures.Timeout(test_timeout, gentle=True))

        self.useFixture(fixtures.NestedTempfile())
        self.useFixture(fixtures.TempHomeDir())

        if os.environ.get('OS_STDOUT_CAPTURE') in _TRUE_VALUES:
            stdout = self.useFixture(fixtures.StringStream('stdout')).stream
            self.useFixture(fixtures.MonkeyPatch('sys.stdout', stdout))
        if os.environ.get('OS_STDERR_CAPTURE') in _TRUE_VALUES:
            stderr = self.useFixture(fixtures.StringStream('stderr')).stream
            self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr))

        self.log_fixture = self.useFixture(fixtures.FakeLogger()) 
開發者ID:softwarefactory-project,項目名稱:DLRN,代碼行數:26,代碼來源:base.py

示例2: setUp

# 需要導入模塊: import fixtures [as 別名]
# 或者: from fixtures import MonkeyPatch [as 別名]
def setUp(self):
        """Run before each test method to initialize test environment."""

        super(TestCase, self).setUp()
        test_timeout = os.environ.get('OS_TEST_TIMEOUT', 0)
        try:
            test_timeout = int(test_timeout)
        except ValueError:
            # If timeout value is invalid do not set a timeout.
            test_timeout = 0
        if test_timeout > 0:
            self.useFixture(fixtures.Timeout(test_timeout, gentle=True))

        self.useFixture(fixtures.NestedTempfile())
        self.useFixture(fixtures.TempHomeDir())

        if os.environ.get('OS_STDOUT_CAPTURE') in _TRUE_VALUES:
            stdout = self.useFixture(fixtures.StringStream('stdout')).stream
            self.useFixture(fixtures.MonkeyPatch('sys.stdout', stdout))
        if os.environ.get('OS_STDERR_CAPTURE') in _TRUE_VALUES:
            stderr = self.useFixture(fixtures.StringStream('stderr')).stream
            self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr))

        self.log_fixture = self.useFixture(fixtures.FakeLogger()) 
開發者ID:openstack,項目名稱:bashate,代碼行數:26,代碼來源:base.py

示例3: setUp

# 需要導入模塊: import fixtures [as 別名]
# 或者: from fixtures import MonkeyPatch [as 別名]
def setUp(self):
        self.LOG.info('Starting: %s', self._testMethodName)
        super(TestCase, self).setUp()

        self.client = client.BarbicanClient()

        stdout_capture = os.environ.get('OS_STDOUT_CAPTURE')
        stderr_capture = os.environ.get('OS_STDERR_CAPTURE')
        log_capture = os.environ.get('OS_LOG_CAPTURE')

        if ((stdout_capture and stdout_capture.lower() == 'true') or
                stdout_capture == '1'):
            stdout = self.useFixture(fixtures.StringStream('stdout')).stream
            self.useFixture(fixtures.MonkeyPatch('sys.stdout', stdout))
        if ((stderr_capture and stderr_capture.lower() == 'true') or
                stderr_capture == '1'):
            stderr = self.useFixture(fixtures.StringStream('stderr')).stream
            self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr))
        if ((log_capture and log_capture.lower() == 'true') or
                log_capture == '1'):
            self.useFixture(fixtures.LoggerFixture(nuke_handlers=False,
                                                   format=self.log_format,
                                                   level=logging.DEBUG)) 
開發者ID:cloud-security-research,項目名稱:sgx-kms,代碼行數:25,代碼來源:base.py

示例4: setUp

# 需要導入模塊: import fixtures [as 別名]
# 或者: from fixtures import MonkeyPatch [as 別名]
def setUp(self):
        """Run before each test method to initialize test environment."""

        super(TestCase, self).setUp()
        test_timeout = os.environ.get('OS_TEST_TIMEOUT', 0)
        try:
            test_timeout = int(test_timeout)
        except ValueError:
            # If timeout value is invalid do not set a timeout.
            test_timeout = 0
        if test_timeout > 0:
            self.useFixture(fixtures.Timeout(test_timeout, gentle=True))

        self.useFixture(fixtures.NestedTempfile())
        self.temp_homedir = self.useFixture(fixtures.TempHomeDir()).path

        if os.environ.get('OS_STDOUT_CAPTURE') in _TRUE_VALUES:
            stdout = self.useFixture(fixtures.StringStream('stdout')).stream
            self.useFixture(fixtures.MonkeyPatch('sys.stdout', stdout))
        if os.environ.get('OS_STDERR_CAPTURE') in _TRUE_VALUES:
            stderr = self.useFixture(fixtures.StringStream('stderr')).stream
            self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr))

        self.log_fixture = self.useFixture(fixtures.FakeLogger()) 
開發者ID:openstack,項目名稱:python-tripleoclient,代碼行數:26,代碼來源:base.py

示例5: setUp

# 需要導入模塊: import fixtures [as 別名]
# 或者: from fixtures import MonkeyPatch [as 別名]
def setUp(self):
        super(GetSocketTestCase, self).setUp()
        self.useFixture(fixtures.MonkeyPatch(
            "senlin.api.common.wsgi.get_bind_addr",
            lambda x, y: ('192.168.0.13', 1234)))
        addr_info_list = [(2, 1, 6, '', ('192.168.0.13', 80)),
                          (2, 2, 17, '', ('192.168.0.13', 80)),
                          (2, 3, 0, '', ('192.168.0.13', 80))]
        self.useFixture(fixtures.MonkeyPatch(
            "senlin.api.common.wsgi.socket.getaddrinfo",
            lambda *x: addr_info_list))
        self.useFixture(fixtures.MonkeyPatch(
            "senlin.api.common.wsgi.time.time",
            mock.Mock(side_effect=[0, 1, 5, 10, 20, 35])))
        wsgi.cfg.CONF.senlin_api.cert_file = '/etc/ssl/cert'
        wsgi.cfg.CONF.senlin_api.key_file = '/etc/ssl/key'
        wsgi.cfg.CONF.senlin_api.ca_file = '/etc/ssl/ca_cert'
        wsgi.cfg.CONF.senlin_api.tcp_keepidle = 600 
開發者ID:openstack,項目名稱:senlin,代碼行數:20,代碼來源:test_wsgi.py

示例6: test_correct_configure_socket

# 需要導入模塊: import fixtures [as 別名]
# 或者: from fixtures import MonkeyPatch [as 別名]
def test_correct_configure_socket(self):
        mock_socket = mock.Mock()
        self.useFixture(fixtures.MonkeyPatch(
            'senlin.api.common.wsgi.ssl.wrap_socket',
            mock_socket))
        self.useFixture(fixtures.MonkeyPatch(
            'senlin.api.common.wsgi.eventlet.listen',
            lambda *x, **y: mock_socket))
        server = wsgi.Server(name='senlin-api', conf=cfg.CONF.senlin_api)
        server.default_port = 1234
        server.configure_socket()
        self.assertIn(mock.call.setsockopt(socket.SOL_SOCKET,
                                           socket.SO_REUSEADDR, 1),
                      mock_socket.mock_calls)
        self.assertIn(mock.call.setsockopt(socket.SOL_SOCKET,
                                           socket.SO_KEEPALIVE, 1),
                      mock_socket.mock_calls)
        if hasattr(socket, 'TCP_KEEPIDLE'):
            self.assertIn(mock.call().setsockopt(
                socket.IPPROTO_TCP,
                socket.TCP_KEEPIDLE,
                wsgi.cfg.CONF.senlin_api.tcp_keepidle), mock_socket.mock_calls) 
開發者ID:openstack,項目名稱:senlin,代碼行數:24,代碼來源:test_wsgi.py

示例7: setUp

# 需要導入模塊: import fixtures [as 別名]
# 或者: from fixtures import MonkeyPatch [as 別名]
def setUp(self):
        super(SenlinTestCase, self).setUp()
        self.setup_logging()
        service.ENABLE_SLEEP = False
        self.useFixture(fixtures.MonkeyPatch(
            'senlin.common.exception._FATAL_EXCEPTION_FORMAT_ERRORS',
            True))

        def enable_sleep():
            service.ENABLE_SLEEP = True

        self.addCleanup(enable_sleep)
        self.addCleanup(cfg.CONF.reset)

        messaging.setup("fake://", optional=True)
        self.addCleanup(messaging.cleanup)

        utils.setup_dummy_db()
        self.addCleanup(utils.reset_dummy_db) 
開發者ID:openstack,項目名稱:senlin,代碼行數:21,代碼來源:base.py

示例8: setUp

# 需要導入模塊: import fixtures [as 別名]
# 或者: from fixtures import MonkeyPatch [as 別名]
def setUp(self):
        super(TestCase, self).setUp()

        self.useFixture(fixtures.NestedTempfile())
        conf = copy.deepcopy(USER_CONF)
        tdir = self.useFixture(fixtures.TempDir())
        conf['cache']['path'] = tdir.path
        self.cloud_yaml = _write_yaml(conf)
        self.secure_yaml = _write_yaml(SECURE_CONF)
        self.vendor_yaml = _write_yaml(VENDOR_CONF)
        self.no_yaml = _write_yaml(NO_CONF)
        self.useFixture(fixtures.MonkeyPatch(
            'os_client_config.__version__', '1.2.3'))
        self.useFixture(fixtures.MonkeyPatch(
            'openstack.version.__version__', '3.4.5'))

        # Isolate the test runs from the environment
        # Do this as two loops because you can't modify the dict in a loop
        # over the dict in 3.4
        keys_to_isolate = []
        for env in os.environ.keys():
            if env.startswith('OS_'):
                keys_to_isolate.append(env)
        for env in keys_to_isolate:
            self.useFixture(fixtures.EnvironmentVariable(env)) 
開發者ID:openstack,項目名稱:os-client-config,代碼行數:27,代碼來源:base.py

示例9: test_write_would_block_too_many_times

# 需要導入模塊: import fixtures [as 別名]
# 或者: from fixtures import MonkeyPatch [as 別名]
def test_write_would_block_too_many_times(self):
        self.useFixture(fixtures.MonkeyPatch(
            'ironic_inspector.pxe_filter.dnsmasq._EXCLUSIVE_WRITE_ATTEMPTS',
            1))
        err = IOError('Oops!')
        err.errno = errno.EWOULDBLOCK
        self.mock_fcntl.side_effect = [err, None]

        wrote = dnsmasq._exclusive_write_or_pass(self.path, self.buf)
        self.assertFalse(wrote)
        self.mock_open.assert_called_once_with(self.path, 'w', 1)
        self.mock_fcntl.assert_has_calls(
            [self.fcntl_lock_call, self.fcntl_unlock_call])
        self.mock_fd.write.assert_not_called()
        retry_log_call = mock.call('%s locked; will try again (later)',
                                   self.path)
        failed_log_call = mock.call(
            'Failed to write the exclusively-locked path: %(path)s for '
            '%(attempts)s times', {
                'attempts': dnsmasq._EXCLUSIVE_WRITE_ATTEMPTS,
                'path': self.path
            })
        self.mock_log.assert_has_calls([retry_log_call, failed_log_call])
        self.mock_sleep.assert_called_once_with(
            dnsmasq._EXCLUSIVE_WRITE_ATTEMPTS_DELAY) 
開發者ID:openstack,項目名稱:ironic-inspector,代碼行數:27,代碼來源:test_dnsmasq_pxe_filter.py

示例10: setUp

# 需要導入模塊: import fixtures [as 別名]
# 或者: from fixtures import MonkeyPatch [as 別名]
def setUp(self):
        super(PrefixLazyTranslation, self).setUp()
        self.useFixture(ToggleLazy(True))
        self.useFixture(fixtures.MonkeyPatch(
            'oslo_i18n._gettextutils.get_available_languages',
            lambda *x, **y: self.languages))
        self.useFixture(fixtures.MonkeyPatch(
            'oslo_i18n.get_available_languages',
            lambda *x, **y: self.languages))
        self.useFixture(fixtures.MonkeyPatch('gettext.translation',
                                             _prefix_translations))
        self.useFixture(fixtures.MonkeyPatch('locale.getdefaultlocale',
                                             lambda *x, **y: self.locale)) 
開發者ID:openstack,項目名稱:oslo.i18n,代碼行數:15,代碼來源:fixture.py

示例11: setUp

# 需要導入模塊: import fixtures [as 別名]
# 或者: from fixtures import MonkeyPatch [as 別名]
def setUp(self):
        super(CaptureOutput, self).setUp()
        self._stdout_fixture = fixtures.StringStream('stdout')
        self.stdout = self.useFixture(self._stdout_fixture).stream
        self.useFixture(fixtures.MonkeyPatch('sys.stdout', self.stdout))
        self._stderr_fixture = fixtures.StringStream('stderr')
        self.stderr = self.useFixture(self._stderr_fixture).stream
        self.useFixture(fixtures.MonkeyPatch('sys.stderr', self.stderr))

        self._logs_fixture = fixtures.StringStream('logs')
        self.logs = self.useFixture(self._logs_fixture).stream
        self.useFixture(fixtures.MonkeyPatch(
            'daiquiri.output.STDERR', daiquiri.output.Stream(self.logs))) 
開發者ID:gnocchixyz,項目名稱:gnocchi,代碼行數:15,代碼來源:base.py

示例12: stub_out

# 需要導入模塊: import fixtures [as 別名]
# 或者: from fixtures import MonkeyPatch [as 別名]
def stub_out(self, old, new):
        """Replace a function for the duration of the test.

        Use the monkey patch fixture to replace a function for the
        duration of a test. Useful when you want to provide fake
        methods instead of mocks during testing.

        This should be used instead of self.stubs.Set (which is based
        on mox) going forward.
        """
        self.useFixture(fixtures.MonkeyPatch(old, new)) 
開發者ID:openstack,項目名稱:zun,代碼行數:13,代碼來源:base.py

示例13: setUp

# 需要導入模塊: import fixtures [as 別名]
# 或者: from fixtures import MonkeyPatch [as 別名]
def setUp(self):
        super(BaseTestCase, self).setUp()
        if not self.setUpClassCalled:
            raise RuntimeError("setUpClass does not calls the super's"
                               "setUpClass in the "
                               + self.__class__.__name__)
        test_timeout = os.environ.get('OS_TEST_TIMEOUT', 0)
        try:
            test_timeout = int(test_timeout)
        except ValueError:
            test_timeout = 0
        if test_timeout > 0:
            self.useFixture(fixtures.Timeout(test_timeout, gentle=True))

        if (os.environ.get('OS_STDOUT_CAPTURE') == 'True' or
                os.environ.get('OS_STDOUT_CAPTURE') == '1'):
            stdout = self.useFixture(fixtures.StringStream('stdout')).stream
            self.useFixture(fixtures.MonkeyPatch('sys.stdout', stdout))
        if (os.environ.get('OS_STDERR_CAPTURE') == 'True' or
                os.environ.get('OS_STDERR_CAPTURE') == '1'):
            stderr = self.useFixture(fixtures.StringStream('stderr')).stream
            self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr))
        if (os.environ.get('OS_LOG_CAPTURE') != 'False' and
            os.environ.get('OS_LOG_CAPTURE') != '0'):
            self.useFixture(fixtures.LoggerFixture(nuke_handlers=False,
                                                   format=self.log_format,
                                                   level=None)) 
開發者ID:openstack,項目名稱:tempest-lib,代碼行數:29,代碼來源:base.py

示例14: setUp

# 需要導入模塊: import fixtures [as 別名]
# 或者: from fixtures import MonkeyPatch [as 別名]
def setUp(self):
        """Run before each test method to initialize test environment."""

        super(TestCase, self).setUp()
        self.stubbed_mapped_nics = {}

        def dummy_mapped_nics(nic_mapping=None):
            return self.stubbed_mapped_nics
        if self.stub_mapped_nics:
            self.stub_out('os_net_config.objects.mapped_nics',
                          dummy_mapped_nics)

        test_timeout = os.environ.get('OS_TEST_TIMEOUT', 0)
        try:
            test_timeout = int(test_timeout)
        except ValueError:
            # If timeout value is invalid do not set a timeout.
            test_timeout = 0
        if test_timeout > 0:
            self.useFixture(fixtures.Timeout(test_timeout, gentle=True))

        self.useFixture(fixtures.NestedTempfile())
        self.useFixture(fixtures.TempHomeDir())

        if os.environ.get('OS_STDOUT_CAPTURE') in _TRUE_VALUES:
            stdout = self.useFixture(fixtures.StringStream('stdout')).stream
            self.useFixture(fixtures.MonkeyPatch('sys.stdout', stdout))
        if os.environ.get('OS_STDERR_CAPTURE') in _TRUE_VALUES:
            stderr = self.useFixture(fixtures.StringStream('stderr')).stream
            self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr))

        self.log_fixture = self.useFixture(fixtures.FakeLogger()) 
開發者ID:openstack,項目名稱:os-net-config,代碼行數:34,代碼來源:base.py

示例15: stub_out

# 需要導入模塊: import fixtures [as 別名]
# 或者: from fixtures import MonkeyPatch [as 別名]
def stub_out(self, old, new):
        """Replace a function for the duration of the test.

        Use the monkey patch fixture to replace a function for the
        duration of a test. Useful when you want to provide fake
        methods instead of mocks during testing.

        This should be used instead of set.stubs.Set (which is based
        on mox) going forward.
        """
        self.useFixture(fixtures.MonkeyPatch(old, new)) 
開發者ID:openstack,項目名稱:os-net-config,代碼行數:13,代碼來源:base.py


注:本文中的fixtures.MonkeyPatch方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。