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


Python object函数代码示例

本文整理汇总了Python中object函数的典型用法代码示例。如果您正苦于以下问题:Python object函数的具体用法?Python object怎么用?Python object使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了object函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_worker_factory

def test_worker_factory():
    class Service(object):
        name = "service"
        foo_proxy = RpcProxy("foo_service")
        bar_proxy = RpcProxy("bar_service")

    class OtherService(object):
        pass

    # simplest case, no overrides
    instance = worker_factory(Service)
    assert isinstance(instance, Service)
    assert isinstance(instance.foo_proxy, Mock)
    assert isinstance(instance.bar_proxy, Mock)

    # no dependencies to replace
    instance = worker_factory(OtherService)
    assert isinstance(instance, OtherService)

    # override specific dependency
    bar_dependency = object()
    instance = worker_factory(Service, bar_proxy=bar_dependency)
    assert isinstance(instance, Service)
    assert isinstance(instance.foo_proxy, Mock)
    assert instance.bar_proxy is bar_dependency

    # non-applicable dependency
    with pytest.raises(ExtensionNotFound):
        worker_factory(Service, nonexist=object())
开发者ID:koenvo,项目名称:nameko,代码行数:29,代码来源:test_services.py

示例2: test_exception_when_adding_multiple_bonds_with_invalid_id

 def test_exception_when_adding_multiple_bonds_with_invalid_id(self):
     # given
     bonds = [Bond(uid=object(), particles=[uuid.uuid4()]), Bond(uid=object(), particles=[uuid.uuid4()])]
     # then
     with self.assertRaises(AttributeError):
         # when
         self.container.add_bonds(bonds)
开发者ID:kitchoi,项目名称:simphony-common,代码行数:7,代码来源:abc_check_particles.py

示例3: test___getitem___hit

 def test___getitem___hit(self):
     _APP1, _APP2 = object(), object()
     mapper = self._makeOne()
     mapper.applications.append(((None, '/foo/bar'), _APP2))
     mapper.applications.append(((None, '/foo'), _APP1))
     self.assertTrue(mapper['/foo'] is _APP1)
     self.assertTrue(mapper['/foo/bar'] is _APP2)
开发者ID:pombredanne,项目名称:rutter,代码行数:7,代码来源:test_urlmap.py

示例4: test_good_configuration

  def test_good_configuration(self):
    self.mox.StubOutWithMock(application_configuration, 'ModuleConfiguration')
    static_backend_entry = backendinfo.BackendEntry(name='static')
    dynamic_backend_entry = backendinfo.BackendEntry(name='dynamic')
    backend_info = backendinfo.BackendInfoExternal(
        backends=[static_backend_entry, dynamic_backend_entry])
    module_config = object()
    application_configuration.ModuleConfiguration(
        '/appdir/app.yaml').AndReturn(module_config)
    application_configuration.BackendsConfiguration._parse_configuration(
        '/appdir/backends.yaml').AndReturn(backend_info)
    static_configuration = object()
    dynamic_configuration = object()
    application_configuration.BackendConfiguration(
        module_config,
        mox.IgnoreArg(),
        static_backend_entry).InAnyOrder().AndReturn(static_configuration)
    application_configuration.BackendConfiguration(
        module_config,
        mox.IgnoreArg(),
        dynamic_backend_entry).InAnyOrder().AndReturn(dynamic_configuration)

    self.mox.ReplayAll()
    config = application_configuration.BackendsConfiguration(
        '/appdir/app.yaml',
        '/appdir/backends.yaml')
    self.assertItemsEqual([static_configuration, dynamic_configuration],
                          config.get_backend_configurations())
    self.mox.VerifyAll()
开发者ID:KronnyEC,项目名称:cliques,代码行数:29,代码来源:application_configuration_test.py

示例5: test___ne__same_value

 def test___ne__same_value(self):
     start = object()
     end = object()
     time_range1 = self._makeOne(start=start, end=end)
     time_range2 = self._makeOne(start=start, end=end)
     comparison_val = (time_range1 != time_range2)
     self.assertFalse(comparison_val)
开发者ID:evmin,项目名称:gcloud-python,代码行数:7,代码来源:test_row.py

示例6: test_to_dict

    def test_to_dict(self):
        cell1 = object()
        cell2 = object()
        cell3 = object()

        family_name1 = u'name1'
        family_name2 = u'name2'
        qual1 = b'col1'
        qual2 = b'col2'
        qual3 = b'col3'

        partial_row_data = self._makeOne(None)
        partial_row_data._cells = {
            family_name1: {
                qual1: cell1,
                qual2: cell2,
            },
            family_name2: {
                qual3: cell3,
            },
        }

        result = partial_row_data.to_dict()
        expected_result = {
            b'name1:col1': cell1,
            b'name1:col2': cell2,
            b'name2:col3': cell3,
        }
        self.assertEqual(result, expected_result)
开发者ID:muscovitegrinder,项目名称:gcloud-python,代码行数:29,代码来源:test_row_data.py

示例7: testNoExit

    def testNoExit(self):
        result = object()
        test = object()

        class FakeRunner(object):
            def run(self, test):
                self.test = test
                return result

        runner = FakeRunner()

        oldParseArgs = unittest2.TestProgram.parseArgs
        def restoreParseArgs():
            unittest2.TestProgram.parseArgs = oldParseArgs
        unittest2.TestProgram.parseArgs = lambda *args: None
        self.addCleanup(restoreParseArgs)

        def removeTest():
            del unittest2.TestProgram.test
        unittest2.TestProgram.test = test
        self.addCleanup(removeTest)

        program = unittest2.TestProgram(testRunner=runner, exit=False, verbosity=2)

        self.assertEqual(program.result, result)
        self.assertEqual(runner.test, test)
        self.assertEqual(program.verbosity, 2)
开发者ID:ismcodes,项目名称:thor,代码行数:27,代码来源:test_program.py

示例8: create_stack

    def create_stack(self, stack_name='test_stack'):
        temp = template_format.parse(test_template_waitcondition)
        template = parser.Template(temp)
        ctx = utils.dummy_context()
        stack = parser.Stack(ctx, stack_name, template, disable_rollback=True)

        self.stack_id = stack.store()

        self.m.StubOutWithMock(nova_keypair.KeypairConstraint, 'validate')
        nova_keypair.KeypairConstraint.validate(
            mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)
        self.m.StubOutWithMock(image.ImageConstraint, 'validate')
        image.ImageConstraint.validate(
            mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True)

        self.m.StubOutWithMock(instance.Instance, 'handle_create')
        self.m.StubOutWithMock(instance.Instance, 'check_create_complete')
        for cookie in (object(), object()):
            instance.Instance.handle_create().AndReturn(cookie)
            instance.Instance.check_create_complete(cookie).AndReturn(True)

        id = identifier.ResourceIdentifier('test_tenant_id', stack.name,
                                           stack.id, '', 'WH')
        self.m.StubOutWithMock(wc.WaitConditionHandle, 'identifier')
        wc.WaitConditionHandle.identifier().MultipleTimes().AndReturn(id)

        self.m.StubOutWithMock(scheduler.TaskRunner, '_sleep')
        return stack
开发者ID:PFZheng,项目名称:heat,代码行数:28,代码来源:test_metadata_refresh.py

示例9: test_testing_resources

 def test_testing_resources(self):
     from pyramid.traversal import find_resource
     from pyramid.interfaces import ITraverser
     ob1 = object()
     ob2 = object()
     resources = {'/ob1':ob1, '/ob2':ob2}
     config = self._makeOne(autocommit=True)
     config.testing_resources(resources)
     adapter = config.registry.getAdapter(None, ITraverser)
     result = adapter(DummyRequest({'PATH_INFO':'/ob1'}))
     self.assertEqual(result['context'], ob1)
     self.assertEqual(result['view_name'], '')
     self.assertEqual(result['subpath'], ())
     self.assertEqual(result['traversed'], (text_('ob1'),))
     self.assertEqual(result['virtual_root'], ob1)
     self.assertEqual(result['virtual_root_path'], ())
     result = adapter(DummyRequest({'PATH_INFO':'/ob2'}))
     self.assertEqual(result['context'], ob2)
     self.assertEqual(result['view_name'], '')
     self.assertEqual(result['subpath'], ())
     self.assertEqual(result['traversed'], (text_('ob2'),))
     self.assertEqual(result['virtual_root'], ob2)
     self.assertEqual(result['virtual_root_path'], ())
     self.assertRaises(KeyError, adapter, DummyRequest({'PATH_INFO':'/ob3'}))
     try:
         config.begin()
         self.assertEqual(find_resource(None, '/ob1'), ob1)
     finally:
         config.end()
开发者ID:7924102,项目名称:pyramid,代码行数:29,代码来源:test_testing.py

示例10: test_put

    def test_put(self):
        import operator

        table = object()
        batch = self._makeOne(table)
        batch._timestamp = timestamp = object()
        row_key = 'row-key'
        batch._row_map[row_key] = row = _MockRow()

        col1_fam = 'cf1'
        col1_qual = 'qual1'
        value1 = 'value1'
        col2_fam = 'cf2'
        col2_qual = 'qual2'
        value2 = 'value2'
        data = {col1_fam + ':' + col1_qual: value1,
                col2_fam + ':' + col2_qual: value2}

        self.assertEqual(batch._mutation_count, 0)
        self.assertEqual(row.set_cell_calls, [])
        batch.put(row_key, data)
        self.assertEqual(batch._mutation_count, 2)
        # Since the calls depend on data.keys(), the order
        # is non-deterministic.
        first_elt = operator.itemgetter(0)
        ordered_calls = sorted(row.set_cell_calls, key=first_elt)

        cell1_args = (col1_fam, col1_qual, value1)
        cell1_kwargs = {'timestamp': timestamp}
        cell2_args = (col2_fam, col2_qual, value2)
        cell2_kwargs = {'timestamp': timestamp}
        self.assertEqual(ordered_calls, [
            (cell1_args, cell1_kwargs),
            (cell2_args, cell2_kwargs),
        ])
开发者ID:muscovitegrinder,项目名称:gcloud-python,代码行数:35,代码来源:test_batch.py

示例11: test_existing_credentials_arguments_passed_on

    def test_existing_credentials_arguments_passed_on(self):
        # When re-using existing credentials, the arguments login_with
        # is called with are passed on the the __init__() method.
        os.makedirs(
            os.path.join(self.temp_dir, 'api.example.com', 'credentials'))
        credentials_file_path = os.path.join(
            self.temp_dir, 'api.example.com', 'credentials', 'app name')
        credentials = Credentials(
            'app name', consumer_secret='consumer_secret:42',
            access_token=AccessToken('access_key:84', 'access_secret:168'))
        credentials.save_to_path(credentials_file_path)

        timeout = object()
        proxy_info = object()
        version = "foo"
        launchpad = NoNetworkLaunchpad.login_with(
            'app name', launchpadlib_dir=self.temp_dir,
            service_root=SERVICE_ROOT, timeout=timeout, proxy_info=proxy_info,
            version=version)
        expected_arguments = dict(
            service_root=SERVICE_ROOT,
            timeout=timeout,
            proxy_info=proxy_info,
            version=version,
            cache=os.path.join(self.temp_dir, 'api.example.com', 'cache'))
        for key, expected in expected_arguments.items():
            actual = launchpad.passed_in_args[key]
            self.assertEqual(actual, expected)
开发者ID:Alberto-Beralix,项目名称:Beralix,代码行数:28,代码来源:test_launchpad.py

示例12: test_getitem

 def test_getitem(self):
     item1 = object()
     item2 = object()
     items = ItemList(object, items=[item1, item2])
     assert_true(items[0] is item1)
     assert_true(items[1] is item2)
     assert_true(items[-1] is item2)
开发者ID:strimber,项目名称:robotframework,代码行数:7,代码来源:test_itemlist.py

示例13: test_nearest

    def test_nearest(self):
        nn = KDTree_3Double()

        nn_id = {}
        
        o1 = object()
        nn.add(((1,1,0), id(o1)))
        nn_id[id(o1)] = o1
        o2 = object()
        nn.add(((10,10,0), id(o2)))
        nn_id[id(o2)] = o2
        o3 = object()
        nn.add(((4.1, 4.1,0), id(o3)))
        nn_id[id(o3)] = o3
        
        expected =  o3
        actual = nn.find_nearest((2.9,2.9,0))[1]
        self.assertTrue(expected==nn_id[actual], "%s != %s"%(str(expected), str(nn_id[actual])))

        expected = o3
        actual = nn.find_nearest((6, 6,0))[1]
        self.assertTrue(expected==nn_id[actual], "%s != %s"%(str(expected), str(nn_id[actual])))

        expected = o2
        actual = nn.find_nearest((8, 9,0))[1]
        self.assertTrue(expected==nn_id[actual], "%s != %s"%(str(expected), str(nn_id[actual])))
开发者ID:anetasie,项目名称:sherpa-old,代码行数:26,代码来源:test_kdtree.py

示例14: test_worker_term_hard_handler_only_stop_MainProcess

 def test_worker_term_hard_handler_only_stop_MainProcess(self):
     try:
         import _multiprocessing  # noqa
     except ImportError:
         raise SkipTest('only relevant for multiprocessing')
     process = current_process()
     name, process.name = process.name, 'OtherProcess'
     try:
         with patch('celery.apps.worker.active_thread_count') as c:
             c.return_value = 3
             worker = self._Worker()
             handlers = self.psig(
                 cd.install_worker_term_hard_handler, worker)
             try:
                 handlers['SIGQUIT']('SIGQUIT', object())
                 self.assertTrue(state.should_terminate)
             finally:
                 state.should_terminate = False
         with patch('celery.apps.worker.active_thread_count') as c:
             c.return_value = 1
             worker = self._Worker()
             handlers = self.psig(
                 cd.install_worker_term_hard_handler, worker)
             with self.assertRaises(WorkerTerminate):
                 handlers['SIGQUIT']('SIGQUIT', object())
     finally:
         process.name = name
开发者ID:EricSchles,项目名称:celery,代码行数:27,代码来源:test_worker.py

示例15: test_datetimelike_bounded_cell

 def test_datetimelike_bounded_cell(self):
     point = object()
     cell = Cell(point=object(),
                 bound=[mock.Mock(timetuple=mock.Mock()),
                        mock.Mock(timetuple=mock.Mock())])
     with self.assertRaisesRegexp(TypeError, 'bounded region for datetime'):
         cell.contains_point(point)
开发者ID:MahatmaCane,项目名称:iris,代码行数:7,代码来源:test_Cell.py


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