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


Python mock.Mock方法代码示例

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


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

示例1: test_cookie_store_save

# 需要导入模块: from tests import mock [as 别名]
# 或者: from tests.mock import Mock [as 别名]
def test_cookie_store_save(self):
        session = Mock()
        session.http.cookies = [
            requests.cookies.create_cookie("test-name", "test-value", domain="test.se")
        ]

        Plugin.bind(session, 'tests.test_plugin')
        Plugin.cache = Mock()
        Plugin.cache.get_all.return_value = {}

        plugin = Plugin("http://test.se")
        plugin.save_cookies(default_expires=3600)

        Plugin.cache.set.assert_called_with("__cookie:test-name:test.se:80:/",
                                            self._create_cookie_dict("test-name", "test-value", None),
                                            3600) 
开发者ID:streamlink,项目名称:streamlink,代码行数:18,代码来源:test_plugin.py

示例2: test_cookie_store_save_expires

# 需要导入模块: from tests import mock [as 别名]
# 或者: from tests.mock import Mock [as 别名]
def test_cookie_store_save_expires(self):
        with freezegun.freeze_time(datetime.datetime(2018, 1, 1)):
            session = Mock()
            session.http.cookies = [
                requests.cookies.create_cookie("test-name", "test-value", domain="test.se", expires=time.time() + 3600,
                                               rest={'HttpOnly': None})
            ]

            Plugin.bind(session, 'tests.test_plugin')
            Plugin.cache = Mock()
            Plugin.cache.get_all.return_value = {}

            plugin = Plugin("http://test.se")
            plugin.save_cookies(default_expires=60)

            Plugin.cache.set.assert_called_with("__cookie:test-name:test.se:80:/",
                                                self._create_cookie_dict("test-name", "test-value", 1514768400),
                                                3600) 
开发者ID:streamlink,项目名称:streamlink,代码行数:20,代码来源:test_plugin.py

示例3: test_cookie_store_clear

# 需要导入模块: from tests import mock [as 别名]
# 或者: from tests.mock import Mock [as 别名]
def test_cookie_store_clear(self):
        session = Mock()
        session.http.cookies = requests.cookies.RequestsCookieJar()

        Plugin.bind(session, 'tests.test_plugin')
        Plugin.cache = Mock()
        Plugin.cache.get_all.return_value = {
            "__cookie:test-name:test.se:80:/": self._create_cookie_dict("test-name", "test-value", None),
            "__cookie:test-name2:test.se:80:/": self._create_cookie_dict("test-name2", "test-value2", None)
        }
        plugin = Plugin("http://test.se")

        # non-empty cookiejar
        self.assertTrue(len(session.http.cookies.get_dict()) > 0)

        plugin.clear_cookies()
        self.assertSequenceEqual(
            Plugin.cache.set.mock_calls,
            [call("__cookie:test-name:test.se:80:/", None, 0),
             call("__cookie:test-name2:test.se:80:/", None, 0)])
        self.assertSequenceEqual(session.http.cookies, []) 
开发者ID:streamlink,项目名称:streamlink,代码行数:23,代码来源:test_plugin.py

示例4: test_cookie_store_clear_filter

# 需要导入模块: from tests import mock [as 别名]
# 或者: from tests.mock import Mock [as 别名]
def test_cookie_store_clear_filter(self):
        session = Mock()
        session.http.cookies = requests.cookies.RequestsCookieJar()

        Plugin.bind(session, 'tests.test_plugin')
        Plugin.cache = Mock()
        Plugin.cache.get_all.return_value = {
            "__cookie:test-name:test.se:80:/": self._create_cookie_dict("test-name", "test-value", None),
            "__cookie:test-name2:test.se:80:/": self._create_cookie_dict("test-name2", "test-value2", None)
        }
        plugin = Plugin("http://test.se")

        # non-empty cookiejar
        self.assertTrue(len(session.http.cookies.get_dict()) > 0)

        plugin.clear_cookies(lambda c: c.name.endswith("2"))
        self.assertSequenceEqual(
            Plugin.cache.set.mock_calls,
            [call("__cookie:test-name2:test.se:80:/", None, 0)])
        self.assertSequenceEqual(
            list(map(self._cookie_to_dict, session.http.cookies)),
            [self._cookie_to_dict(requests.cookies.create_cookie("test-name", "test-value", domain="test.se"))]
        ) 
开发者ID:streamlink,项目名称:streamlink,代码行数:25,代码来源:test_plugin.py

示例5: test_bitrate_rounded

# 需要导入模块: from tests import mock [as 别名]
# 或者: from tests.mock import Mock [as 别名]
def test_bitrate_rounded(self):
        def mock_rep(bandwidth):
            node = Mock(
                tag="Representation",
                attrib={
                    "id": "test",
                    "bandwidth": bandwidth,
                    "mimeType": "video/mp4"
                }
            )
            node.findall.return_value = []
            return Representation(node)

        self.assertEqual(mock_rep(1.2 * 1000.0).bandwidth_rounded, 1.2)
        self.assertEqual(mock_rep(45.6 * 1000.0).bandwidth_rounded, 46.0)
        self.assertEqual(mock_rep(134.0 * 1000.0).bandwidth_rounded, 130.0)
        self.assertEqual(mock_rep(1324.0 * 1000.0).bandwidth_rounded, 1300.0) 
开发者ID:streamlink,项目名称:streamlink,代码行数:19,代码来源:test_dash_parser.py

示例6: test_parse_manifest_video_only

# 需要导入模块: from tests import mock [as 别名]
# 或者: from tests.mock import Mock [as 别名]
def test_parse_manifest_video_only(self, mpdClass):
        mpdClass.return_value = Mock(periods=[
            Mock(adaptationSets=[
                Mock(contentProtection=None,
                     representations=[
                         Mock(id=1, mimeType="video/mp4", height=720),
                         Mock(id=2, mimeType="video/mp4", height=1080)
                     ])
            ])
        ])

        streams = DASHStream.parse_manifest(self.session, self.test_url)
        mpdClass.assert_called_with(ANY, base_url="http://test.bar", url="http://test.bar/foo.mpd")

        self.assertSequenceEqual(
            sorted(list(streams.keys())),
            sorted(["720p", "1080p"])
        ) 
开发者ID:streamlink,项目名称:streamlink,代码行数:20,代码来源:test_dash.py

示例7: test_parse_manifest_audio_single

# 需要导入模块: from tests import mock [as 别名]
# 或者: from tests.mock import Mock [as 别名]
def test_parse_manifest_audio_single(self, mpdClass):
        mpdClass.return_value = Mock(periods=[
            Mock(adaptationSets=[
                Mock(contentProtection=None,
                     representations=[
                         Mock(id=1, mimeType="video/mp4", height=720),
                         Mock(id=2, mimeType="video/mp4", height=1080),
                         Mock(id=3, mimeType="audio/aac", bandwidth=128.0, lang='en')
                     ])
            ])
        ])

        streams = DASHStream.parse_manifest(self.session, self.test_url)
        mpdClass.assert_called_with(ANY, base_url="http://test.bar", url="http://test.bar/foo.mpd")

        self.assertSequenceEqual(
            sorted(list(streams.keys())),
            sorted(["720p", "1080p"])
        ) 
开发者ID:streamlink,项目名称:streamlink,代码行数:21,代码来源:test_dash.py

示例8: test_parse_manifest_audio_multi

# 需要导入模块: from tests import mock [as 别名]
# 或者: from tests.mock import Mock [as 别名]
def test_parse_manifest_audio_multi(self, mpdClass):
        mpdClass.return_value = Mock(periods=[
            Mock(adaptationSets=[
                Mock(contentProtection=None,
                     representations=[
                         Mock(id=1, mimeType="video/mp4", height=720),
                         Mock(id=2, mimeType="video/mp4", height=1080),
                         Mock(id=3, mimeType="audio/aac", bandwidth=128.0, lang='en'),
                         Mock(id=4, mimeType="audio/aac", bandwidth=256.0, lang='en')
                     ])
            ])
        ])

        streams = DASHStream.parse_manifest(self.session, self.test_url)
        mpdClass.assert_called_with(ANY, base_url="http://test.bar", url="http://test.bar/foo.mpd")

        self.assertSequenceEqual(
            sorted(list(streams.keys())),
            sorted(["720p+a128k", "1080p+a128k", "720p+a256k", "1080p+a256k"])
        ) 
开发者ID:streamlink,项目名称:streamlink,代码行数:22,代码来源:test_dash.py

示例9: test_parse_manifest_audio_multi_lang

# 需要导入模块: from tests import mock [as 别名]
# 或者: from tests.mock import Mock [as 别名]
def test_parse_manifest_audio_multi_lang(self, mpdClass):
        mpdClass.return_value = Mock(periods=[
            Mock(adaptationSets=[
                Mock(contentProtection=None,
                     representations=[
                         Mock(id=1, mimeType="video/mp4", height=720),
                         Mock(id=2, mimeType="video/mp4", height=1080),
                         Mock(id=3, mimeType="audio/aac", bandwidth=128.0, lang='en'),
                         Mock(id=4, mimeType="audio/aac", bandwidth=128.0, lang='es')
                     ])
            ])
        ])

        streams = DASHStream.parse_manifest(self.session, self.test_url)
        mpdClass.assert_called_with(ANY, base_url="http://test.bar", url="http://test.bar/foo.mpd")

        self.assertSequenceEqual(
            sorted(list(streams.keys())),
            sorted(["720p", "1080p"])
        )

        self.assertEqual(streams["720p"].audio_representation.lang, "en")
        self.assertEqual(streams["1080p"].audio_representation.lang, "en") 
开发者ID:streamlink,项目名称:streamlink,代码行数:25,代码来源:test_dash.py

示例10: test_parse_manifest_audio_multi_lang_alpha3

# 需要导入模块: from tests import mock [as 别名]
# 或者: from tests.mock import Mock [as 别名]
def test_parse_manifest_audio_multi_lang_alpha3(self, mpdClass):
        mpdClass.return_value = Mock(periods=[
            Mock(adaptationSets=[
                Mock(contentProtection=None,
                     representations=[
                         Mock(id=1, mimeType="video/mp4", height=720),
                         Mock(id=2, mimeType="video/mp4", height=1080),
                         Mock(id=3, mimeType="audio/aac", bandwidth=128.0, lang='eng'),
                         Mock(id=4, mimeType="audio/aac", bandwidth=128.0, lang='spa')
                     ])
            ])
        ])

        streams = DASHStream.parse_manifest(self.session, self.test_url)
        mpdClass.assert_called_with(ANY, base_url="http://test.bar", url="http://test.bar/foo.mpd")

        self.assertSequenceEqual(
            sorted(list(streams.keys())),
            sorted(["720p", "1080p"])
        )

        self.assertEqual(streams["720p"].audio_representation.lang, "eng")
        self.assertEqual(streams["1080p"].audio_representation.lang, "eng") 
开发者ID:streamlink,项目名称:streamlink,代码行数:25,代码来源:test_dash.py

示例11: test_parse_manifest_audio_invalid_lang

# 需要导入模块: from tests import mock [as 别名]
# 或者: from tests.mock import Mock [as 别名]
def test_parse_manifest_audio_invalid_lang(self, mpdClass):
        mpdClass.return_value = Mock(periods=[
            Mock(adaptationSets=[
                Mock(contentProtection=None,
                     representations=[
                         Mock(id=1, mimeType="video/mp4", height=720),
                         Mock(id=2, mimeType="video/mp4", height=1080),
                         Mock(id=3, mimeType="audio/aac", bandwidth=128.0, lang='en_no_voice'),
                     ])
            ])
        ])

        streams = DASHStream.parse_manifest(self.session, self.test_url)
        mpdClass.assert_called_with(ANY, base_url="http://test.bar", url="http://test.bar/foo.mpd")

        self.assertSequenceEqual(
            sorted(list(streams.keys())),
            sorted(["720p", "1080p"])
        )

        self.assertEqual(streams["720p"].audio_representation.lang, "en_no_voice")
        self.assertEqual(streams["1080p"].audio_representation.lang, "en_no_voice") 
开发者ID:streamlink,项目名称:streamlink,代码行数:24,代码来源:test_dash.py

示例12: test_set_defaults

# 需要导入模块: from tests import mock [as 别名]
# 或者: from tests.mock import Mock [as 别名]
def test_set_defaults(self):
        session = Mock()
        plugin = Mock()
        parser = Mock()

        session.plugins = {"mock": plugin}
        plugin.arguments = Arguments(
            Argument("test1", default="default1"),
            Argument("test2", default="default2"),
            Argument("test3")
        )

        setup_plugin_args(session, parser)

        self.assertEqual(plugin.options.get("test1"), "default1")
        self.assertEqual(plugin.options.get("test2"), "default2")
        self.assertEqual(plugin.options.get("test3"), None) 
开发者ID:streamlink,项目名称:streamlink,代码行数:19,代码来源:test_options.py

示例13: test_get_invalid_page

# 需要导入模块: from tests import mock [as 别名]
# 或者: from tests.mock import Mock [as 别名]
def test_get_invalid_page(self):
        page_resp = Mock()
        page_resp.text = u"""
            var validate = "foo";
            var resourceId = "1234";
        """
        self.session.http.get.return_value = page_resp

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

        streams = plugin.streams()

        self.assertEqual({}, streams)

        # test the url is used correctly

        self.session.http.get.assert_called_with(
            "http://tvplayer.com/watch/dave"
        ) 
开发者ID:streamlink,项目名称:streamlink,代码行数:22,代码来源:test_tvplayer.py

示例14: test_calls_on_failure_when_it_is_callable

# 需要导入模块: from tests import mock [as 别名]
# 或者: from tests.mock import Mock [as 别名]
def test_calls_on_failure_when_it_is_callable(self):
        self.conn.send_get_request.return_value = self.status_with({
            'cfgs': {
                'my_func': {
                    'generated': False,
                    'failed': True,
                    'error': 'error message'
                }
            }
        })
        d = Decompilation('ID', self.conn)
        on_failure = mock.Mock()

        d.wait_until_cfg_is_generated('my_func', on_failure=on_failure)

        on_failure.assert_called_once_with('error message') 
开发者ID:s3rvac,项目名称:retdec-python,代码行数:18,代码来源:decompilation_tests.py

示例15: test_display_decompilation_progress_displays_correct_value_failed_decompilation

# 需要导入模块: from tests import mock [as 别名]
# 或者: from tests.mock import Mock [as 别名]
def test_display_decompilation_progress_displays_correct_value_failed_decompilation(self):
        displayer = ProgressLogDisplayer()
        d = mock.Mock(spec_set=Decompilation)
        d.id = 'ID'
        d.has_finished.return_value = True
        d.has_failed.return_value = True
        d.get_phases.return_value = [
            DecompilationPhase(
                name='Waiting For Resources',
                part=None,
                description='Waiting for resources',
                completion=0,
                warnings=[]
            )
        ]

        displayer.display_decompilation_progress(d)

        self.assertEqual(
            self.stdout.getvalue(), """
ID
--

Waiting for resources (0%)...                      [FAIL]
""".lstrip()) 
开发者ID:s3rvac,项目名称:retdec-python,代码行数:27,代码来源:decompiler_tests.py


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