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


Python Mocker.result方法代码示例

本文整理汇总了Python中mocker.Mocker.result方法的典型用法代码示例。如果您正苦于以下问题:Python Mocker.result方法的具体用法?Python Mocker.result怎么用?Python Mocker.result使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mocker.Mocker的用法示例。


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

示例1: test_story_runner_returns_a_result_with_the_original_Fixture

# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import result [as 别名]
def test_story_runner_returns_a_result_with_the_original_Fixture():
    
    mocker = Mocker()
    
    settings = Settings()
    fixture = Fixture()
    action = some_action()
    fixture.append_story(action.scenario.story)
    runner = StoryRunner()

    context = Object()
    context.browser_driver = mocker.mock()
    context.browser_driver.start_test("http://localhost")
    context.browser_driver.stop_test()
    context.settings = mocker.mock()
    context.settings.on_before_action
    mocker.result(None)
    context.settings.on_action_successful
    mocker.result(None)
    
    context.language = mocker.mock()
    context.language.get('given')
    mocker.result('Given')
    context.language.get('when')
    mocker.result('When')
    context.language.get('then')
    mocker.result('Then')

    with mocker:
        result = runner.run_stories(settings, fixture, context=context)
    
        assert result.fixture == fixture
开发者ID:Desperado,项目名称:pyccuracy,代码行数:34,代码来源:test_story_runner.py

示例2: test_should_execute_scenarios_successfully

# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import result [as 别名]
def test_should_execute_scenarios_successfully():
    
    mocker = Mocker()
    
    settings = Settings()
    runner = StoryRunner()
    fixture = Fixture()
    fixture.append_story(some_action().scenario.story)

    context = Object()
    context.browser_driver = mocker.mock()
    context.browser_driver.start_test("http://localhost")
    context.browser_driver.stop_test()
    context.settings = mocker.mock()
    context.settings.on_before_action
    mocker.result(None)
    context.settings.on_action_successful
    mocker.result(None)
    
    context.language = mocker.mock()
    context.language.get('given')
    mocker.result('Given')
    context.language.get('when')
    mocker.result('When')
    context.language.get('then')
    mocker.result('Then')

    with mocker:
        result = runner.run_stories(settings=settings, fixture=fixture, context=context)
    
        assert fixture.get_status() == Status.Successful
开发者ID:Desperado,项目名称:pyccuracy,代码行数:33,代码来源:test_story_runner.py

示例3: test_read_tags

# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import result [as 别名]
    def test_read_tags(self):
        mocker = Mocker()
        csv_reader = mocker.mock()

        headers = [
            'title', 'isbn', 'publisher', 'list_price', 'publish_date',
            'class_', 'sheet_numbers', 'folio', 'print_type', 'author',
            'barcode', 'comments', 'audience', 'awards']
        first_line = [
            'a', '1234', 'aph', '30', '2012', 'I.', 18, '4', 'mono', 'sb', 'a',
            'blahblahblah', 'ms', 'annual']
        field_map = {'title': 0, 'isbn': 1, 'publisher': 2, 'list_price': 3,
            'publish_date': 4, 'class_': 5, 'sheet_numbers': 6, 'folio': 7, 
            'print_type': 8, 'author': 9, 'barcode': 10, 'comments': 11 }

        csv_reader.next() # read headers
        mocker.result(headers)
        
        csv_reader.next() # read first line
        mocker.result(first_line)

        mocker.replay()

        reader = CatalogReader(csv_reader, field_map)
        item = reader.read()
        
        self.assertIsInstance(item, CatalogItem)
        self.assertEquals(2, len(item.tags))
        
        self.assertEquals('ms', item.tags['audience'])
        self.assertEquals('annual', item.tags['awards'])

        mocker.restore()
        mocker.verify()
开发者ID:unasogno,项目名称:bookstore,代码行数:36,代码来源:book_catalog_testcases.py

示例4: test_call_no_unicode_and_no_error_desc

# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import result [as 别名]
    def test_call_no_unicode_and_no_error_desc(self):
        reg = getUtility(IRegistry).forInterface(ICollectiveFlattr)
        reg.access_token = u''

        mocker = Mocker()
        func = mocker.replace('collective.flattr.browser.flattr.Flattr.getAccessToken')
        func(u'un8Vzv7pNMXNuAQY3uRgjYfM4V3Feirz')
        mocker.result({'access_token': u'NEW_ACCESS_TOKEN',
            'token_type': u'bearer', 'error': u'blubber'})

        with as_manager(self.portal) as view:
            from collective.flattr.browser.flattr import Flattr
            with mocker:
                self.layer['request']['code'] = 'un8Vzv7pNMXNuAQY3uRgjYfM4V3Feirz'
                view = Flattr(self.portal, self.layer['request'])

                ret = view()
                self.assertEquals(reg.access_token, u'')
                self.assertEquals(self.layer['request'].response\
                    .headers['location'], 'http://nohost/plone')
                ret = IStatusMessage(self.layer['request'])\
                    .showStatusMessages()
                self.assertEquals(ret[0].message,
                    u'undefined: Undefined error while getting access token')
                self.assertEquals(ret[0].type, u'error')
开发者ID:chrigl,项目名称:docker-library,代码行数:27,代码来源:test_flattr_view.py

示例5: test_without_when

# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import result [as 别名]
    def test_without_when(self):
        mocker = Mocker()
        mock_time = mocker.replace('time.time')
        mock_time()
        mocker.result(1.0)
        mock_time()
        mocker.result(2.0)
        mock_time()
        mocker.result(3.0)
        mock_time()
        mocker.result(4.0)
        mock_time()
        mocker.result(5.0)

        mocker.replay()

        controller = pid.PID(P = 0.5, I = 0.5, D = 0.5,
                             setpoint = 0, initial = 12)

        self.assertEqual(controller.calculate_response(6), -3)
        self.assertEqual(controller.calculate_response(3), -4.5)
        self.assertEqual(controller.calculate_response(-1.5), -0.75)
        self.assertEqual(controller.calculate_response(-2.25), -1.125)

        mocker.restore()
        mocker.verify()
开发者ID:amrod,项目名称:PythonTesting,代码行数:28,代码来源:test_pid.py

示例6: test_wait_for_disappear

# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import result [as 别名]
    def test_wait_for_disappear(self):

        mocker = Mocker()

        context = Context(Settings())
        browser_mock = mocker.mock()
        browser_mock.find_by_xpath('some element')
        mocker.count(min=1, max=None)

        element_mock = mocker.mock()
        mocker.result(element_mock)

        element_mock.visible
        mocker.result(True)

        mocker.count(min=1, max=None)
        mocker.result(True)

        element_mock.visible
        mocker.result(False)
        mocker.count(min=2, max=None)

        mocker.result(True)

        with mocker:
            driver = SplinterDriver(context, browser=browser_mock)
            driver.wait_for_element_to_disappear("some element", 1)
开发者ID:jusbrasil,项目名称:pyccuracy,代码行数:29,代码来源:test_splinter_driver.py

示例7: test_see_summary_for_fixture_returns_proper_string_for_no_tests

# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import result [as 别名]
def test_see_summary_for_fixture_returns_proper_string_for_no_tests():
    
    mocker = Mocker()
    
    expected = """================
Test Run Summary
================

Status: UNKNOWN

Test Data Stats
---------------
Successful Stories......0/0 (0.00%)
Failed Stories..........0/0 (0.00%)
Successful Scenarios....0/0 (0.00%)
Failed Scenarios........0/0 (0.00%)"""

    template_loader_mock = mocker.mock()
    template_loader_mock.load("summary")
    mocker.result(summary_template)
    
    with mocker:
        settings = Settings()
        fixture = Fixture()
        result = Result(fixture=fixture, template_loader=template_loader_mock)
    
        summary = result.summary_for(settings.default_culture)
        assert summary == expected
开发者ID:Desperado,项目名称:pyccuracy,代码行数:30,代码来源:test_result.py

示例8: setUpZope

# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import result [as 别名]
    def setUpZope(self, app, configurationContext):
        # Mock postmonkey
        mocker = Mocker()
        postmonkey = mocker.replace("postmonkey")
        mailchimp = postmonkey.PostMonkey(ANY)
        mocker.count(0, 1000)
        # Lists
        mailchimp.lists()
        mocker.count(0, 1000)
        mocker.result({
            u'total': 2,
            u'data': [{
                    u'id': 625,
                    u'web_id': 625,
                    u'name': u'ACME Newsletter',
                    u'default_from_name': u'[email protected]',
                },
                {
                    u'id': 626,
                    u'web_id': 626,
                    u'name': u'ACME Newsletter 2',
                    u'default_from_name': u'[email protected]',
                },
            ]})
        mocker.replay()

        # Load ZCML
        import example.tdd
        xmlconfig.file(
            'configure.zcml',
            example.tdd,
            context=configurationContext
        )
开发者ID:tisto,项目名称:example.tdd,代码行数:35,代码来源:testing.py

示例9: test_historylogs_without_filters

# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import result [as 别名]
    def test_historylogs_without_filters(self):
        for document_type in ['article', 'journal']:
            historylogs = json.loads(
                open(os.path.dirname(__file__) +
                     '/fixtures/historylogs_%s.json' % document_type).read()
            )
            mocker = Mocker()
            databroker = mocker.mock()
            databroker['historychanges_%s' % document_type].find(ANY).count()
            mocker.result(historylogs['meta']['total'])
            databroker['historychanges_%s' % document_type].find(ANY).skip(ANY).limit(ANY).sort("date")
            mocker.result(historylogs['objects'])
            mocker.replay()

            db = DataBroker(databroker)
            result = db.historychanges(document_type)

            # assert date filters are correct in meta
            self.assertIn('meta', result.keys())
            self.assertIn('filter', result['meta'].keys())
            self.assertIn('date', result['meta']['filter'].keys())
            self.assertEqual(['$lte', '$gt'], result['meta']['filter']['date'].keys())

            self.assertEqual(
                historylogs['meta']['total'],
                result['meta']['total']
            )
            self.assertIn('objects', result.keys())
            self.assertEqual(historylogs['objects'], result['objects'])
            self.assertEqual(
                result['objects'][0].keys(),
                ['date', 'code', 'event', 'collection']
            )
开发者ID:jfunez,项目名称:articles_meta,代码行数:35,代码来源:test_controller.py

示例10: test_server_start_stop_metrics

# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import result [as 别名]
    def test_server_start_stop_metrics(self):
        """Test start/stop metrics."""
        mocker = Mocker()

        service_meter = mocker.mock(name='meter')
        self.service.metrics = service_meter

        revno = mocker.mock(name='revno')
        self.patch(metrics.services, 'revno', revno)

        service_meter.meter('server_stop')
        service_meter.decrement('services_active')
        service_meter.meter('server_start')
        service_meter.increment('services_active')

        service_meter.timing("busy.ping", ANY)
        mocker.count(0, None)

        revno()
        mocker.count(0, None)

        service_meter.connection
        mocker.result(None)

        with mocker:
            yield self.service.stopService()
            yield self.service.startService()
开发者ID:CSRedRat,项目名称:magicicada-server,代码行数:29,代码来源:test_basic.py

示例11: test_see_summary_for_fixture_returns_proper_string_for_failed_tests

# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import result [as 别名]
def test_see_summary_for_fixture_returns_proper_string_for_failed_tests():
    
    mocker = Mocker()
    
    expected = """================
Test Run Summary
================

Status: FAILED

Test Data Stats
---------------
Successful Stories......0/1 (0.00%)
Failed Stories..........1/1 (100.00%)
Successful Scenarios....0/1 (0.00%)
Failed Scenarios........1/1 (100.00%)"""

    template_loader_mock = mocker.mock()
    template_loader_mock.load("summary")
    mocker.result(summary_template)
    
    with mocker:
        settings = Settings()
        fixture = Fixture()
        action = some_action()
        fixture.append_story(action.scenario.story)
        action.mark_as_failed()
        result = Result(fixture=fixture, template_loader=template_loader_mock)
    
        summary = result.summary_for(settings.default_culture)
        assert summary == expected
开发者ID:Desperado,项目名称:pyccuracy,代码行数:33,代码来源:test_result.py

示例12: test_parsing_files_with_proper_header_returns_parsed_scenario

# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import result [as 别名]
def test_parsing_files_with_proper_header_returns_parsed_scenario():
    
    mocker = Mocker()
    
    settings = Settings()
    files = ["some path"]
    
    story_text = """As a someone
I want to do something
So that I'm happy"""

    filemock = mocker.mock()
    filemock.list_files(directories=settings.tests_dirs, pattern=settings.file_pattern)
    mocker.result(files)
    filemock.read_file(files[0])
    mocker.result(story_text)

    language_mock = mocker.mock()
    language_mock.get("as_a")
    mocker.result("As a")
    language_mock.get("i_want_to")
    mocker.result("I want to")
    language_mock.get("so_that")
    mocker.result("So that")

    with mocker:
        parser = FileParser(language=language_mock, file_object=filemock)
    
        fixture = parser.get_stories(settings=settings)
        assert len(fixture.stories) == 1
        assert fixture.stories[0].as_a == "someone"
        assert fixture.stories[0].i_want_to == "do something"
        assert fixture.stories[0].so_that == "I'm happy"
开发者ID:Desperado,项目名称:pyccuracy,代码行数:35,代码来源:test_file_parser.py

示例13: test_offset

# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import result [as 别名]
    def test_offset(self):
        """
        Test that, if the server's BEGIN_CONTENT message specifies an offset,
        the file to be uploaded is seek'ed to the right position.
        """
        offset = 23
        mocker = Mocker()
        transport = mocker.mock()
        transport.registerProducer(ANY, streaming=True)
        transport.write(ANY)
        mocker.count(1, None)  # I don't really care how many times
        fd = mocker.mock()
        fd.seek(offset)  # this is really all I care about
        fd.read(ANY)
        mocker.result('')
        mocker.replay()

        protocol = StorageClient()
        protocol.transport = transport
        pc = PutContent(protocol, 'share', 'node', '', '', 0, 0, 0, fd)
        message = protocol_pb2.Message()
        message.type = protocol_pb2.Message.BEGIN_CONTENT
        message.begin_content.offset = offset
        pc.start()
        pc.processMessage(message)
开发者ID:magicicada-bot,项目名称:magicicada-protocol,代码行数:27,代码来源:test_putcontent.py

示例14: test_required_field_missing

# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import result [as 别名]
    def test_required_field_missing(self):
        mocker = Mocker()
        csv_reader = mocker.mock()
        
        headers = [
            'title', 'isbn', 'publisher', 'list_price', 'publish_date',
            'class_', 'sheet_numbers', 'folio', 'print_type', 'author',
            'barcode']
        first_line = [
            'a', '1234', 'aph', '30', '2012', 'I.', 18, '4', 'mono', 'sb', 'a']
        field_map = {
            'title': 0, 'isbn': 1, 'publisher': 2, 'list_price': 3,
            'publish_date': 4, 'class_': 5, 'sheet_numbers': 6, 'folio': 7,
            'print_type': 8, 'author': 9, 'barcode': 10, 'comments': 11 }

        csv_reader.next() # read headers
        mocker.result(headers)
            
        csv_reader.next() # read first line
        mocker.result(first_line)

        mocker.replay()

        reader = CatalogReader(csv_reader, field_map)
        item = reader.read()

        self.assertIsNone(item.comments)

        mocker.restore()
        mocker.verify()
开发者ID:unasogno,项目名称:bookstore,代码行数:32,代码来源:book_catalog_testcases.py

示例15: test_read_basic_fields

# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import result [as 别名]
    def test_read_basic_fields(self):
        mocker = Mocker()
        csv_reader = mocker.mock()

        csv_reader.next()
        header_line = [
            'title', 'isbn', 'publisher', 'list_price', 'publish_date',
            'class_', 'sheet_numbers', 'folio', 'print_type', 'author',
            'barcode', 'comments']
        mocker.result(header_line)

        csv_reader.next()
        first_line = [
            'a', '1234', 'aph', '30', '2012', 'I.', 18, '4', 'mono', 'sb', 'a',
            'blahblahblah' ]
        mocker.result(first_line)

        mocker.replay()

        field_map = {'title': 0, 'isbn': 1, 'publisher': 2, 'list_price': 3,
            'publish_date': 4, 'class_': 5, 'sheet_numbers': 6, 'folio': 7, 
            'print_type': 8, 'author': 9, 'barcode': 10, 'comments': 11 }

        reader = CatalogReader(csv_reader, field_map)
        item = reader.read()
        
        self.assertIsInstance(item, CatalogItem)

        mocker.restore()
        mocker.verify()
开发者ID:unasogno,项目名称:bookstore,代码行数:32,代码来源:book_catalog_testcases.py


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