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


Python PropertyMock.__exit__方法代码示例

本文整理汇总了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
开发者ID:alialliallie,项目名称:shiftmanager,代码行数:42,代码来源:conftest.py

示例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
开发者ID:jklukas,项目名称:shiftmanager,代码行数:8,代码来源:conftest.py


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