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


Python Mocker.throw方法代码示例

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


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

示例1: test_find_match_not_matched

# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import throw [as 别名]
    def test_find_match_not_matched(self):
        key1 = "chr1:154000-230000"
        mocker = Mocker()

        junction = mocker.mock()
        junction.coverage
        mocker.result(40)

        container1 = mocker.mock()
        container2 = mocker.mock()

        container1.keys()
        mocker.result([key1])

        container1[key1]
        mocker.result(junction)

        container2[key1]
        mocker.throw(KeyError)
        mocker.count(1)

        mocker.replay()

        self.common, self.diff = jc.findMatch(container1, container2)
        self.assertEqual(self.common.keys(), [])
        self.assertEqual(self.diff.keys(), [key1])

        mocker.restore()
        mocker.verify()
开发者ID:bjventers,项目名称:python-codes-for-RNAseq,代码行数:31,代码来源:test_junction_comp.py

示例2: test

# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import throw [as 别名]
 def test(serial):
     m = Mocker()
     proj = Project.create()
     log = m.replace("editxt.project.log", passthrough=False)
     nsdat = m.replace(NSData, passthrough=False)
     nspls = m.replace(NSPropertyListSerialization, passthrough=False)
     create_document_view_with_state = m.method(Project.create_document_view_with_state)
     create_document_view = m.method(Project.create_document_view)
     proj._documents = docs = m.mock(KVOList)
     if "path" in serial:
         data = nsdat.dataWithContentsOfFile_(serial["path"]) >> m.mock()
         serial_, format, error = nspls. \
             propertyListFromData_mutabilityOption_format_errorDescription_( \
                 data, NSPropertyListImmutable, None, None) >> ({}, m.mock(), None)
     else:
         serial_ = serial
     docs_ = serial_.get("documents", [])
     for item in docs_:
         create_document_view_with_state(item)
         if item == "doc_not_found":
             m.throw(Exception("document not found"))
             log.warn("cannot open document: %r" % item)
         #proj._is_dirty = True
     bool(docs); m.result(bool(docs_))
     if not docs_:
         create_document_view()
         #proj._is_dirty = True
     with m:
         proj.deserialize(serial)
         if "path" in serial:
             eq_(proj.path, serial["path"])
             assert "name" not in serial
         else:
             eq_(proj.name, serial.get("name", const.UNTITLED_PROJECT_NAME))
             eq_(proj.expanded, serial.get("expanded", True))
开发者ID:youngrok,项目名称:editxt,代码行数:37,代码来源:test_project.py

示例3: test_order_not_filled

# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import throw [as 别名]
def test_order_not_filled():
    order = Order("item #1", 1)

    mocker = Mocker()
    inventory = mocker.mock()
    inventory.remove("item #1", 1)
    mocker.throw(QuantityError)

    mocker.replay()
    order.fill(inventory)

    mocker.verify()
    assert not order.filled
开发者ID:osantana,项目名称:curso-tdd,代码行数:15,代码来源:test_order.py

示例4: test_selenium_driver_raises_on_start_test_when_selenium_cant_start

# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import throw [as 别名]
def test_selenium_driver_raises_on_start_test_when_selenium_cant_start():
    
    mocker = Mocker()
    
    context = Context(Settings())
    selenium_mock = mocker.mock()
    selenium_mock.start()
    mocker.throw(DriverError("invalid usage"))

    with mocker:
        driver = SeleniumDriver(context, selenium=selenium_mock)
    
        assert_raises(DriverError, driver.start_test, url="http://localhost", \
                      exc_pattern=re.compile(r"Error when starting selenium. Is it running ?"))
开发者ID:Desperado,项目名称:pyccuracy,代码行数:16,代码来源:test_selenium_browser_driver.py

示例5: test_wait_for_disappear_works_even_when_is_visible_raises

# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import throw [as 别名]
def test_wait_for_disappear_works_even_when_is_visible_raises():
    
    mocker = Mocker()
    
    context = Context(Settings())
    selenium_mock = mocker.mock()
    selenium_mock.is_element_present('some element')
    mocker.count(min=1, max=None)
    mocker.result(True)
    selenium_mock.is_visible('some element')
    mocker.throw(Exception("ERROR: Element some element not found"))

    with mocker:
        driver = SeleniumDriver(context, selenium=selenium_mock)
        driver.wait_for_element_to_disappear("some element", 1)
开发者ID:Desperado,项目名称:pyccuracy,代码行数:17,代码来源:test_selenium_browser_driver.py

示例6: test

# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import throw [as 别名]
 def test(c):
     m = Mocker()
     lg = m.replace("editxt.textcommand.log")
     mi = m.mock(ak.NSMenuItem)
     tv = m.mock(ak.NSTextView)
     tc = m.mock()
     tcc = CommandManager("<history>")
     cmds = m.replace(tcc, "commands")
     cmds.get(mi.tag() >> 42) >> (tc if c.has_command else None)
     if c.has_command:
         tc(tv, None)
         if c.error:
             m.throw(Exception)
             lg.exception("%s.execute failed", ANY)
     with m:
         tcc.do_menu_command(tv, mi)
开发者ID:editxt,项目名称:editxt,代码行数:18,代码来源:test_textcommand.py

示例7: test

# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import throw [as 别名]
 def test(c):
     m = Mocker()
     lg = m.replace("editxt.textcommand.log")
     mi = m.mock(ak.NSMenuItem)
     tv = m.mock(ak.NSTextView)
     tc = m.mock()
     tcc = TextCommandController("<history>")
     cmds = m.replace(tcc, 'commands')
     cmds.get(mi.tag() >> 42) >> (tc if c.has_command else None)
     if c.has_command:
         tc(tv, mi, None)
         if c.error:
             m.throw(Exception)
             lg.error("%s.execute failed", ANY, exc_info=True)
     with m:
         tcc.do_textview_command(tv, mi)
开发者ID:khairy,项目名称:editxt,代码行数:18,代码来源:test_textcommand.py

示例8: test

# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import throw [as 别名]
 def test(c):
     m = Mocker()
     lg = m.replace("editxt.textcommand.log", passthrough=False)
     mi = m.mock(NSMenuItem)
     tv = m.mock(NSTextView)
     tc = m.mock(TextCommand)
     tcc = TextCommandController(None)
     cmds = m.replace(tcc.commands)
     cmd = cmds.get(mi.tag() >> 42) >> (tc if c.has_command else None)
     if c.has_command:
         cmd.execute(tv, mi)
         if c.error:
             m.throw(Exception)
             lg.error("%s.execute failed", ANY, exc_info=True)
     with m:
         tcc.do_textview_command(tv, mi)
开发者ID:youngrok,项目名称:editxt,代码行数:18,代码来源:test_textcommand.py

示例9: test_shared_exon

# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import throw [as 别名]
    def test_shared_exon(self):
        mocker = Mocker()

        self.model = mocker.mock()
        self.model.blockStarts
        mocker.result([100, 400, 700])
        mocker.count(2, None)

        self.model.blockSizes
        mocker.result([100, 100, 100])
        mocker.count(1, None)

        self.model.chrom
        mocker.result("chr1")
        mocker.count(2, None)

        self.model.start
        mocker.result(0)
        mocker.count(1, None)

        self.junctions1 = mocker.mock()
        self.junctions2 = mocker.mock()
        self.junc1 = [400]
        self.junc2 = [700]

        juncKey = "chr1:200"
        self.junctions1[juncKey]
        mocker.result(self.junc1)

        self.junctions2[juncKey]
        mocker.result(self.junc2)

        juncKey = "chr1:500"
        self.junctions1[juncKey]
        mocker.throw(KeyError)

        juncKey = "chr1:800"
        self.junctions1[juncKey]
        mocker.throw(KeyError)

        mocker.replay()
        self.sharedExons = {}
        jc.scanJunctions(self.model, self.junctions1, self.junctions2, self.sharedExons)

        for j in self.sharedExons:
            self.assertEqual(self.sharedExons[j], [400])
            self.assertEqual(j, "chr1:200")
开发者ID:bjventers,项目名称:python-codes-for-RNAseq,代码行数:49,代码来源:test_junction_comp.py

示例10: test_is_element_visible_with_element_removal_while_executing

# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import throw [as 别名]
    def test_is_element_visible_with_element_removal_while_executing(self):
        from selenium.common.exceptions import StaleElementReferenceException

        mocker = Mocker()

        context = Context(Settings())
        browser_mock = mocker.mock()

        xpath = '//div'

        browser_mock.find_by_xpath(xpath)

        element_mock = mocker.mock()
        mocker.result(element_mock)
        element_mock.visible
        mocker.throw(StaleElementReferenceException)

        with mocker:
            driver = SplinterDriver(context, browser=browser_mock)
            is_visible = driver.is_element_visible(xpath)
            self.assertEqual(is_visible, False)
开发者ID:jusbrasil,项目名称:pyccuracy,代码行数:23,代码来源:test_splinter_driver.py

示例11: test_find_match_match_not_match

# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import throw [as 别名]
    def test_find_match_match_not_match(self):
        key1 = ["chr1:154000-230000", "chr1:155000-230000"]
        key2 = ["chr1:154000-230000"]
        mocker = Mocker()
        junction = mocker.mock()
        junction.coverage
        mocker.result(40)
        mocker.count(1, None)

        container1 = mocker.mock()
        container2 = mocker.mock()

        container1.keys()
        mocker.result(key1)

        container1[key1[0]]
        mocker.result(junction)
        mocker.count(1, None)

        container1[key1[1]]
        mocker.result(junction)
        mocker.count(1, None)

        container2[key1[0]]
        mocker.result(junction)
        mocker.count(1, None)

        container2[key1[1]]
        mocker.throw(KeyError)
        mocker.count(1)

        mocker.replay()
        self.common, self.diff = jc.findMatch(container1, container2)
        self.assertEqual(self.common.keys(), [key1[0]])
        self.assertEqual(self.diff.keys(), [key1[1]])

        mocker.restore()
        mocker.verify()
开发者ID:bjventers,项目名称:python-codes-for-RNAseq,代码行数:40,代码来源:test_junction_comp.py

示例12: Mocker

# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import throw [as 别名]
 def test_create_database_terminates_the_instance_if_it_fails_to_create_the_database_and_save_instance_with_error_state(self):
     exc_msg = u"I've failed to create your database, sorry! :("
     mocker = Mocker()
     c_database = mocker.replace("mysqlapi.api.models.DatabaseManager.create_database")
     c_database()
     mocker.throw(Exception(exc_msg))
     mocker.replay()
     instance = Instance(
         ec2_id="i-00009",
         name="home",
         host="unknown.host",
         state="running",
     )
     ec2_client = mocks.FakeEC2Client()
     try:
         t = create_database(instance, ec2_client)
         t.join()
         self.assertIn("terminate instance home", ec2_client.actions)
         self.assertIsNotNone(instance.pk)
         self.assertEqual("error", instance.state)
         self.assertEqual(exc_msg, instance.reason)
     finally:
         instance.delete()
     mocker.verify()
开发者ID:agnhesi,项目名称:mysqlapi,代码行数:26,代码来源:test_create_database.py

示例13: OAuthTwitterTest

# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import throw [as 别名]

#.........这里部分代码省略.........
                                       {'oauth_token': TOKEN.key})
            self.assertEqual(response['Location'],
                             'http://testserver/twitter/associate/'
                             '?user=twitter&error=user_already_linked')

    def test_association_associated_remove(self):
        Api = self.mocker.replace(TwitterApi)
        userinfo = self.mocker.mock()
        Api(ANY).GetUserInfo()
        self.mocker.result(userinfo)
        with self.mocker:
            # Associated removes association.
            self.assertTrue(self.twitter.twitter)
            self.assertTrue(self.client.login(username=self.twitter.username,
                                              password=self.twitter.username))
            response = self.client.post(reverse('twitter_associate'))
            self.assertEqual(response.status_code, 200)
            self.assertTrue(TwitterUser.objects.get(user=self.twitter))
            response = self.client.post(reverse('twitter_associate'),
                                        {'action': 'remove',
                                         'twitter_id': '1'})
            self.assertEqual(response.status_code, 200)
            self.assertRaises(TwitterUser.DoesNotExist,
                              TwitterUser.objects.get, user=self.twitter)


    def test_association_user_revoked(self):
        # User visits associate after revoking their Twitter credentials.
        self.assertTrue(self.twitter.twitter)
        self.assertTrue(self.client.login(username=self.twitter.username,
                                          password=self.twitter.username))
        Api = self.mocker.replace(TwitterApi)
        Api(ANY).GetUserInfo()
        self.mocker.throw(HTTPError('url', 401, '', {}, None))
        with self.mocker:
            # User goes off to Twitter and gets redirected back to callback
            session = self.client.session
            session[REQUEST_KEY] = TOKEN.to_string()
            session.save()
            response = self.client.get(reverse('twitter_associate'))
            self.assertEqual(response.status_code, 200)

    def test_callback(self):
        # User goes directly to the callback page.
        response = self.client.get(reverse(oauthtwitter.callback))
        self.assertEqual(response['Location'],
                         'http://testserver%s' % settings.LOGIN_URL)
        # User goes directly to the callback page. but tampers with oauth_token
        response = self.client.get(reverse(oauthtwitter.callback),
                                   {'oauth_token': 'bad'})
        self.assertEqual(response['Location'],
                         'http://testserver%s' % settings.LOGIN_URL)
        # User comes in through Twitter OAuth, but tampers with oauth_token
        o = self.mocker.patch(oauthtwitter)
        request = self.mocker.mock()
        request.GET
        self.mocker.result({'oauth_token': 'bad'})
        request.session
        self.mocker.result({})
        self.mocker.count(1, None)
        request.twitter_request_token
        self.mocker.result(TOKEN)
        # New user comes in through Twitter OAuth
        request.GET
        self.mocker.result({'oauth_token': 'a'})
        request.twitter_request_token
开发者ID:callowayproject,项目名称:django-tweeter,代码行数:70,代码来源:tests.py


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