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


Python Mock.key方法代码示例

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


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

示例1: test_gamestate_handle_events_pause_quit

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import key [as 别名]
def test_gamestate_handle_events_pause_quit(Dungeon, event_get, fontinit):
    waves = MagicMock()
    waves.__len__.return_value = 2

    def event_get_called():
        return cur_events

    event_get.side_effect = event_get_called

    d = Mock()
    d.walls = []
    Dungeon.load.return_value = d

    gs = gamestate.GameState()
    assert not gs.paused
    assert gs.running

    # No events, no changes.
    cur_events = []
    gs.handle_events()
    assert not gs.paused
    assert gs.running
    assert event_get.call_count == 1

    # 'quit' -- q -> not-running
    event_key_q = Mock()
    event_key_q.type = pygame.KEYDOWN
    event_key_q.key = pygame.K_q
    cur_events = [event_key_q]
    gs.handle_events()
    assert not gs.paused
    assert not gs.running
    assert event_get.call_count == 2

    # 'pause' -- p -> paused, p -> unpaused
    gs = gamestate.GameState()
    event_key_p = Mock()
    event_key_p.type = pygame.KEYDOWN
    event_key_p.key = pygame.K_p
    cur_events = [event_key_p]
    gs.handle_events()
    assert gs.paused
    assert gs.running

    # (toggle-unpaused)
    gs.handle_events()
    assert not gs.paused
    assert gs.running

    # (toggle-paused, then quit while paused)
    gs.handle_events()
    assert gs.paused
    assert gs.running
    cur_events = [event_key_q]
    gs.handle_events()
    assert gs.paused
    assert not gs.running
开发者ID:bstpierre,项目名称:yendor,代码行数:59,代码来源:test_gamestate.py

示例2: test_fire

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import key [as 别名]
    def test_fire(self, mock_load_png_sequence, mock_pulsator,
                  mock_bullet_class):
        img, rect = Mock(), Mock()
        mock_image_sequence = [(img, rect)]
        mock_load_png_sequence.return_value = mock_image_sequence
        mock_paddle = Mock()
        mock_paddle.rect.center = (100, 100)
        mock_paddle.rect.bottomleft = (60, 120)
        mock_paddle.rect.width = 50
        mock_game = Mock()
        mock_event = Mock()
        mock_event.key = pygame.K_SPACE
        mock_bullet1, mock_bullet2 = Mock(), Mock()
        mock_bullet_class.side_effect = mock_bullet1, mock_bullet2

        state = LaserState(mock_paddle, mock_game)
        state._fire(mock_event)

        mock_bullet_class.assert_has_calls(
            [call(mock_game, position=(70, 120)),
             call(mock_game, position=(100, 120))])
        self.assertEqual(len(state._bullets), 2)
        mock_game.sprites.append.assert_has_calls([call(mock_bullet1),
                                                   call(mock_bullet2)])
        mock_bullet1.release.assert_called_once_with()
        mock_bullet2.release.assert_called_once_with()
开发者ID:wkeeling,项目名称:arkanoid,代码行数:28,代码来源:test_paddle.py

示例3: _get_recursive_structure

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import key [as 别名]
 def _get_recursive_structure(self, structure, path, parent):
     if not isinstance(structure, dict) or len(structure) == 0:
         parent.value = structure
         return
     for key, subdict in structure.items():
             child = Mock()
             child.value = None
             child.key = path + "/" + key
             parent.children.append(child)
             self._get_recursive_structure(subdict, child.key, child)
开发者ID:carriercomm,项目名称:dynamite,代码行数:12,代码来源:FakeEtcdClient.py

示例4: test_release_ball

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import key [as 别名]
    def test_release_ball(self, mock_pygame, mock_load_png_sequence):
        mock_game = _configure_mocks(mock_load_png_sequence, mock_pygame)
        mock_game.balls = [Mock(), Mock(), Mock()]
        mock_event = Mock()
        mock_event.key = mock_pygame.K_SPACE  # Spacebar event

        catch_powerup = CatchPowerUp(mock_game, Mock())
        catch_powerup._release_ball(mock_event)

        for ball in mock_game.balls:
            ball.release.assert_called_once_with()
开发者ID:wkeeling,项目名称:arkanoid,代码行数:13,代码来源:test_powerup.py

示例5: test_release_ball_when_other_key_pressed

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import key [as 别名]
    def test_release_ball_when_other_key_pressed(self, mock_pygame,
                                                 mock_load_png_sequence):
        mock_game = _configure_mocks(mock_load_png_sequence, mock_pygame)
        mock_game.balls = [Mock(), Mock(), Mock()]
        mock_event = Mock()
        mock_event.key = mock_pygame.SOME_OTHER_KEY

        catch_powerup = CatchPowerUp(mock_game, Mock())
        catch_powerup._release_ball(mock_event)

        for ball in mock_game.balls:
            self.assertEqual(ball.call_count, 0)
开发者ID:wkeeling,项目名称:arkanoid,代码行数:14,代码来源:test_powerup.py

示例6: do_event

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import key [as 别名]
def do_event(tool, etype, button=1, xdata=0, ydata=0, key=None, step=1):
    """
     *name*
        the event name

    *canvas*
        the FigureCanvas instance generating the event

    *guiEvent*
        the GUI event that triggered the matplotlib event

    *x*
        x position - pixels from left of canvas

    *y*
        y position - pixels from bottom of canvas

    *inaxes*
        the :class:`~matplotlib.axes.Axes` instance if mouse is over axes

    *xdata*
        x coord of mouse in data coords

    *ydata*
        y coord of mouse in data coords

     *button*
        button pressed None, 1, 2, 3, 'up', 'down' (up and down are used
        for scroll events)

    *key*
        the key depressed when the mouse event triggered (see
        :class:`KeyEvent`)

    *step*
        number of scroll steps (positive for 'up', negative for 'down')
    """
    event = Mock()
    event.button = button
    ax = tool.ax
    event.x, event.y = ax.transData.transform([(xdata, ydata),
                                               (xdata, ydata)])[00]
    event.xdata, event.ydata = xdata, ydata
    event.inaxes = ax
    event.canvas = ax.figure.canvas
    event.key = key
    event.step = step
    event.guiEvent = None
    event.name = 'Custom'

    func = getattr(tool, etype)
    func(event)
开发者ID:QuLogic,项目名称:matplotlib,代码行数:54,代码来源:test_widgets.py

示例7: test_operations_evaluated

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import key [as 别名]
    def test_operations_evaluated(self, mock_fetch_data: Mock, *mocks):
        mock_operation = Mock(name='mock_operation ', spec=f.Operation)
        mock_operation.key, mock_operation.definition = 'mock_operation', slicer.table.abc
        mock_operation.metrics = []

        mock_widget = f.Widget(mock_operation)
        mock_widget.transform = Mock()

        mock_df = {}
        mock_fetch_data.return_value = mock_df

        # Need to keep widget the last call in the chain otherwise the object gets cloned and the assertion won't work
        slicer.data \
            .dimension(slicer.dimensions.timestamp) \
            .widget(mock_widget) \
            .fetch()

        mock_operation.apply.assert_called_once_with(mock_df, None)
开发者ID:kayak,项目名称:fireant,代码行数:20,代码来源:test_pagination.py

示例8: test_fire_no_space

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import key [as 别名]
    def test_fire_no_space(self, mock_load_png_sequence, mock_pulsator,
                           mock_bullet_class):
        """Test that fire does not happen when spacebar not pressed.
        """
        img, rect = Mock(), Mock()
        mock_image_sequence = [(img, rect)]
        mock_load_png_sequence.return_value = mock_image_sequence
        mock_paddle = Mock()
        mock_paddle.rect.center = (100, 100)
        mock_paddle.rect.bottomleft = (60, 120)
        mock_paddle.rect.width = 50
        mock_game = Mock()
        mock_event = Mock()
        mock_event.key = pygame.KEYUP

        state = LaserState(mock_paddle, mock_game)
        state._fire(mock_event)

        self.assertEqual(mock_bullet_class.call_count, 0)
开发者ID:wkeeling,项目名称:arkanoid,代码行数:21,代码来源:test_paddle.py

示例9: test_operations_results_stored_in_data_frame

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import key [as 别名]
    def test_operations_results_stored_in_data_frame(self, mock_fetch_data: Mock, *mocks):
        mock_operation = Mock(name='mock_operation ', spec=f.Operation)
        mock_operation.key, mock_operation.definition = 'mock_operation', slicer.table.abc
        mock_operation.metrics = []

        mock_widget = f.Widget(mock_operation)
        mock_widget.transform = Mock()

        mock_df = {}
        mock_fetch_data.return_value = mock_df

        # Need to keep widget the last call in the chain otherwise the object gets cloned and the assertion won't work
        slicer.data \
            .dimension(slicer.dimensions.timestamp) \
            .widget(mock_widget) \
            .fetch()

        f_op_key = format_metric_key(mock_operation.key)
        self.assertIn(f_op_key, mock_df)
        self.assertEqual(mock_df[f_op_key], mock_operation.apply.return_value)
开发者ID:kayak,项目名称:fireant,代码行数:22,代码来源:test_pagination.py

示例10: test_fire_max

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import key [as 别名]
    def test_fire_max(self, mock_load_png_sequence, mock_pulsator,
                      mock_bullet_class):
        """Test that it is not possible to fire 2 more bullets if there are
        already 3 or more in the air.
        """
        img, rect = Mock(), Mock()
        mock_image_sequence = [(img, rect)]
        mock_load_png_sequence.return_value = mock_image_sequence
        mock_paddle = Mock()
        mock_paddle.rect.center = (100, 100)
        mock_paddle.rect.bottomleft = (60, 120)
        mock_paddle.rect.width = 50
        mock_game = Mock()
        mock_event = Mock()
        mock_event.key = pygame.K_SPACE

        state = LaserState(mock_paddle, mock_game)
        state._bullets.extend([Mock()] * 3)
        state._fire(mock_event)

        self.assertEqual(mock_bullet_class.call_count, 0)
开发者ID:wkeeling,项目名称:arkanoid,代码行数:23,代码来源:test_paddle.py


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