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


Python Mock.text方法代码示例

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


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

示例1: test_pick_up_surrounding_text

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import text [as 别名]
    def test_pick_up_surrounding_text(self):
        """
        process_key_event() should work with the surrounding text
        if possible.
        """
        surrounding_text = Mock()
        surrounding_text.text = "ao"
        cursor = 2
        anchor = 2
        key = "s"
        result = "áo"

        self.config["input-method-definition"] = {
            "s": "/"
        }
        self.config["input-method"] = "my-im"

        self.engine.get_surrounding_text = \
            Mock(return_value=(surrounding_text, cursor, anchor))

        self.backend.process_key_event(ord(key), 0)

        self.engine.get_surrounding_text.assert_called_once()

        last_action = self.backend.last_action()
        expected = {
            "type": "update-composition",
            "editing-string": result,
            "raw-string": surrounding_text.text + key
        }
        eq_(last_action, expected)
开发者ID:BoGoEngine,项目名称:ibus-bogo,代码行数:33,代码来源:test_surrounding_text_backend.py

示例2: test_get_streams

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import text [as 别名]
    def test_get_streams(self, hlsstream, mock_http, mock_get_stream_data):
        mock_get_stream_data.return_value = {
            "stream": "http://test.se/stream1"
        }

        page_resp = Mock()
        page_resp.text = u"""
                    <div class="video-js theoplayer-skin theo-seekbar-above-controls content-box vjs-fluid"
                 data-resource= "bbcone"
                 data-token = "1324567894561268987948596154656418448489159"
                                    data-content-type="live"
                    data-environment="live"
                    data-subscription="free"
                    data-channel-id="89">
                <div id="channel-info" class="channel-info">
                    <div class="row visible-xs visible-sm">
        """

        mock_http.get.return_value = page_resp
        hlsstream.parse_variant_playlist.return_value = {"test": HLSStream(self.session, "http://test.se/stream1")}

        TVPlayer.bind(self.session, "test.plugin.tvplayer")
        plugin = TVPlayer("http://tvplayer.com/watch/dave")

        streams = plugin.get_streams()

        self.assertTrue("test" in streams)

        # test the url is used correctly
        mock_http.get.assert_called_with("http://tvplayer.com/watch/dave")
        # test that the correct API call is made
        mock_get_stream_data.assert_called_with(resource="bbcone", channel_id="89", token="1324567894561268987948596154656418448489159")
        # test that the correct URL is used for the HLSStream
        hlsstream.parse_variant_playlist.assert_called_with(ANY, "http://test.se/stream1")
开发者ID:,项目名称:,代码行数:36,代码来源:

示例3: test_extract_number_bedrooms

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import text [as 别名]
 def test_extract_number_bedrooms(self):
     tag_mock = Mock()
     tag_mock.text = " / 3br - 730ft2 - "
     self.link_html.find = Mock(return_value=tag_mock)
     number_bedrooms = listing.extract_number_bedrooms(
         self.link_html, self.page_html, self.unhidden_page_html)
     self.assertEqual(number_bedrooms, 3)
开发者ID:ChrisPMohr,项目名称:ApartmentHunter,代码行数:9,代码来源:listing_test.py

示例4: test_avatar_url

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import text [as 别名]
 def test_avatar_url(self, post_mock, get_mock):
     # Esse é um teste unitário, não pode depender de rede ou da lib requests
     response = Mock()
     response.text = GET_MOCK_RESULT
     get_mock.return_value = response
     self.assertEqual('https://avatars.githubusercontent.com/u/3457115?v=3', github.buscar_avatar('renzon'))
     get_mock.assert_called_once_with('https://api.github.com/users/renzon')
开发者ID:renzon,项目名称:hu,代码行数:9,代码来源:github_tests.py

示例5: test_no_bedrooms

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import text [as 别名]
 def test_no_bedrooms(self):
     tag_mock = Mock()
     tag_mock.text = ''
     self.link_html.find = Mock(return_value=tag_mock)
     number_bedrooms = listing.extract_number_bedrooms(
         self.link_html, self.page_html, self.unhidden_page_html)
     self.assertIsNone(number_bedrooms)
开发者ID:ChrisPMohr,项目名称:ApartmentHunter,代码行数:9,代码来源:listing_test.py

示例6: test_get_last_record

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import text [as 别名]
    def test_get_last_record(self, requests_get_patched):
        mock_response = Mock(spec=Response)
        mock_response.status_code = 200
        mock_response.text = self.expected_current.xml
        requests_get_patched.return_value = mock_response

        last_record = NistBeacon.get_last_record()
        self.assertIsInstance(last_record, NistBeaconValue)
开发者ID:urda,项目名称:nistbeacon,代码行数:10,代码来源:test_nistbeacon.py

示例7: get_evaluation

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import text [as 别名]
 def get_evaluation(codename, outcome):
     evaluation = Mock()
     evaluation.codename = codename
     evaluation.outcome = outcome
     evaluation.execution_memory = 100
     evaluation.execution_time = 0.5
     evaluation.text = "Nothing to report"
     return evaluation
开发者ID:cms-dev,项目名称:cms,代码行数:10,代码来源:scoretypetestutils.py

示例8: test_get_record

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import text [as 别名]
    def test_get_record(self, requests_get_patched):
        mock_response = Mock(spec=Response)
        mock_response.status_code = 200
        mock_response.text = self.expected_current.xml
        requests_get_patched.return_value = mock_response

        record = NistBeacon.get_record(self.reference_timestamp)
        self.assertEqual(self.expected_current, record)
开发者ID:urda,项目名称:nistbeacon,代码行数:10,代码来源:test_nistbeacon.py

示例9: generate_mock_status

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import text [as 别名]
def generate_mock_status(id=None, text=None, created_at=None, user=None):
    status = Mock(spec=classes.Status)
    status.id = id
    status.text = text if text else "The text for mock status {0}".format(status.id)
    status.created_at = created_at if created_at else datetime.utcnow()
    if user is None:
        user = generate_mock_user()
    status.author = user
    status.in_reply_to_status_id = None
    return status
开发者ID:jga,项目名称:conversationalist,代码行数:12,代码来源:mocking.py

示例10: mock_requests_post

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import text [as 别名]
 def mock_requests_post(self, url, data=None, headers=None, verify=False):
     mock_response = Mock()
     mock_response.text = '<GetBillingAgreementDetailsResponse>\
         <GetBillingAgreementDetailsResult><BillingAgreementDetails>\
         <BillingAgreementStatus><State>Draft</State>\
         </BillingAgreementStatus></BillingAgreementDetails>\
         </GetBillingAgreementDetailsResult>\
         </GetBillingAgreementDetailsResponse>'
     mock_response.status_code = 200
     return mock_response
开发者ID:optionalg,项目名称:login-and-pay-with-amazon-sdk-python,代码行数:12,代码来源:test_pwa.py

示例11: mockreturn_login

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import text [as 别名]
 def mockreturn_login(*args, **kwargs):
     r = Mock()
     r.status_code = 200
     r.text = json.dumps({
         "logged_in_user": {
             "pk": self.USER_ID,
             "username": self.USERNAME,
             "full_name": self.FULLNAME
         },
         "status": "ok"
     })
     return r
开发者ID:fauzanakbar,项目名称:py_instagram_bot,代码行数:14,代码来源:test_bot.py

示例12: test_create_image

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import text [as 别名]
    def test_create_image(self, image_service):
        mock_template = Mock()
        mock_text = Mock()
        mock_image = Mock()
        mock_image.template = mock_template
        mock_image.text = mock_text

        image = image_service.create_image(mock_template, mock_text)

        assert image_service.image_store.create.called_once_with(mock_image)

        assert image.template is mock_image.template
        assert image.text is mock_image.text
开发者ID:jkloo,项目名称:memegen,代码行数:15,代码来源:test_services_image.py

示例13: test_get_json_no_credentials

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import text [as 别名]
    def test_get_json_no_credentials(self):
        response_mock = Mock()
        response_raise_for_status_mock = MagicMock()
        response_mock.raise_for_status = response_raise_for_status_mock
        response_mock.text = '[1,2,3]'

        requests_get_mock = MagicMock(return_value=response_mock)
        with patch('requests.get', requests_get_mock):
            result = bintray_resolver.get_json('http://site.com', None, None)
            self.assertEqual([1, 2, 3], result)

        requests_get_mock.assert_called_with('http://site.com')
        response_raise_for_status_mock.assert_called_with()
开发者ID:fsat,项目名称:conductr-cli,代码行数:15,代码来源:test_bintray_resolver.py

示例14: test_get_json

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import text [as 别名]
    def test_get_json(self):
        response_mock = Mock()
        response_raise_for_status_mock = MagicMock()
        response_mock.raise_for_status = response_raise_for_status_mock
        response_mock.text = '[1,2,3]'

        requests_get_mock = MagicMock(return_value=response_mock)
        with patch('requests.get', requests_get_mock):
            result = bintray_resolver.get_json('http://site.com', 'username', 'password')
            self.assertEqual([1, 2, 3], result)

        requests_get_mock.assert_called_with('http://site.com', auth=('username', 'password'))
        response_raise_for_status_mock.assert_called_with()
开发者ID:fsat,项目名称:conductr-cli,代码行数:15,代码来源:test_bintray_resolver.py

示例15: test_chain_check_init

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import text [as 别名]
    def test_chain_check_init(self, requests_get_patched):
        first_response = Mock(spec=Response)
        first_response.status_code = 200
        first_response.text = self.expected_first.xml

        previous_response = Mock(spec=Response)
        previous_response.status_code = 404

        next_response = Mock(spec=Response)
        next_response.status_code = 200
        next_response.text = self.expected_first_next.xml

        requests_get_patched.side_effect = [
            first_response,
            previous_response,
            next_response,
        ]

        self.assertTrue(
            NistBeacon.chain_check(
                self.init_timestamp,
            )
        )
开发者ID:urda,项目名称:nistbeacon,代码行数:25,代码来源:test_nistbeacon.py


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