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


Python mock.MagicMock方法代码示例

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


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

示例1: test_cookie_dict

# 需要导入模块: from mock import mock [as 别名]
# 或者: from mock.mock import MagicMock [as 别名]
def test_cookie_dict():
    c = RetsHttpClient('login_url', 'username', 'password')
    c._session = mock.MagicMock()
    jar = RequestsCookieJar()
    c1 = Cookie(1, 'name1', 'value1', 80, 80, 'domain', 'domain_specified', 'domain_initial_dot', 'path',
                'path_specified', True, True, False, 'comment', 'comment_url', 'rest')
    c2 = Cookie(1, 'name2', 'value2', 80, 80, 'domain', 'domain_specified', 'domain_initial_dot', 'path',
                'path_specified', True, True, False, 'comment', 'comment_url', 'rest')
    c3 = Cookie(1, 'name1', 'value1', 80, 80, 'domain', 'domain_specified3', 'domain_initial_dot3', 'path3',
                'path_specified3', True, True, False, 'comment', 'comment_url', 'rest')

    jar.set_cookie(c1)
    jar.set_cookie(c2)
    jar.set_cookie(c3)
    c._session.cookies = jar

    assert c.cookie_dict == {'name1': 'value1', 'name2': 'value2'} 
开发者ID:opendoor-labs,项目名称:rets,代码行数:19,代码来源:http_client_test.py

示例2: test_frame_focus_widget_property

# 需要导入模块: from mock import mock [as 别名]
# 或者: from mock.mock import MagicMock [as 别名]
def test_frame_focus_widget_property(self):
        """
        Check the frame exposes the focussed widget
        """
        screen = MagicMock(spec=Screen, colours=8, unicode_aware=False)
        canvas = Canvas(screen, 10, 40, 0, 0)
        form = TestFrame(canvas)
        form.reset()

        # If the Frame loses the focus it must not return a focussed widget.
        form._has_focus = False
        self.assertIsNone(form.focussed_widget)

        # If the Frame focus is undefined, it must not return a focussed widget.
        form._has_focus = True
        form._focus = 9999
        self.assertIsNone(form.focussed_widget) 
开发者ID:peterbrittain,项目名称:asciimatics,代码行数:19,代码来源:test_widgets.py

示例3: test_load_callback

# 需要导入模块: from mock import mock [as 别名]
# 或者: from mock.mock import MagicMock [as 别名]
def test_load_callback(self):
        """
        Check that the _on_load callback works as expected.
        """
        def _on_load():
            self._did_load = True

        # Reset state for test
        self._did_load = False

        # Create a dummy screen
        screen = MagicMock(spec=Screen, colours=8, unicode_aware=False)
        canvas = Canvas(screen, 2, 40, 0, 0)

        # Create the form we want to test.
        form = Frame(canvas, canvas.height, canvas.width, on_load=_on_load)
        form.fix()
        scene = Scene([form], -1)

        # Check only called on reset.
        self.assertEqual(self._did_load, False)
        scene.reset()
        self.assertEqual(self._did_load, True) 
开发者ID:peterbrittain,项目名称:asciimatics,代码行数:25,代码来源:test_widgets.py

示例4: test_frame_rate

# 需要导入模块: from mock import mock [as 别名]
# 或者: from mock.mock import MagicMock [as 别名]
def test_frame_rate(self):
        """
        Check Frame rate limiting works as expected.
        """
        screen = MagicMock(spec=Screen, colours=8, unicode_aware=False)
        canvas = Canvas(screen, 10, 40, 0, 0)
        form = TestFrame(canvas)
        form.reset()

        # With no special CPU consideration, and a cursor to animate, there
        # should be a 5 frame pause.
        self.assertEqual(form.reduce_cpu, False)
        self.assertEqual(form.frame_update_count, 5)

        # Shift focus away from a text input (to get no cursor animation).
        self.process_keys(form, [Screen.KEY_BACK_TAB])

        # With no special CPU consideration, and no cursors to animate, there
        # should be a (very!) long pause.
        self.assertEqual(form.reduce_cpu, False)
        self.assertEqual(form.frame_update_count, 1000000) 
开发者ID:peterbrittain,项目名称:asciimatics,代码行数:23,代码来源:test_widgets.py

示例5: test_cpu_saving

# 需要导入模块: from mock import mock [as 别名]
# 或者: from mock.mock import MagicMock [as 别名]
def test_cpu_saving(self):
        """
        Check Frame rate limiting is even more extreme when in cpu saving mode.
        """
        screen = MagicMock(spec=Screen, colours=8, unicode_aware=False)
        canvas = Canvas(screen, 10, 40, 0, 0)
        form = TestFrame(canvas, reduce_cpu=True)
        form.reset()

        # In this mode, it shouldn't matter where we are on the Frame - all
        # widgets will basically say they don't need animation.
        self.assertEqual(form.reduce_cpu, True)
        self.assertEqual(form.frame_update_count, 1000000)

        # Shift focus away from a text input, just to be sure.
        self.process_keys(form, [Screen.KEY_BACK_TAB])
        self.assertEqual(form.frame_update_count, 1000000) 
开发者ID:peterbrittain,项目名称:asciimatics,代码行数:19,代码来源:test_widgets.py

示例6: test_empty_frame

# 需要导入模块: from mock import mock [as 别名]
# 或者: from mock.mock import MagicMock [as 别名]
def test_empty_frame(self):
        """
        Check empty Frames still work.
        """
        screen = MagicMock(spec=Screen, colours=8, unicode_aware=False)
        canvas = Canvas(screen, 10, 40, 0, 0)
        scene = MagicMock(spec=Scene)
        form = TestFrame3(canvas)
        form.register_scene(scene)
        form.reset()

        # Check all keyboard events get swallowed
        self.assertIsNone(form.process_event(KeyboardEvent(ord("A"))))

        # Check Mouse events over the Frame are swallowed and others allowed
        # to bubble down the input stack.
        self.assertIsNone(
            form.process_event(MouseEvent(20, 5, MouseEvent.LEFT_CLICK)))
        self.assertIsNotNone(
            form.process_event(MouseEvent(5, 5, MouseEvent.LEFT_CLICK)))

        # Check form data is empty.
        form.save()
        self.assertEqual(form.data, {}) 
开发者ID:peterbrittain,项目名称:asciimatics,代码行数:26,代码来源:test_widgets.py

示例7: test_divider

# 需要导入模块: from mock import mock [as 别名]
# 或者: from mock.mock import MagicMock [as 别名]
def test_divider(self):
        """
        Check Divider widget sundry features work.
        """
        # Now set up the Frame ready for testing
        screen = MagicMock(spec=Screen, colours=8, unicode_aware=False)
        scene = Scene([], duration=-1)
        canvas = Canvas(screen, 10, 40, 0, 0)
        form = Frame(canvas, canvas.height, canvas.width)
        layout = Layout([100], fill_frame=True)
        form.add_layout(layout)
        divider = Divider(draw_line=False, height=7)
        layout.add_widget(divider)
        form.fix()
        form.register_scene(scene)
        form.reset()

        # Check events are ignored
        event = object()
        self.assertEqual(event, divider.process_event(event))

        # Check value is None
        self.assertIsNone(divider.value) 
开发者ID:peterbrittain,项目名称:asciimatics,代码行数:25,代码来源:test_widgets.py

示例8: test_find_widget

# 需要导入模块: from mock import mock [as 别名]
# 或者: from mock.mock import MagicMock [as 别名]
def test_find_widget(self):
        """
        Check find_widget works as expected.
        """
        # Set up the Frame ready for testing
        screen = MagicMock(spec=Screen, colours=8, unicode_aware=False)
        scene = Scene([], duration=-1)
        canvas = Canvas(screen, 10, 40, 0, 0)
        form = TestFrame5(canvas)
        scene.add_effect(form)
        scene.reset()

        # Can't find a non-existent widget
        self.assertIsNone(form.find_widget("ABLAH"))

        # Can find a defined widget
        self.assertEquals(form.find_widget("date"), form.date_widget) 
开发者ID:peterbrittain,项目名称:asciimatics,代码行数:19,代码来源:test_widgets.py

示例9: test_frame_themes

# 需要导入模块: from mock import mock [as 别名]
# 或者: from mock.mock import MagicMock [as 别名]
def test_frame_themes(self):
        """
        Check we can set a colour theme for a Frame.
        """
        # Now set up the Frame ready for testing
        screen = MagicMock(spec=Screen, colours=8, unicode_aware=False)
        scene = Scene([], duration=-1)
        canvas = Canvas(screen, 10, 40, 0, 0)
        form = Frame(canvas, canvas.height, canvas.width)

        # Check colour changes work...
        self.assertEqual(
            form.palette["background"],
            (Screen.COLOUR_WHITE, Screen.A_NORMAL, Screen.COLOUR_BLUE))
        form.set_theme("monochrome")
        self.assertEqual(
            form.palette["background"],
            (Screen.COLOUR_WHITE, Screen.A_NORMAL, Screen.COLOUR_BLACK))

        # Check that a bad theme name has no effect.
        form.set_theme("blah - this doesn't exist")
        self.assertEqual(
            form.palette["background"],
            (Screen.COLOUR_WHITE, Screen.A_NORMAL, Screen.COLOUR_BLACK)) 
开发者ID:peterbrittain,项目名称:asciimatics,代码行数:26,代码来源:test_widgets.py

示例10: test_max_len

# 需要导入模块: from mock import mock [as 别名]
# 或者: from mock.mock import MagicMock [as 别名]
def test_max_len(self):
        """
        Check that the max_length setting works as expected.
        """
        # Now set up the Frame ready for testing
        screen = MagicMock(spec=Screen, colours=8, unicode_aware=False)
        scene = Scene([], duration=-1)
        canvas = Canvas(screen, 10, 40, 0, 0)
        form = Frame(canvas, canvas.height, canvas.width)
        layout = Layout([100])
        form.add_layout(layout)

        # Simple form with a limited length Text field.
        text = Text(label="Text", name="max_len_text", max_length=4)
        layout.add_widget(text)
        form.fix()
        form.register_scene(scene)
        scene.add_effect(form)
        scene.reset()

        # Check it stops accepting text after hitting limit.
        self.process_keys(form, "123456")
        form.save()
        self.assertEqual(form.data["max_len_text"], "1234") 
开发者ID:peterbrittain,项目名称:asciimatics,代码行数:26,代码来源:test_widgets.py

示例11: test_scroll

# 需要导入模块: from mock import mock [as 别名]
# 或者: from mock.mock import MagicMock [as 别名]
def test_scroll(self):
        """
        Check that Scroll works.
        """
        # Check that it will attempt to scroll the screen at the required rate.
        screen = MagicMock(spec=Screen, colours=8, unicode_aware=False)
        effect = Scroll(screen, 2)
        effect.reset()
        effect.update(1)
        screen.scroll.assert_not_called()
        effect.update(2)
        screen.scroll.assert_called_once()

        # Check there is no stop frame
        self.assertEqual(effect.stop_frame, 0)

        # This effect should ignore events.
        event = object()
        self.assertEqual(event, effect.process_event(event)) 
开发者ID:peterbrittain,项目名称:asciimatics,代码行数:21,代码来源:test_effects.py

示例12: test_banner

# 需要导入模块: from mock import mock [as 别名]
# 或者: from mock.mock import MagicMock [as 别名]
def test_banner(self):
        """
        Check that BannerText works.
        """
        # Check that banner redraws every frame.
        screen = MagicMock(spec=Screen, colours=8, unicode_aware=False)
        canvas = Canvas(screen, 10, 100, 0, 0)
        effect = BannerText(canvas, StaticRenderer(images=["hello"]), 2, 3)
        effect.reset()
        effect.update(0)
        self.assertEqual(canvas.get_from(canvas.width - 1, 2),
                         (ord("h"), 3, 0, 0))
        effect.update(1)
        self.assertEqual(canvas.get_from(canvas.width - 1, 2),
                         (ord("e"), 3, 0, 0))

        # Check there is some stop frame - will vary according to screen width
        self.assertGreater(effect.stop_frame, 0)

        # This effect should ignore events.
        event = object()
        self.assertEqual(event, effect.process_event(event)) 
开发者ID:peterbrittain,项目名称:asciimatics,代码行数:24,代码来源:test_effects.py

示例13: test_mirage

# 需要导入模块: from mock import mock [as 别名]
# 或者: from mock.mock import MagicMock [as 别名]
def test_mirage(self):
        """
        Check that Mirage works.
        """
        # Check that Mirage randomly updates the Screen every other frame.
        screen = MagicMock(spec=Screen, colours=8, unicode_aware=False)
        canvas = Canvas(screen, 10, 40, 0, 0)
        effect = Mirage(canvas, FigletText("hello"), 3, 1)
        effect.reset()
        effect.update(0)
        self.assert_blank(canvas)
        effect.update(1)
        changed = False
        for x in range(canvas.width):
            for y in range(canvas.height):
                if canvas.get_from(x, y) != (32, 7, 0, 0):
                    changed = True
        self.assertTrue(changed)

        # Check there is no stop frame by default.
        self.assertEqual(effect.stop_frame, 0)

        # This effect should ignore events.
        event = object()
        self.assertEqual(event, effect.process_event(event)) 
开发者ID:peterbrittain,项目名称:asciimatics,代码行数:27,代码来源:test_effects.py

示例14: test_stars

# 需要导入模块: from mock import mock [as 别名]
# 或者: from mock.mock import MagicMock [as 别名]
def test_stars(self):
        """
        Check that Stars works.
        """
        # Check that Stars randomly updates the Screen every frame.
        screen = MagicMock(spec=Screen, colours=8, unicode_aware=False)
        canvas = Canvas(screen, 10, 40, 0, 0)
        effect = Stars(canvas, 100)
        effect.reset()
        self.assert_blank(canvas)
        my_buffer = [[(32, 7, 0, 0) for _ in range(40)] for _ in range(10)]
        for i in range(10):
            effect.update(i)
            self.assertTrue(self.check_canvas(
                canvas,
                my_buffer,
                lambda value: self.assertIn(chr(value[0]), " .+x*")))

        # Check there is no stop frame by default.
        self.assertEqual(effect.stop_frame, 0)

        # This effect should ignore events.
        event = object()
        self.assertEqual(event, effect.process_event(event)) 
开发者ID:peterbrittain,项目名称:asciimatics,代码行数:26,代码来源:test_effects.py

示例15: test_stars_pattern

# 需要导入模块: from mock import mock [as 别名]
# 或者: from mock.mock import MagicMock [as 别名]
def test_stars_pattern(self):
        """
        Check that Stars custom pattern value works.
        """
        # Check that Stars randomly updates the Screen every frame.
        screen = MagicMock(spec=Screen, colours=8, unicode_aware=False)
        canvas = Canvas(screen, 10, 40, 0, 0)
        effect = Stars(canvas, 100, "TESTTESTTEST")
        effect.reset()
        my_buffer = [[(32, 7, 0, 0) for _ in range(40)] for _ in range(10)]
        for i in range(10):
            effect.update(i)
            self.assertTrue(self.check_canvas(
                canvas,
                my_buffer,
                lambda value: self.assertIn(chr(value[0]), " TES"))) 
开发者ID:peterbrittain,项目名称:asciimatics,代码行数:18,代码来源:test_effects.py


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