本文整理汇总了Python中mock.PropertyMock.__exit__方法的典型用法代码示例。如果您正苦于以下问题:Python PropertyMock.__exit__方法的具体用法?Python PropertyMock.__exit__怎么用?Python PropertyMock.__exit__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mock.PropertyMock
的用法示例。
在下文中一共展示了PropertyMock.__exit__方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: mock_connection
# 需要导入模块: from mock import PropertyMock [as 别名]
# 或者: from mock.PropertyMock import __exit__ [as 别名]
def mock_connection():
mock_connection = PropertyMock()
class MockCursor(object):
def __init__(self, *args, **kwargs):
self.statements = []
self.return_rows = []
self.cursor_position = 0
def execute(self, statement, *args, **kwargs):
self.statements.append(statement)
def fetchone(self, *args, **kwargs):
if self.cursor_position > len(self.return_rows) - 1:
return None
else:
next_row = self.return_rows[self.cursor_position]
self.cursor_position += 1
return next_row
def __enter__(self, *args, **kwargs):
return self
def __exit__(self, *args, **kwargs):
return
def __iter__(self):
for row in self.return_rows:
yield row
mock_cursor = MockCursor()
mock_connection_enter = MagicMock()
mock_connection_enter.cursor.return_value = mock_cursor
mock_connection.return_value = mock_connection
mock_connection.cursor.return_value = mock_cursor
mock_connection.__enter__ = lambda x: mock_connection_enter
mock_connection.__exit__ = MagicMock()
return mock_connection
示例2: mock_connection
# 需要导入模块: from mock import PropertyMock [as 别名]
# 或者: from mock.PropertyMock import __exit__ [as 别名]
def mock_connection():
mock_connection = PropertyMock()
mock_connection.return_value = mock_connection
mock_connection.__enter__ = MagicMock()
mock_connection.__exit__ = MagicMock()
return mock_connection