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


Python MagicMock.execute方法代码示例

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


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

示例1: test_execute_query1

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import execute [as 别名]
    def test_execute_query1(self):
        m_execute = Mock()
        expected = [(17, 22), (19, 24)]
        returns = [(17, 22), (19, 24), None]

        def foo(*args):
            r = returns.pop(0)
            return r
        m_fetchone = Mock(side_effect=foo)
        m_cursor = MagicMock()
        m_cursor.execute = m_execute
        m_cursor.fetchone = m_fetchone
        conn = MagicMock()
        conn.cursor.return_value.__enter__.return_value = m_cursor

        zipped = zip(
            dbapi2_util.execute_query_iter(
                conn,
                "select * from somewhere"
            ),
            expected
        )
        for x, y in zipped:
            eq_(x, y)
        eq_(conn.cursor.call_count, 1)
        eq_(m_cursor.execute.call_count, 1)
        m_cursor.execute.assert_called_once_with("select * from somewhere",
                                                 None)
开发者ID:snorp,项目名称:socorro,代码行数:30,代码来源:test_dbapi2_util.py

示例2: _setup

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import execute [as 别名]
def _setup():
    global reconnect_handler, session_manager, session_list, path, kernel_id, kernel_manager,\
     individual_kernel_manager, response_id, good_msg, client, spark_events, request

    # Mock kernel manager
    client = MagicMock()
    client.execute = MagicMock(return_value=response_id)
    client.get_shell_msg = MagicMock(return_value=good_msg)
    individual_kernel_manager = MagicMock()
    individual_kernel_manager.client = MagicMock(return_value=client)
    kernel_manager = MagicMock()
    kernel_manager.get_kernel = MagicMock(return_value=individual_kernel_manager)

    # Mock session manager
    session_list = [create_session_dict(path, kernel_id)]
    session_manager = MagicMock()
    session_manager.list_sessions = MagicMock(return_value=session_list)

    # Mock spark events
    spark_events = MagicMock()

    # Mock request 
    request = MagicMock()
    request.body = json.dumps({"path": path, "username": username, "password": password, "endpoint": endpoint})

    # Create mocked reconnect_handler        
    ReconnectHandler.__bases__ = (SimpleObject,)
    reconnect_handler = ReconnectHandler()
    reconnect_handler.spark_events = spark_events
    reconnect_handler.session_manager = session_manager
    reconnect_handler.kernel_manager = kernel_manager
    reconnect_handler.set_status = MagicMock()
    reconnect_handler.finish = MagicMock()
    reconnect_handler.current_user = 'alex'
    reconnect_handler.request = request
开发者ID:jupyter-incubator,项目名称:sparkmagic,代码行数:37,代码来源:test_handlers.py

示例3: test_procedure

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import execute [as 别名]
    def test_procedure(self):
        manager = MagicMock()
        manager.execute = MagicMock(return_value='expected')

        with self.assertRaises(TypeError):
            Procedure('wrong', manager)

        p = Procedure(F('sum'), manager)

        ast = p.to_ast()

        self.assertEqual(
            ast,
            {
                'name': 'run',
                'val': {
                    'name': 'func_sum',
                    'val': []
                }
            }
        )

        result = p()

        self.assertEqual(result, 'expected')
        manager.execute.assert_called_with(
            p.to_ast(),
            scope=[]
        )
开发者ID:linkdd,项目名称:link.dbrequest,代码行数:31,代码来源:lazy.py

示例4: setUp

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import execute [as 别名]
 def setUp(self):
     # instantiate broker for testing
     self.sommelier_broker = SommelierBroker()
     # create mock DB
     db = MagicMock()
     db.execute = MagicMock()
     db.fetch_all = MagicMock()
     db.fetch_one = MagicMock()
     # inject mock db into broker
     self.sommelier_broker.db = db
开发者ID:pgchamberlin,项目名称:sommelier,代码行数:12,代码来源:brokers_test.py

示例5: testNextTurn

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import execute [as 别名]
    def testNextTurn(self):
        from game import Game
        g = Game()

        #Create mock objects
        helpCommand = MagicMock()
        helpCommand.execute = MagicMock()
        g._parser.getNextCommand = MagicMock(return_value=helpCommand)

        g._nextTurn()
        self.assertTrue(helpCommand.execute.called, "Game._nextTurn() failed to execute command")
开发者ID:dchukhin,项目名称:lord-of-the-rings,代码行数:13,代码来源:test.py

示例6: SideEffect1

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import execute [as 别名]
 def SideEffect1(groupKey, pageToken=''):
   """Mock list function to return different mock execute calls."""
   # pylint: disable=unused-argument
   # pylint: disable=invalid-name
   if pageToken == '':
     mock_execute.return_value = fake_dictionary_1
   else:
     mock_execute.return_value = fake_dictionary_2
   some_object = MagicMock()
   some_object.execute = mock_execute
   return some_object
开发者ID:uProxy,项目名称:ufo-management-server,代码行数:13,代码来源:google_directory_service_test.py

示例7: SideEffect

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import execute [as 别名]
 def SideEffect(customer, maxResults, pageToken, projection, orderBy):
   """Mock list function to return different mock execute calls."""
   # pylint: disable=unused-argument
   # pylint: disable=invalid-name
   if pageToken == '':
     mock_execute.return_value = fake_dictionary_1
   else:
     mock_execute.return_value = fake_dictionary_2
   some_object = MagicMock()
   some_object.execute = mock_execute
   return some_object
开发者ID:uProxy,项目名称:ufo-management-server,代码行数:13,代码来源:google_directory_service_test.py

示例8: test_single_value_sql5

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import execute [as 别名]
    def test_single_value_sql5(self):
        m_execute = Mock()
        m_fetchall = Mock(return_value=((17, 22),))
        m_cursor = MagicMock()
        m_cursor.execute = m_execute
        m_cursor.fetchall = m_fetchall
        conn = MagicMock()
        conn.cursor.return_value.__enter__.return_value = m_cursor

        dbapi2_util.single_row_sql(conn, "select 17, 22", (1, 2, 3))
        eq_(conn.cursor.call_count, 1)
        eq_(m_cursor.execute.call_count, 1)
        m_cursor.execute.assert_called_once_with("select 17, 22", (1, 2, 3))
开发者ID:snorp,项目名称:socorro,代码行数:15,代码来源:test_dbapi2_util.py

示例9: test_single_value_sql2

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import execute [as 别名]
    def test_single_value_sql2(self):
        m_execute = Mock()
        m_fetchall = Mock(return_value=((17,),))
        m_cursor = MagicMock()
        m_cursor.execute = m_execute
        m_cursor.fetchall = m_fetchall
        conn = MagicMock()
        conn.cursor.return_value.__enter__.return_value = m_cursor

        dbapi2_util.single_value_sql(conn, "select 17", (1, 2, 3))
        assert conn.cursor.call_count == 1
        assert m_cursor.execute.call_count == 1
        m_cursor.execute.assert_called_once_with('select 17', (1, 2, 3))
开发者ID:stephendonner,项目名称:socorro,代码行数:15,代码来源:test_dbapi2_util.py

示例10: test_single_value_sql1

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import execute [as 别名]
    def test_single_value_sql1(self):
        m_execute = Mock()
        m_fetchall = Mock(return_value=((17,),))
        m_cursor = MagicMock()
        m_cursor.execute = m_execute
        m_cursor.fetchall = m_fetchall
        conn = MagicMock()
        conn.cursor.return_value.__enter__.return_value = m_cursor

        r = dbapi2_util.single_value_sql(conn, "select 17")
        eq_(r, 17)
        eq_(conn.cursor.call_count, 1)
        eq_(m_cursor.execute.call_count, 1)
        m_cursor.execute.assert_called_once_with('select 17', None)
开发者ID:snorp,项目名称:socorro,代码行数:16,代码来源:test_dbapi2_util.py

示例11: test_single_value_sql4

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import execute [as 别名]
    def test_single_value_sql4(self):
        m_execute = Mock()
        m_fetchall = Mock(return_value=None)
        m_cursor = MagicMock()
        m_cursor.execute = m_execute
        m_cursor.fetchall = m_fetchall
        conn = MagicMock()
        conn.cursor.return_value.__enter__.return_value = m_cursor

        with pytest.raises(dbapi2_util.SQLDidNotReturnSingleRow):
            dbapi2_util.single_row_sql(conn, 'select 17, 22', (1, 2, 3))
        assert conn.cursor.call_count == 1
        assert m_cursor.execute.call_count == 1
        m_cursor.execute.assert_called_once_with("select 17, 22", (1, 2, 3))
开发者ID:stephendonner,项目名称:socorro,代码行数:16,代码来源:test_dbapi2_util.py

示例12: test_single_row_sql1

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import execute [as 别名]
    def test_single_row_sql1(self):
        m_execute = Mock()
        m_fetchall = Mock(return_value=((17, 22),))
        m_cursor = MagicMock()
        m_cursor.execute = m_execute
        m_cursor.fetchall = m_fetchall
        conn = MagicMock()
        conn.cursor.return_value.__enter__.return_value = m_cursor

        r = dbapi2_util.single_row_sql(conn, "select 17, 22")
        assert r == (17, 22)
        assert conn.cursor.call_count == 1
        assert m_cursor.execute.call_count == 1
        m_cursor.execute.assert_called_once_with('select 17, 22', None)
开发者ID:stephendonner,项目名称:socorro,代码行数:16,代码来源:test_dbapi2_util.py

示例13: test_single_value_sql4

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import execute [as 别名]
    def test_single_value_sql4(self):
        m_execute = Mock()
        m_fetchall = Mock(return_value=None)
        m_cursor = MagicMock()
        m_cursor.execute = m_execute
        m_cursor.fetchall = m_fetchall
        conn = MagicMock()
        conn.cursor.return_value.__enter__.return_value = m_cursor

        assert_raises(dbapi2_util.SQLDidNotReturnSingleRow,
                          dbapi2_util.single_row_sql,
                          conn,
                          "select 17, 22",
                          (1, 2, 3))
        eq_(conn.cursor.call_count, 1)
        eq_(m_cursor.execute.call_count, 1)
        m_cursor.execute.assert_called_once_with("select 17, 22", (1, 2, 3))
开发者ID:snorp,项目名称:socorro,代码行数:19,代码来源:test_dbapi2_util.py

示例14: test_execute_no_results

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import execute [as 别名]
    def test_execute_no_results(self):
        m_execute = Mock()
        m_cursor = MagicMock()
        m_cursor.execute = m_execute
        conn = MagicMock()
        conn.cursor.return_value.__enter__.return_value = m_cursor

        dbapi2_util.execute_no_results(
          conn,
          "insert into table (a, b, c) values (%s, %s, %s)",
          (1, 2, 3)
        )
        eq_(conn.cursor.call_count, 1)
        eq_(m_cursor.execute.call_count, 1)
        m_cursor.execute.assert_called_once_with(
          "insert into table (a, b, c) values (%s, %s, %s)",
          (1, 2, 3)
        )
开发者ID:snorp,项目名称:socorro,代码行数:20,代码来源:test_dbapi2_util.py

示例15: test_execute_query2

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import execute [as 别名]
    def test_execute_query2(self):
        m_execute = Mock()
        expected = []
        returns = [None]

        def foo(*args):
            r = returns.pop(0)
            return r
        m_fetchone = Mock(side_effect=foo)
        m_cursor = MagicMock()
        m_cursor.execute = m_execute
        m_cursor.fetchone = m_fetchone
        conn = MagicMock()
        conn.cursor.return_value.__enter__.return_value = m_cursor

        zipped = zip(dbutil.execute_query_iter(conn, "select * from somewhere"), expected)
        for x, y in zipped:
            assert x == y
        assert conn.cursor.call_count == 1
        assert m_cursor.execute.call_count == 1
        m_cursor.execute.assert_called_once_with("select * from somewhere", None)
开发者ID:willkg,项目名称:socorro,代码行数:23,代码来源:test_dbutil.py


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