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


Python Mock.x方法代码示例

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


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

示例1: create_mock_aristo_data

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import x [as 别名]
def create_mock_aristo_data(data):
    mock_data = Mock(AristoData)
    mock_data.x = pd.DataFrame.from_records([data], index=["id"],
                                                  columns=("id", "question", "A", "B", "C", "D", "answer"))
    mock_data.y = mock_data.x[['answer']]
    mock_data.x = mock_data.x[["question", "A", "B", "C", "D"]]

    return mock_data
开发者ID:elangovana,项目名称:Aristo,代码行数:10,代码来源:integrationtest_solr_wikipedia_pipeline.py

示例2: create_mock_train_test_aristo_data

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import x [as 别名]
def create_mock_train_test_aristo_data(train_data, test_question):
    mock_train_data = Mock(AristoData)
    mock_train_data.x = pd.DataFrame.from_records(train_data, index=["id"],
                                                  columns=("id", "question", "A", "B", "C", "D", "answer"))
    mock_train_data.y = mock_train_data.x[['answer']]
    mock_train_data.x = mock_train_data.x[["question", "A", "B", "C", "D"]]
    mock_test_data = Mock(AristoData)
    mock_test_data.x = pd.DataFrame.from_records([test_question], index=["id"],
                                                 columns=("id", "question", "A", "B", "C", "D"))
    mock_test_data.y = None
    return (mock_train_data, mock_test_data)
开发者ID:elangovana,项目名称:Aristo,代码行数:13,代码来源:unittest_similarity_pipeline.py

示例3: do_event

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import x [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

示例4: test_setting_attribute_with_spec_set

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import x [as 别名]
    def test_setting_attribute_with_spec_set(self):
        class X(object):
            y = 3

        mock = Mock(spec=X)
        mock.x = 'foo'

        mock = Mock(spec_set=X)
        def set_attr():
            mock.x = 'foo'

        mock.y = 'foo'
        self.assertRaises(AttributeError, set_attr)
开发者ID:MarkTseng,项目名称:cpython,代码行数:15,代码来源:testmock.py

示例5: test_setting_attribute_with_spec_set

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import x [as 别名]
    def test_setting_attribute_with_spec_set(self):

        class X(object):
            __qualname__ = 'MockTest.test_setting_attribute_with_spec_set.<locals>.X'
            y = 3

        mock = Mock(spec=X)
        mock.x = 'foo'
        mock = Mock(spec_set=X)

        def set_attr():
            mock.x = 'foo'

        mock.y = 'foo'
        self.assertRaises(AttributeError, set_attr)
开发者ID:johndpope,项目名称:sims4-ai-engine,代码行数:17,代码来源:testmock.py

示例6: test_rmenu

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import x [as 别名]
 def test_rmenu(self):
     """Test the context menu."""
     squeezer = self.make_mock_squeezer()
     expandingbutton = ExpandingButton('TEXT', 'TAGS', 50, squeezer)
     with patch('tkinter.Menu') as mock_Menu:
         mock_menu = Mock()
         mock_Menu.return_value = mock_menu
         mock_event = Mock()
         mock_event.x = 10
         mock_event.y = 10
         expandingbutton.context_menu_event(event=mock_event)
         self.assertEqual(mock_menu.add_command.call_count,
                          len(expandingbutton.rmenu_specs))
         for label, *data in expandingbutton.rmenu_specs:
             mock_menu.add_command.assert_any_call(label=label, command=ANY)
开发者ID:FFMG,项目名称:myoddweb.piger,代码行数:17,代码来源:test_squeezer.py

示例7: test_hitObjects

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import x [as 别名]
    def test_hitObjects(self):
        bge = Mock()

        sensors = []
        raySensor = Mock(None)
        raySensor.x = 1
        sensors.append(Mock(spec_set=["hitObject"]))
        sensors[0].hitObject = "A"
        sensors.append(Mock())
        sensors[1].hitObjectList = ["B"]
        sensors.append(Mock())
        sensors[2].hitObjectList = ["C", "D"]
        bge.logic.getCurrentController().sensors = sensors
        with patch.dict("sys.modules", {"bge": bge}):
            from mutil import sensors

            self.assertEqual(sensors.hitObjects, ["A", "B", "C", "D"])
开发者ID:BlenderMonster,项目名称:Gravitovores,代码行数:19,代码来源:test_sensors.py


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