• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python mock.PropertyMock类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: mockery

 def mockery(self, property_name, property_return_value=None):
     """
     Return property of *property_name* on self.table with return value of
     *property_return_value*.
     """
     # mock <a:tbl> element of Table so we can mock its properties
     tbl = MagicMock()
     self.table._tbl_elm = tbl
     # create a suitable mock for the property
     property_ = PropertyMock()
     if property_return_value:
         property_.return_value = property_return_value
     # and attach it the the <a:tbl> element object (class actually)
     setattr(type(tbl), property_name, property_)
     return property_
开发者ID:castaway,项目名称:python-pptx,代码行数:15,代码来源:test_table.py


示例17: 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".format(liveserver.url))
             actual_result = json.loads(api_call_result.read().decode("utf-8"))
             expected_result = json.loads(expected_api_call_response)
             diff = [element for element in actual_result if element not in expected_result]
             diff.extend([element for element in expected_result if element not in actual_result])
             self.assertEqual(diff, [], "Found difference between expected and actual result : %s" % diff)
             written_to_socket = livesocket.incoming.get()
             self.assertTrue("GET hosts" in written_to_socket and "OutputFormat: json" in written_to_socket)
开发者ID:jfrome,项目名称:livestatus_service,代码行数:15,代码来源:should_parse_socket_output_when_query_is_executed_tests.py


示例18: setUp

    def setUp(self):
        super(TestGeometry, self).setUp()

        # Geometry object to use in the tests.
        self.geometry = Geometry()

        # Delta values for approximate equality checks.
        # The default values handle float inaccuracies that may be caused by 
        # conversions in the geometry class.
        self.dist_delta = sys.float_info.epsilon * 10
        self.coord_delta = self.dist_delta
        self.angle_delta = sys.float_info.epsilon * 10

        # Create a mock version of a `Locations` object. The location frames 
        # have property mocks that can be configured to return a specific 
        # location value.
        self.locations_mock = Mock(spec_set=Locations)
        self.relative_mock = PropertyMock()
        self.global_mock = PropertyMock()
        self.local_mock = PropertyMock()

        type(self.locations_mock).global_relative_frame = self.relative_mock
        type(self.locations_mock).global_frame = self.global_mock
        type(self.locations_mock).local_frame = self.local_mock

        # Location objects that can be used by type checking tests, where the 
        # coordinate values do not matter at all.
        self.local_location = LocationLocal(1.0, 2.0, 3.0)
        self.global_location = LocationGlobal(4.0, 5.0, 6.0)
        self.relative_location = LocationGlobalRelative(7.0, 8.0, 9.0)
开发者ID:lhelwerd,项目名称:mobile-radio-tomography,代码行数:30,代码来源:geometry.py


示例19: 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:

                url = '{0}cmd'.format(liveserver.url)
                parameters = {'q': 'DISABLE_HOST_NOTIFICATIONS;devica01',
                              }
                data = urlencode(parameters)
                binary_data = data.encode('utf-8')
                request = Request(url, binary_data)
                response = urlopen(request)
                self.assertEquals(response.read(), b'OK\n')
                written_to_socket = livesocket.incoming.get()
                self.assertTrue('DISABLE_HOST_NOTIFICATIONS;devica01' in written_to_socket)
开发者ID:tklein,项目名称:livestatus_service,代码行数:17,代码来源:should_respond_ok_and_write_to_livestatus_socket_when_command_is_executed_tests.py


示例20: test_extract

    def test_extract(self):
        untiny = Untiny()

        mock_response = MagicMock()
        mock_response_text = PropertyMock()
        type(mock_response).text = mock_response_text

        untiny.is_tiny = MagicMock()

        with patch("requests.get", MagicMock(return_value=mock_response)) as mock_get:
            # If the URL is tiny send a request to untiny.me to extract
            # full URL
            untiny.is_tiny.return_value = True
            mock_response_text.return_value = "http://foo.com"
            self.assertEquals(
                untiny.extract("http://2pl.us/234"),
                "http://foo.com",
            )
            self.assertEquals(mock_get.call_count, 1)
            self.assertEquals(mock_response_text.call_count, 1)

            # Check with another URL
            mock_response_text.return_value = "http://bar.com"
            self.assertEquals(
                untiny.extract("http://1u.ro/123"),
                "http://bar.com",
            )
            self.assertEquals(mock_get.call_count, 2)
            self.assertEquals(mock_response_text.call_count, 2)

            # If the URL is not tiny return it unchanged.
            untiny.is_tiny.return_value = False
            self.assertEquals(
                untiny.extract("http://example.com"),
                "http://example.com",
            )
            self.assertEquals(mock_get.call_count, 2)

        with patch("requests.get", MagicMock(side_effect=requests.RequestException)) as mock_get:
            # If a request to untiny.me fails return the original URL.
            untiny.is_tiny.return_value = True
            self.assertEquals(
                untiny.extract("http://1u.ro/123"),
                "http://1u.ro/123",
            )
            self.assertEquals(mock_get.call_count, 1)
开发者ID:andreyfedoseev,项目名称:djangourls.com,代码行数:46,代码来源:tests.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python call.add_chain函数代码示例发布时间:2022-05-27
下一篇:
Python mock.NonCallableMock类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap