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


Python PropertyMock.assert_has_calls方法代码示例

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


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

示例1: test_load_one_workspace

# 需要导入模块: from mock import PropertyMock [as 别名]
# 或者: from mock.PropertyMock import assert_has_calls [as 别名]
    def test_load_one_workspace(self, get_ws_handle_mock, load_mock, process_limits):
        # Create a view that will return a path on call to get_workspace_to_load_path
        tempdir = gettempdir()  # To ensure sample paths are valid on platform of execution
        path_to_nexus = join(tempdir, 'cde.nxs')
        workspace_name = 'cde'
        self.view.get_workspace_efixed = mock.Mock(return_value=(1.845, False))
        ws_mock = mock.Mock(spec=Workspace)
        get_ws_handle_mock.return_value = ws_mock
        e_fixed = PropertyMock()
        e_mode = PropertyMock(return_value="Indirect")
        ef_defined = PropertyMock(return_value=False)
        type(ws_mock).e_fixed = e_fixed
        type(ws_mock).e_mode = e_mode
        type(ws_mock).ef_defined = ef_defined

        with patch('mslice.models.workspacemanager.workspace_algorithms.get_workspace_handle') as gwh:
            gwh.return_value = ws_mock
            limits = PropertyMock(side_effect=({} if i < 2 else {'DeltaE':[-1, 1]} for i in range(6)))
            type(ws_mock).limits = limits
            e_fixed.return_value = 1.845
            self.presenter.load_workspace([path_to_nexus])
        load_mock.assert_called_with(filename=path_to_nexus, output_workspace=workspace_name)
        e_fixed.assert_has_calls([call(1.845), call()])
        process_limits.assert_called_once_with(ws_mock)
        self.main_presenter.show_workspace_manager_tab.assert_called_once()
        self.main_presenter.show_tab_for_workspace.assert_called_once()
        self.main_presenter.update_displayed_workspaces.assert_called_once()
开发者ID:mantidproject,项目名称:mslice,代码行数:29,代码来源:data_loader_test.py

示例2: test__disable_events__all

# 需要导入模块: from mock import PropertyMock [as 别名]
# 或者: from mock.PropertyMock import assert_has_calls [as 别名]
    def test__disable_events__all(self, mock_events):
        """Test disabling all events."""
        mock_event1 = MagicMock(spec=HoudiniEvent)

        mock_enabled1 = PropertyMock(return_value=False)
        type(mock_event1).enabled = mock_enabled1

        mock_event2 = MagicMock(spec=HoudiniEvent)

        mock_enabled2 = PropertyMock(return_value=True)
        type(mock_event2).enabled = mock_enabled2

        mock_events.return_value = {
            mock_event1.name: mock_event1,
            mock_event2.name: mock_event2,
        }

        manager = ht.events.manager.HoudiniEventManager()
        manager._event_states = {}

        manager._disable_events()

        # Each event should have it's enabled property accessed twice:
        # once to store the current value and then to set the value to False
        mock_enabled1.assert_has_calls([call(), call(False)])
        mock_enabled2.assert_has_calls([call(), call(False)])

        self.assertFalse(manager._event_states[mock_event1.name])
        self.assertTrue(manager._event_states[mock_event2.name])
开发者ID:captainhammy,项目名称:Houdini-Toolbox,代码行数:31,代码来源:test_manager.py

示例3: test__disable_events__specific_names

# 需要导入模块: from mock import PropertyMock [as 别名]
# 或者: from mock.PropertyMock import assert_has_calls [as 别名]
    def test__disable_events__specific_names(self, mock_events):
        """Test disabling specific events."""
        mock_event1 = MagicMock(spec=HoudiniEvent)

        mock_enabled1 = PropertyMock(return_value=True)
        type(mock_event1).enabled = mock_enabled1

        mock_event2 = MagicMock(spec=HoudiniEvent)

        mock_enabled2 = PropertyMock(return_value=True)
        type(mock_event2).enabled = mock_enabled2

        mock_events.return_value = {
            mock_event1.name: mock_event1,
            mock_event2.name: mock_event2,
        }

        manager = ht.events.manager.HoudiniEventManager()
        manager._event_states = {}

        manager._disable_events(names=[mock_event2.name])

        # Event 1's enabled property should not have been accessed.
        mock_enabled1.assert_not_called()

        # Event 2's should have been accessed to get the current value
        # and once to disable it.
        mock_enabled2.assert_has_calls([call(), call(False)])

        self.assertTrue(manager._event_states[mock_event2.name])
        self.assertEqual(len(manager._event_states), 1)
开发者ID:captainhammy,项目名称:Houdini-Toolbox,代码行数:33,代码来源:test_manager.py

示例4: test__restore_events

# 需要导入模块: from mock import PropertyMock [as 别名]
# 或者: from mock.PropertyMock import assert_has_calls [as 别名]
    def test__restore_events(self, mock_events):
        """Test restoring disabled events."""

        mock_event1 = MagicMock(spec=HoudiniEvent)
        mock_enabled1 = PropertyMock(return_value=False)
        type(mock_event1).enabled = mock_enabled1

        mock_event2 = MagicMock(spec=HoudiniEvent)
        mock_enabled2 = PropertyMock(return_value=False)
        type(mock_event2).enabled = mock_enabled2

        mock_events.return_value = {
            mock_event1.name: mock_event1,
            mock_event2.name: mock_event2,
        }

        mock_states = MagicMock(spec=dict)

        states = {mock_event1.name: False, mock_event2.name: True}
        mock_states.iteritems.return_value = states.iteritems()

        manager = ht.events.manager.HoudiniEventManager()
        manager._event_states = mock_states

        manager._restore_events()

        # Event 1's enable should have been set to False, 2's True
        mock_enabled1.assert_has_calls([call(False)])
        mock_enabled2.assert_has_calls([call(True)])

        mock_states.clear.assert_called_once()
开发者ID:captainhammy,项目名称:Houdini-Toolbox,代码行数:33,代码来源:test_manager.py

示例5: test_arm_and_takeoff

# 需要导入模块: from mock import PropertyMock [as 别名]
# 或者: from mock.PropertyMock import assert_has_calls [as 别名]
    def test_arm_and_takeoff(self):
        with patch("sys.stdout"):
            with patch.object(Mock_Vehicle, "check_arming", return_value=False):
                # The method must raise an exception when the vehicle is not 
                # ready to be armed.
                with self.assertRaises(RuntimeError):
                    self.mission.arm_and_takeoff()

            params = {
                "spec": Mock_Vehicle,
                "check_arming.return_value": True,
                "simple_takeoff.return_value": False
            }
            with patch.object(self.mission, "vehicle", **params) as vehicle_mock:
                armed_mock = PropertyMock(side_effect=[False, False, True])
                type(vehicle_mock).armed = armed_mock

                with patch.object(time, "sleep") as sleep_mock:
                    # A ground vehicle that does not take off should have the 
                    # appropriate calls.
                    self.mission.arm_and_takeoff()
                    armed_mock.assert_has_calls([call(True), call(), call()])
                    sleep_mock.assert_any_call(1)
                    self.assertEqual(vehicle_mock.speed, self.mission.speed)

            alt = self.settings.get("altitude")
            undershoot = self.settings.get("altitude_undershoot")
            loc_ground = LocationGlobalRelative(0.0, 0.0, 0.0)
            loc_under = LocationGlobalRelative(0.0, 0.0, undershoot * alt - 0.5)
            loc_takeoff = LocationGlobalRelative(0.0, 0.0, alt)
            locs = [loc_ground, loc_ground, loc_under, loc_under, loc_takeoff]

            global_relative_frame_mock = PropertyMock(side_effect=locs)
            location_mock = MagicMock()
            type(location_mock).global_relative_frame = global_relative_frame_mock
            params = {
                "spec": Mock_Vehicle,
                "check_arming.return_value": True,
                "simple_takeoff.return_value": True,
                "location": location_mock
            }
            with patch.object(self.mission, "vehicle", **params) as vehicle_mock:
                armed_mock = PropertyMock(side_effect=[False, True])
                type(vehicle_mock).armed = armed_mock

                with patch.object(time, "sleep") as sleep_mock:
                    # A flying vehicle that takes off has the correct calls.
                    self.mission.arm_and_takeoff()
                    self.assertEqual(global_relative_frame_mock.call_count, 5)
                    self.assertEqual(sleep_mock.call_count, 2)
开发者ID:lhelwerd,项目名称:mobile-radio-tomography,代码行数:52,代码来源:mission.py


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