本文整理匯總了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'}
示例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)
示例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)
示例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)
示例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)
示例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, {})
示例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)
示例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)
示例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))
示例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")
示例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))
示例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))
示例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))
示例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))
示例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")))