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


Python Mock.__iter__方法代码示例

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


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

示例1: test_step_status_is_collected_and_reported

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import __iter__ [as 别名]
    def test_step_status_is_collected_and_reported(self, format_summary):
        feature = Mock()
        scenario = Mock()
        steps = [Mock(), Mock(), Mock(), Mock(), Mock()]
        steps[0].status = 'failed'
        steps[0].__iter__ = Mock(return_value=iter([]))
        steps[1].status = 'undefined'
        steps[1].__iter__ = Mock(return_value=iter([]))
        steps[2].status = 'passed'
        steps[2].__iter__ = Mock(return_value=iter([]))
        steps[3].status = 'passed'
        steps[3].__iter__ = Mock(return_value=iter([]))
        steps[4].status = None
        steps[4].__iter__ = Mock(return_value=iter([]))
        feature.status = 'failed'
        feature.duration = 12.3
        feature.__iter__ = Mock(return_value=iter([scenario]))
        scenario.status = 'failed'
        scenario.__iter__ = Mock(return_value=iter(steps))

        config = Mock()
        reporter = SummaryReporter(config)

        reporter.feature(feature)
        reporter.end()

        expected = {
            'passed': 2,
            'failed': 1,
            'skipped': 1,
            'untested': 0,
            'undefined': 1,
        }

        eq_(format_summary.call_args_list[2][0], ('step', expected))
开发者ID:eykd,项目名称:behave,代码行数:37,代码来源:test_summary.py

示例2: _fake_popen

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import __iter__ [as 别名]
    def _fake_popen( self, stdout, stderr, sleeptime ):
        def wait_stdout( self ):
            import time
            for line in stdout.splitlines():
                time.sleep(sleeptime)
                yield line

        def wait_stderr( self ):
            import time
            for line in stderr.splitlines():
                time.sleep(sleeptime)
                yield line

        m = Mock(spec=subprocess.Popen)
        sout = Mock()
        sout.read = stdout
        sout.__iter__ = wait_stdout

        serr = Mock()
        serr.read = stderr
        serr.__iter__ = wait_stderr
        
        m.return_value.stdout = sout
        m.return_value.stderr = serr
        return m
开发者ID:necrolyte2,项目名称:beast_whip,代码行数:27,代码来源:common.py

示例3: test_scenario_status_is_collected_and_reported

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import __iter__ [as 别名]
    def test_scenario_status_is_collected_and_reported(self, format_summary, 
												       stderr):
        # pylint: disable=W0621
        #   W0621   Redefining name ... from outer scope (format_summary)
        feature = Mock()
        scenarios = [Mock(), Mock(), Mock(), Mock(), Mock()]
        scenarios[0].status = 'failed'
        scenarios[0].__iter__ = Mock(return_value=iter([]))
        scenarios[1].status = 'failed'
        scenarios[1].__iter__ = Mock(return_value=iter([]))
        scenarios[2].status = 'skipped'
        scenarios[2].__iter__ = Mock(return_value=iter([]))
        scenarios[3].status = 'passed'
        scenarios[3].__iter__ = Mock(return_value=iter([]))
        scenarios[4].status = None
        scenarios[4].__iter__ = Mock(return_value=iter([]))
        feature.status = 'failed'
        feature.duration = 12.3
        feature.__iter__ = Mock(return_value=iter(scenarios))

        config = Mock()
        reporter = SummaryReporter(config)

        reporter.feature(feature)
        reporter.end()

        expected = {
            'passed': 1,
            'failed': 2,
            'skipped': 2,
            'untested': 0,
        }

        eq_(format_summary.call_args_list[1][0], ('scenario', expected))
开发者ID:hangtwenty,项目名称:behave,代码行数:36,代码来源:test_summary.py

示例4: test_checkout_deliveries_with_shipping_method

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import __iter__ [as 别名]
def test_checkout_deliveries_with_shipping_method(monkeypatch):
    shipping_cost = 5
    items_cost = 5

    partition = Mock(
        is_shipping_required=MagicMock(return_value=True),
        get_total=Mock(return_value=Price(items_cost, currency=settings.DEFAULT_CURRENCY)),
        get_price_per_item=Mock(return_value=Price(items_cost, currency=settings.DEFAULT_CURRENCY)))

    def f():
        yield partition

    partition.__iter__ = Mock(return_value=f())
    cart = Mock(partition=Mock(return_value=[partition]),
                currency=settings.DEFAULT_CURRENCY)

    shipping_method_mock = Mock(get_total=Mock(return_value=Price(shipping_cost, currency=settings.DEFAULT_CURRENCY)))
    monkeypatch.setattr(Checkout, 'shipping_method', shipping_method_mock)

    checkout = Checkout(
        cart, AnonymousUser(), 'tracking_code')

    deliveries = list(checkout.deliveries)
    assert deliveries[0][1] == Price(shipping_cost, currency=settings.DEFAULT_CURRENCY)
    assert deliveries[0][2] == Price(items_cost + shipping_cost, currency=settings.DEFAULT_CURRENCY)
    assert deliveries[0][0][0][0] == partition
开发者ID:fnugrahendi,项目名称:saleor,代码行数:28,代码来源:test_checkout.py

示例5: test_scenario_status_is_collected_and_reported

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import __iter__ [as 别名]
    def test_scenario_status_is_collected_and_reported(self, format_summary,
                                                       stdout):
        feature = Mock()
        scenarios = [Mock(), Mock(), Mock(), Mock(), Mock()]
        scenarios[0].status = Status.failed
        scenarios[0].__iter__ = Mock(return_value=iter([]))
        scenarios[1].status = Status.failed
        scenarios[1].__iter__ = Mock(return_value=iter([]))
        scenarios[2].status = Status.skipped
        scenarios[2].__iter__ = Mock(return_value=iter([]))
        scenarios[3].status = Status.passed
        scenarios[3].__iter__ = Mock(return_value=iter([]))
        scenarios[4].status = Status.untested
        scenarios[4].__iter__ = Mock(return_value=iter([]))
        feature.status = Status.failed
        feature.duration = 12.3
        feature.__iter__ = Mock(return_value=iter(scenarios))

        config = Mock()
        reporter = SummaryReporter(config)

        reporter.feature(feature)
        reporter.end()

        expected = {
            Status.passed.name: 1,
            Status.failed.name: 2,
            Status.skipped.name: 1,
            Status.untested.name: 1,
        }

        eq_(format_summary.call_args_list[1][0], ('scenario', expected))
开发者ID:Abdoctor,项目名称:behave,代码行数:34,代码来源:test_summary.py

示例6: test_catter

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import __iter__ [as 别名]
def test_catter():
    fs = Filesystem(DB(':memory:'))
    fs.root().add_file('zeroes', [test_asset_ids], 130)

    asset = Mock()
    asset.__enter__ = Mock(return_value=asset)
    asset.__exit__ = Mock(return_value=False)
    asset.status = Mock(return_value=proto.AssetStatus(size=1024 * 1024, status=proto.SUCCESS))
    asset.__iter__ = Mock(return_value=('\x00' * (128 * 1024) for _ in range(8)))

    bithorde = Mock()
    bithorde.open = Mock(return_value=asset)
    cat = Cat(fs, bithorde)

    sha = sha1()
    for chunk in cat(P('zeroes')):
        sha.update(chunk)
    assert_equals(sha.hexdigest(), '3b71f43ff30f4b15b5cd85dd9e95ebc7e84eb5a3')

    with assert_raises(FNotFound):
        for chunk in cat(P('NON-EXISTING')):
            pass

    asset.status = Mock(return_value=proto.AssetStatus(status=proto.NOTFOUND))
    with assert_raises(NotFoundError):
        for chunk in cat(P('zeroes')):
            pass
开发者ID:rawler,项目名称:bhindex,代码行数:29,代码来源:cat_test.py

示例7: test_scenario_status_is_collected_and_reported

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import __iter__ [as 别名]
    def test_scenario_status_is_collected_and_reported(self, format_summary,
                                                       stdout):
        feature = Mock()
        scenarios = [Mock(), Mock(), Mock(), Mock(), Mock()]
        scenarios[0].status = 'failed'
        scenarios[0].__iter__ = Mock(return_value=iter([]))
        scenarios[1].status = 'failed'
        scenarios[1].__iter__ = Mock(return_value=iter([]))
        scenarios[2].status = 'skipped'
        scenarios[2].__iter__ = Mock(return_value=iter([]))
        scenarios[3].status = 'passed'
        scenarios[3].__iter__ = Mock(return_value=iter([]))
        scenarios[4].status = None
        scenarios[4].__iter__ = Mock(return_value=iter([]))
        feature.status = 'failed'
        feature.duration = 12.3
        feature.__iter__ = Mock(return_value=iter(scenarios))

        config = Mock()
        config.order = ('defined', None)
        reporter = SummaryReporter(config)

        reporter.feature(feature)
        reporter.end()

        expected = {
            'passed': 1,
            'failed': 2,
            'skipped': 2,
            'untested': 0,
        }

        eq_(format_summary.call_args_list[1][0], ('scenario', expected))
开发者ID:Intersec,项目名称:behave,代码行数:35,代码来源:test_summary.py

示例8: test_magic_methods_isolated_between_mocks

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import __iter__ [as 别名]
    def test_magic_methods_isolated_between_mocks(self):
        mock1 = Mock()
        mock2 = Mock()

        mock1.__iter__ = Mock(return_value=iter([]))
        self.assertEqual(list(mock1), [])
        self.assertRaises(TypeError, lambda: list(mock2))
开发者ID:5m0k3r,项目名称:desarrollo_web_udp,代码行数:9,代码来源:testmagicmethods.py

示例9: testMagicMethodsIsolatedBetweenMocks

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import __iter__ [as 别名]
    def testMagicMethodsIsolatedBetweenMocks(self):
        mock1 = Mock()
        mock2 = Mock()

        mock1.__iter__ = Mock(return_value=iter([]))
        self.assertEqual(list(mock1), [])
        self.assertRaises(TypeError, lambda: list(mock2))
开发者ID:dzohrob,项目名称:input-lib,代码行数:9,代码来源:testmagicmethods.py

示例10: test_bound_methods

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import __iter__ [as 别名]
    def test_bound_methods(self):
        m = Mock()

        # XXXX should this be an expected failure instead?

        # this seems like it should work, but is hard to do without introducing
        # other api inconsistencies. Failure message could be better though.
        m.__iter__ = [3].__iter__
        self.assertRaises(TypeError, iter, m)
开发者ID:5m0k3r,项目名称:desarrollo_web_udp,代码行数:11,代码来源:testmagicmethods.py

示例11: test_set_admin

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import __iter__ [as 别名]
    def test_set_admin(self):
        user = "user"
        MockAdmin = Mock()
        MockAdmin.__iter__ = Mock(return_value=iter([user]))
        mock_set_secure_cookie = Mock()

        with patch.object(settings, 'ADMINISTRATORS', MockAdmin):
            with patch.object(self.auth_handler, 'set_secure_cookie', mock_set_secure_cookie):
                self.auth_handler.set_admin(user)

        mock_set_secure_cookie.assert_called_once_with('admin', 'true')
开发者ID:cnelsonsic,项目名称:SimpleMMO,代码行数:13,代码来源:test_authserver.py

示例12: make_mock_manifest

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import __iter__ [as 别名]
def make_mock_manifest(*items):
    rv = Mock(tests_root="/foobar")
    tests = []
    rv.__iter__ = lambda self: iter(tests)
    rv.__getitem__ = lambda self, k: tests[k]
    for test_type, dir_path, num_tests in items:
        for i in range(num_tests):
            filename = dir_path + "/%i.html" % i
            tests.append((test_type,
                          filename,
                          {TestharnessTest("/foo.bar", filename, "/", filename)}))
    return rv
开发者ID:Honry,项目名称:web-platform-tests,代码行数:14,代码来源:test_wpttest.py

示例13: queryset

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import __iter__ [as 别名]
 def queryset(self):
     """Mock "queryset" of instances with numeric id and unicode repr."""
     o1 = Mock()
     o1.pk = 1
     o1.__unicode__ = lambda self: "one"
     o2 = Mock()
     o2.pk = 2
     o2.__unicode__ = lambda self: "two"
     qs = Mock()
     qs.__iter__ = lambda self: iter([o1, o2])
     qs.all.return_value = qs
     return qs
开发者ID:ballacky13,项目名称:moztrap,代码行数:14,代码来源:test_filters.py

示例14: test_set_admin_not_administrator

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import __iter__ [as 别名]
    def test_set_admin_not_administrator(self):
        # Mock auth_handler.clear_cookie
        user = "user"
        MockAdmin = Mock()
        MockAdmin.__iter__ = Mock(return_value=iter([]))
        mock_clear_cookie = Mock()

        with patch.object(settings, 'ADMINISTRATORS', MockAdmin):
            with patch.object(self.auth_handler, 'clear_cookie', mock_clear_cookie):
                self.auth_handler.set_admin(user)

        mock_clear_cookie.assert_called_once_with('admin')
开发者ID:cnelsonsic,项目名称:SimpleMMO,代码行数:14,代码来源:test_authserver.py

示例15: test_step_status_is_collected_and_reported

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import __iter__ [as 别名]
    def test_step_status_is_collected_and_reported(self, format_summary,
                                                   stdout):
        feature = Mock()
        scenario = Mock()
        steps = [Mock(), Mock(), Mock(), Mock(), Mock()]
        steps[0].status = Status.failed
        steps[0].__iter__ = Mock(return_value=iter([]))
        steps[1].status = Status.passed
        steps[1].__iter__ = Mock(return_value=iter([]))
        steps[2].status = Status.passed
        steps[2].__iter__ = Mock(return_value=iter([]))
        steps[3].status = Status.skipped
        steps[4].__iter__ = Mock(return_value=iter([]))
        steps[4].status = Status.undefined
        steps[4].__iter__ = Mock(return_value=iter([]))
        feature.status = Status.failed
        feature.duration = 12.3
        feature.__iter__ = Mock(return_value=iter([scenario]))
        scenario.status = Status.failed
        scenario.__iter__ = Mock(return_value=iter(steps))

        config = Mock()
        sys.stdout.encoding = "UTF-8"
        reporter = SummaryReporter(config)

        reporter.feature(feature)
        reporter.end()

        expected = {
            "all": 5,
            Status.passed.name: 2,
            Status.failed.name: 1,
            Status.skipped.name: 1,
            Status.untested.name: 0,
            Status.undefined.name: 1,
        }

        step_index = 2  # HINT: Index for steps if not rules are used.
        expected_parts = ("step", expected)
        assert format_summary.call_args_list[step_index][0] == expected_parts
开发者ID:behave,项目名称:behave,代码行数:42,代码来源:test_summary.py


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