本文整理汇总了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
示例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)
示例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)
示例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)
示例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)
示例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)
示例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"])