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


Python mock.PropertyMock类代码示例

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


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

示例1: test_store_checks_fullness

 def test_store_checks_fullness(self):
   is_full_mock = PropertyMock()
   with patch.object(_MetricCache, 'is_full', is_full_mock):
     with patch('carbon.cache.events'):
       metric_cache = _MetricCache()
       metric_cache.store('foo', (123456, 1.0))
       is_full_mock.assert_called_once()
开发者ID:Akulatraxas,项目名称:carbon,代码行数:7,代码来源:test_cache.py

示例2: test_load_one_workspace

    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,代码行数:27,代码来源:data_loader_test.py

示例3: test_are_creds_valid_with_invalid_creds

    def test_are_creds_valid_with_invalid_creds(self):
        with patch.object(github.Github, 'get_user') as patched_get_user:
            mocked_login = PropertyMock()
            mocked_login.side_effect = github.BadCredentialsException(401, 'dummy data')
            type(patched_get_user.return_value).login = mocked_login

            self.assertFalse(self.backend.are_creds_valid())
开发者ID:wk8,项目名称:bitbucketmirrorer,代码行数:7,代码来源:test_github.py

示例4: _retrieve_content

 def _retrieve_content(self):
     about_mock = PropertyMock(name="about_mock")
     about_mock.version = "5.5.99"
     about_mock.build = "999"
     content_mock = MagicMock(name="content")
     content_mock.about = about_mock
     return content_mock
开发者ID:aasthabh,项目名称:photon-controller,代码行数:7,代码来源:test_hypervisor.py

示例5: test_follow_redirects

    def test_follow_redirects(self):

        finder = URLFinder()

        mock_response = MagicMock()
        mock_response_url = PropertyMock()
        type(mock_response).url = mock_response_url

        with patch("requests.get", MagicMock(return_value=mock_response)) as mock_get:
            # A request is sent to the URL. If there was a redirect return the
            # final URL.
            mock_response_url.return_value = "http://finalurl.com"
            self.assertEquals(
                finder.follow_redirects("http://redirects.to"),
                "http://finalurl.com",
            )
            self.assertEquals(mock_get.call_count, 1)
            self.assertEquals(mock_response_url.call_count, 1)

            # If there was no redirect return the original URL.
            self.assertEquals(
                finder.follow_redirects("http://finalurl.com"),
                "http://finalurl.com",
            )
            self.assertEquals(mock_get.call_count, 2)
            self.assertEquals(mock_response_url.call_count, 2)

        with patch("requests.get", MagicMock(side_effect=requests.RequestException)) as mock_get:
            # If request failed return None
            self.assertEquals(
                finder.follow_redirects("http://redirects.to"),
                None,
            )
            self.assertEquals(mock_get.call_count, 1)
开发者ID:andreyfedoseev,项目名称:djangourls.com,代码行数:34,代码来源:tests.py

示例6: test_propertymock_returnvalue

    def test_propertymock_returnvalue(self):
        m = MagicMock()
        p = PropertyMock()
        type(m).foo = p

        returned = m.foo
        p.assert_called_once_with()
        self.assertIsInstance(returned, MagicMock)
        self.assertNotIsInstance(returned, PropertyMock)
开发者ID:AaronJaramillo,项目名称:shopDPM,代码行数:9,代码来源:testhelpers.py

示例7: test_should_initialize_logging_with_current_configuration

    def test_should_initialize_logging_with_current_configuration(self, mock_config, mock_initialize_logging):
        config_properties = PropertyMock()
        config_properties.log_file = '/foo/bar/baz.log'
        mock_config.return_value = config_properties

        livestatus_service.initialize('/foo/bar/config.cfg')

        self.assertEqual(
            mock_initialize_logging.call_args, call(config_properties.log_file))
开发者ID:ImmobilienScout24,项目名称:livestatus_service,代码行数:9,代码来源:livestatus_service_tests.py

示例8: test

 def test(self, get_config):
     mock_configuration = PropertyMock()
     mock_configuration.livestatus_socket = './livestatus_socket'
     get_config.return_value = mock_configuration
     with LiveServer() as liveserver:
         with LiveSocket('./livestatus_socket', '{}') as livesocket:
             result = urlopen('{0}cmd?q=DISABLE_HOST_NOTIFICATIONS;devica01'.format(liveserver.url))
             self.assertEqual(result.read(), b'OK\n')
             written_to_socket = livesocket.incoming.get()
             self.assertTrue('DISABLE_HOST_NOTIFICATIONS;devica01' in written_to_socket)
开发者ID:ImmobilienScout24,项目名称:livestatus_service,代码行数:10,代码来源:should_respond_ok_and_write_to_livestatus_socket_when_command_is_posted_tests.py

示例9: test_is_supported

    def test_is_supported(self):

        input_mock = PropertyMock(return_value="coffee")

        class IsSupportedTestCompiler(BaseCompiler):
            input_extension = input_mock

        compiler = IsSupportedTestCompiler()
        self.assertEqual(compiler.is_supported("dummy.coffee"), True)
        self.assertEqual(compiler.is_supported("dummy.js"), False)
        input_mock.assert_called_with()
开发者ID:Anber,项目名称:django-static-precompiler,代码行数:11,代码来源:test_base_compiler.py

示例10: test_dont_access_source

def test_dont_access_source():
    """
    Touching the source may trigger an unneeded query.
    See <https://github.com/matthewwithanm/django-imagekit/issues/295>

    """
    pmock = PropertyMock()
    pmock.__get__ = Mock()
    with patch.object(Photo, 'original_image', pmock):
        photo = Photo()  # noqa
        assert_false(pmock.__get__.called)
开发者ID:FundedByMe,项目名称:django-imagekit,代码行数:11,代码来源:test_no_extra_queries.py

示例11: test_compute_random_record_name

    def test_compute_random_record_name(self):
        someuuid = "someuuid"
        domain = {"name": "domain"}
        uuid1_m = self.create_patch("uuid.uuid1")
        uuid_m = Mock()
        hex_m = PropertyMock()
        type(uuid_m).hex = hex_m

        uuid1_m.return_value = uuid_m
        hex_m.return_value = someuuid

        self.assertEqual(compute_random_record_name(domain), someuuid)
开发者ID:mudrykaa,项目名称:designate-dyn-dns-backend,代码行数:12,代码来源:test_dynamic_dns_backend.py

示例12: test_commands_waypoints

    def test_commands_waypoints(self, commands_mock):
        next_mock = PropertyMock(return_value=1)
        type(commands_mock.return_value).next = next_mock
        self.assertEqual(self.vehicle.get_next_waypoint(), 1)

        self.vehicle.set_next_waypoint()
        next_mock.assert_any_call(2)
        self.vehicle.set_next_waypoint(waypoint=0)
        next_mock.assert_any_call(0)

        commands_mock.return_value.configure_mock(count=2)
        self.assertEqual(self.vehicle.count_waypoints(), 2)
开发者ID:timvandermeij,项目名称:mobile-radio-tomography,代码行数:12,代码来源:vehicle_mavlink_vehicle.py

示例13: test

 def test(self, get_config):
     mock_configuration = PropertyMock()
     mock_configuration.livestatus_socket = './livestatus_socket'
     get_config.return_value = mock_configuration
     with LiveServer() as liveserver:
         socket_response = '[["host_name","notifications_enabled"],["devica01", 1], ["tuvdbs05",1], ["tuvdbs06",1]]'
         with LiveSocket('./livestatus_socket', socket_response) as livesocket:
             api_call_result = urlopen('{0}query?q=GET%20hosts&key=host_name'.format(liveserver.url))
             actual_api_response = json.loads(api_call_result.read().decode('utf-8'))
             self.assertEqual(expected_api_call_response, actual_api_response)
             written_to_socket = livesocket.incoming.get()
             self.assertTrue('GET hosts' in written_to_socket and 'OutputFormat: json' in written_to_socket)
开发者ID:ImmobilienScout24,项目名称:livestatus_service,代码行数:12,代码来源:should_parse_socket_output_when_query_with_key_is_executed_tests.py

示例14: test_arm_and_takeoff

    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,代码行数:50,代码来源:mission.py

示例15: test_change_xy_log

    def test_change_xy_log(self):
        view_x_log_mock = PropertyMock()
        view_y_log_mock = PropertyMock()
        model_x_log_mock = PropertyMock(return_value=True)
        model_y_log_mock = PropertyMock(return_value=False)
        model_x_range_mock = PropertyMock(return_value=(1, 2))
        model_y_range_mock = PropertyMock(return_value=(3, 4))
        type(self.view).x_log = view_x_log_mock
        type(self.view).y_log = view_y_log_mock
        type(self.model).x_log = model_x_log_mock
        type(self.model).y_log = model_y_log_mock
        type(self.model).x_range = model_x_range_mock
        type(self.model).y_range = model_y_range_mock

        # model -> view
        self.presenter = CutPlotOptionsPresenter(self.view, self.model)
        view_x_log_mock.assert_called_once_with(True)
        view_y_log_mock.assert_called_once_with(False)

        # view -> model
        view_x_log_mock.return_value = False
        view_y_log_mock.return_value = True
        self.presenter._xy_config_modified('x_log')
        self.presenter._xy_config_modified('y_log')
        self.presenter.get_new_config()
        self.model.change_axis_scale.assert_called_once_with({'x_range': (1, 2), 'y_range': (3, 4), 'modified': True,
                                                              'x_log': False,    'y_log': True})
开发者ID:mantidproject,项目名称:mslice,代码行数:27,代码来源:plot_options_presenter_test.py


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