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


Python PropertyMock.return_value方法代码示例

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


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

示例1: test_change_axis

# 需要导入模块: from mock import PropertyMock [as 别名]
# 或者: from mock.PropertyMock import return_value [as 别名]
    def test_change_axis(self):

        view_x_label_mock = PropertyMock()
        view_y_label_mock = PropertyMock()
        model_x_label_mock = PropertyMock(return_value='x0')
        model_y_label_mock = PropertyMock(return_value='y0')

        type(self.view).x_label = view_x_label_mock
        type(self.view).y_label = view_y_label_mock
        type(self.model).x_label = model_x_label_mock
        type(self.model).y_label = model_y_label_mock

        # labels passed model -> view
        self.presenter = SlicePlotOptionsPresenter(self.view, self.model)
        model_x_label_mock.assert_called_once_with()
        model_y_label_mock.assert_called_once_with()
        view_x_label_mock.assert_called_once_with('x0')
        view_y_label_mock.assert_called_once_with('y0')

        # labels passed view -> model
        model_x_label_mock.reset_mock()
        model_y_label_mock.reset_mock()
        view_x_label_mock.reset_mock()
        view_y_label_mock.reset_mock()

        view_x_label_mock.return_value = 'x1'
        view_y_label_mock.return_value = 'y1'
        self.presenter._value_modified('x_label')
        self.presenter._value_modified('y_label')
        self.presenter.get_new_config()

        view_x_label_mock.assert_called_once_with()
        view_y_label_mock.assert_called_once_with()
        model_x_label_mock.assert_called_once_with('x1')
        model_y_label_mock.assert_called_once_with('y1')
开发者ID:mantidproject,项目名称:mslice,代码行数:37,代码来源:plot_options_presenter_test.py

示例2: test_change_grid

# 需要导入模块: from mock import PropertyMock [as 别名]
# 或者: from mock.PropertyMock import return_value [as 别名]
    def test_change_grid(self):

        view_x_grid_mock = PropertyMock()
        view_y_grid_mock = PropertyMock()
        model_x_grid_mock = PropertyMock(return_value=False)
        model_y_grid_mock = PropertyMock(return_value=False)

        type(self.view).x_grid = view_x_grid_mock
        type(self.view).y_grid = view_y_grid_mock
        type(self.model).x_grid = model_x_grid_mock
        type(self.model).y_grid = model_y_grid_mock

        # labels passed model -> view
        self.presenter = SlicePlotOptionsPresenter(self.view, self.model)
        model_x_grid_mock.assert_called_once_with()
        model_y_grid_mock.assert_called_once_with()
        view_x_grid_mock.assert_called_once_with(False)
        view_y_grid_mock.assert_called_once_with(False)

        # labels passed view -> model
        model_x_grid_mock.reset_mock()
        model_y_grid_mock.reset_mock()
        view_x_grid_mock.reset_mock()
        view_y_grid_mock.reset_mock()

        view_x_grid_mock.return_value = True
        view_y_grid_mock.return_value = True
        self.presenter._value_modified('x_grid')
        self.presenter._value_modified('y_grid')
        self.presenter.get_new_config()

        view_x_grid_mock.assert_called_once_with()
        view_y_grid_mock.assert_called_once_with()
        model_x_grid_mock.assert_called_once_with(True)
        model_y_grid_mock.assert_called_once_with(True)
开发者ID:mantidproject,项目名称:mslice,代码行数:37,代码来源:plot_options_presenter_test.py

示例3: test_change_colorbar_config

# 需要导入模块: from mock import PropertyMock [as 别名]
# 或者: from mock.PropertyMock import return_value [as 别名]
    def test_change_colorbar_config(self):
        view_colorbar_range_mock = PropertyMock()
        view_colorbar_log_mock = PropertyMock()
        type(self.view).colorbar_range = view_colorbar_range_mock
        type(self.view).colorbar_log = view_colorbar_log_mock

        model_colorbar_range_mock = PropertyMock(return_value=(1, 5))
        model_colorbar_log_mock = PropertyMock(return_value=False)
        type(self.model).colorbar_range = model_colorbar_range_mock
        type(self.model).colorbar_log = model_colorbar_log_mock

        # passed model -> view
        self.presenter = SlicePlotOptionsPresenter(self.view, self.model)

        model_colorbar_range_mock.assert_called_with()
        model_colorbar_log_mock.assert_called_with()
        view_colorbar_range_mock.assert_called_once_with((1, 5))
        view_colorbar_log_mock.assert_called_once_with(False)

        # passed view -> model
        view_colorbar_range_mock.return_value = (2, 10)
        view_colorbar_log_mock.return_value = True
        self.presenter._set_c_range()
        self.presenter._set_colorbar_log()
        self.presenter.get_new_config()
        self.model.change_axis_scale.assert_called_once_with((2, 10), True)
开发者ID:mantidproject,项目名称:mslice,代码行数:28,代码来源:plot_options_presenter_test.py

示例4: test_change_xy_log

# 需要导入模块: from mock import PropertyMock [as 别名]
# 或者: from mock.PropertyMock import return_value [as 别名]
    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,代码行数:29,代码来源:plot_options_presenter_test.py

示例5: test_load_one_workspace

# 需要导入模块: from mock import PropertyMock [as 别名]
# 或者: from mock.PropertyMock import return_value [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

示例6: test_follow_redirects

# 需要导入模块: from mock import PropertyMock [as 别名]
# 或者: from mock.PropertyMock import return_value [as 别名]
    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,代码行数:36,代码来源:tests.py

示例7: test_change_xrange

# 需要导入模块: from mock import PropertyMock [as 别名]
# 或者: from mock.PropertyMock import return_value [as 别名]
    def test_change_xrange(self):

        view_x_range_mock = PropertyMock()
        type(self.view).x_range = view_x_range_mock

        model_x_range_mock = PropertyMock(return_value=(1, 5))
        type(self.model).x_range = model_x_range_mock

        # passed model -> view
        self.presenter1 = SlicePlotOptionsPresenter(self.view, self.model)

        model_x_range_mock.assert_called_with()
        view_x_range_mock.assert_called_once_with((1, 5))

        # passed view -> model through slice presenter
        model_x_range_mock.reset_mock()
        view_x_range_mock.return_value = (2, 10)
        self.presenter1._xy_config_modified('x_range')
        self.presenter1.get_new_config()
        model_x_range_mock.assert_called_once_with((2, 10))

        # passed view -> model through cut presenter
        self.presenter2 = CutPlotOptionsPresenter(self.view, self.model)
        self.presenter2._xy_config_modified('x_range')
        self.presenter2.get_new_config()
        self.model.change_axis_scale.assert_called_once()
开发者ID:mantidproject,项目名称:mslice,代码行数:28,代码来源:plot_options_presenter_test.py

示例8: test_extract

# 需要导入模块: from mock import PropertyMock [as 别名]
# 或者: from mock.PropertyMock import return_value [as 别名]
    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,代码行数:48,代码来源:tests.py

示例9: test_compute_random_record_name

# 需要导入模块: from mock import PropertyMock [as 别名]
# 或者: from mock.PropertyMock import return_value [as 别名]
    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,代码行数:14,代码来源:test_dynamic_dns_backend.py

示例10: mockery

# 需要导入模块: from mock import PropertyMock [as 别名]
# 或者: from mock.PropertyMock import return_value [as 别名]
 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,代码行数:17,代码来源:test_table.py

示例11: mocked_response

# 需要导入模块: from mock import PropertyMock [as 别名]
# 或者: from mock.PropertyMock import return_value [as 别名]
def mocked_response(status_code=200):
    """
    Return mocked response instance

        >>> mocked_response(status_code=404).code == 404
        True
        >>> mocked_response(status_code=404).code == 200
        False
        >>> mocked_response(status_code=404).read() == 'mocked body'
        True
    """
    code = PropertyMock()
    code.return_value = status_code

    response = MagicMock()
    response.read.return_value = 'mocked body'
    type(response).code = code

    return response
开发者ID:raimon49,项目名称:pypro2-unittest-study,代码行数:21,代码来源:test_bankaccount.py

示例12: mock_connection

# 需要导入模块: from mock import PropertyMock [as 别名]
# 或者: from mock.PropertyMock import return_value [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

示例13: test_change_title

# 需要导入模块: from mock import PropertyMock [as 别名]
# 或者: from mock.PropertyMock import return_value [as 别名]
    def test_change_title(self):

        mock_view_title = PropertyMock()
        type(self.view).title = mock_view_title

        mock_model_title = PropertyMock(return_value='Title 0')
        type(self.model).title = mock_model_title

        # title passed model -> view
        self.presenter = CutPlotOptionsPresenter(self.view, self.model)

        mock_model_title.assert_called_once_with()
        mock_view_title.assert_called_once_with('Title 0')

        # title passed view -> model
        mock_view_title.reset_mock()
        mock_model_title.reset_mock()
        mock_view_title.return_value = 'Title 1'
        self.presenter._value_modified('title')
        self.presenter.get_new_config()

        mock_view_title.assert_called_once_with()
        mock_model_title.assert_called_once_with('Title 1')
开发者ID:mantidproject,项目名称:mslice,代码行数:25,代码来源:plot_options_presenter_test.py

示例14: mock_connection

# 需要导入模块: from mock import PropertyMock [as 别名]
# 或者: from mock.PropertyMock import return_value [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.return_value方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。