def test_schedules_job_with_one_child_one_parent(self):
     self.workflow_file_content = "JOB A ls ssh://host/dir\n"
     self.workflow_file_content += "JOB B rm ssh://host/file\n"
     self.workflow_file_content += "PARENT B CHILD A"
     self.run_workflow()
     inorder.verify(self.filesystem).remove(["ssh://host/file"])
     inorder.verify(self.filesystem).list_dir("ssh://host/dir")
    def test_update_draft(self):
        mail = InputMail.from_dict(test_helper.mail_dict())
        when(self.drafts_mailbox).add(mail).thenReturn(mail)

        self.draft_service.update_draft(mail.ident, mail)

        inorder.verify(self.drafts_mailbox).add(mail)
        inorder.verify(self.drafts_mailbox).remove(mail.ident)
    def test_update_draft(self):
        mail = InputMail.from_dict(test_helper.mail_dict())
        when(self.drafts_mailbox).add(mail).thenReturn(mail)

        self.draft_service.update_draft(mail.ident, mail)

        inorder.verify(self.drafts_mailbox).add(mail)
        inorder.verify(self.drafts_mailbox).remove(mail.ident)
    def test_update_draft(self):
        mail = InputMail.from_dict(test_helper.mail_dict())
        when(self.mail_store).add_mail("DRAFTS", mail.raw).thenReturn(defer.succeed(LeapMail("id", "DRAFTS")))

        self.draft_service.update_draft(mail.ident, mail)

        inorder.verify(self.mail_store).add_mail("DRAFTS", mail.raw)
        inorder.verify(self.mail_store).delete_mail(mail.ident)
    def test_update_draft(self):
        mail = InputMail.from_dict(test_helper.mail_dict(), from_address='pixelated@org')
        when(self.mail_store).delete_mail(mail.ident).thenReturn(defer.succeed(True))
        when(self.mail_store).add_mail('DRAFTS', mail.raw).thenReturn(defer.succeed(LeapMail('id', 'DRAFTS')))

        self.draft_service.update_draft(mail.ident, mail)

        inorder.verify(self.mail_store).delete_mail(mail.ident)
        inorder.verify(self.mail_store).add_mail('DRAFTS', mail.raw)
 def test_canAddCommentsToStoryTicket(self):
     tracker = self.makeValidTracker()
     trackerInstance = self.trackerInstance_
     testing = Testing()
     item = self.itemWithComments(testing)
     tracker.updateCommentsFor(item)
     inorder.verify(trackerInstance).AddComment(testing.issue.GetStoryId(), testing.comment1.text())
     inorder.verify(trackerInstance).AddComment(testing.issue.GetStoryId(), testing.comment2.text())
     pass
  def testPassesMixedVerifications(self):
    self.mock.first()
    self.mock.second()

    verify(self.mock).first()
    verify(self.mock).second()

    inorder.verify(self.mock).first()
    inorder.verify(self.mock).second()
Exemple #8
0
    def testPassesMixedVerifications(self):
        self.mock.first()
        self.mock.second()

        verify(self.mock).first()
        verify(self.mock).second()

        inorder.verify(self.mock).first()
        inorder.verify(self.mock).second()
    def test_update_draft(self):
        mail = InputMail.from_dict(test_helper.mail_dict(), from_address='pixelated@org')
        when(self.mail_store).delete_mail(mail.ident).thenReturn(defer.succeed(True))
        when(self.mail_store).add_mail('DRAFTS', mail.raw).thenReturn(defer.succeed(LeapMail('id', 'DRAFTS')))

        self.draft_service.update_draft(mail.ident, mail)

        inorder.verify(self.mail_store).delete_mail(mail.ident)
        inorder.verify(self.mail_store).add_mail('DRAFTS', mail.raw)
 def test_canAddCommentsToStoryTicket(self):
     tracker = self.makeValidTracker()
     trackerInstance = self.trackerInstance_
     testing = Testing()
     item = self.itemWithComments(testing)
     tracker.updateCommentsFor(item)
     inorder.verify(trackerInstance).AddComment(testing.issue.GetStoryId(),
                                                testing.comment1.text())
     inorder.verify(trackerInstance).AddComment(testing.issue.GetStoryId(),
                                                testing.comment2.text())
     pass
Exemple #11
0
 def test_whenSeedingWithRemoteStatusForJira(self):
     ticket = JiraTicket()
     statusId = "1234"
     closed = "Closed"
     ticket.setStatus(statusId)
     mapObject = mock()
     when(mapObject).translateStatusTo('jiraStatusName', statusId).thenReturn([closed])
     status = TrackerItemStatus(ticket, apiObject=mapObject)
     status.pivotal()
     inorder.verify(mapObject).translateStatusTo('jiraStatusName', statusId)
     inorder.verify(mapObject).translateStatusTo('pivotal', closed)
     self.assertEqual(status.jira(), [closed])
Exemple #12
0
    def test_secure_with_mycnf_error(self):
        mock_conn = mock_sql_connection()
        when(mock_conn).execute(any()).thenReturn(None)
        when(utils).execute_with_timeout("sudo", any(str), "stop").thenReturn(None)
        # skip writing the file for now
        when(os.path).isfile(any()).thenReturn(False)
        mock_status = mock()
        when(mock_status).wait_for_real_status_to_change_to(any(), any(), any()).thenReturn(True)
        app = MySqlApp(mock_status)

        self.assertRaises(TypeError, app.secure, None)

        verify(mock_conn, atleast=2).execute(any())
        inorder.verify(mock_status).wait_for_real_status_to_change_to(
            rd_instance.ServiceStatuses.SHUTDOWN, any(), any()
        )
        verifyNoMoreInteractions(mock_status)
Exemple #13
0
    def test_set_data_watcher(self):
        watcher = mock()
        z = pookeeper.allocate(self.hosts)

        z.create('/pookie', CREATOR_ALL_ACL, Ephemeral(), data=_random_data())

        stat = z.exists('/pookie')
        stat = z.set_data('/pookie', _random_data(), stat.version)
        z.get_data('/pookie', watcher=watcher)
        stat = z.set_data('/pookie', _random_data(), stat.version)
        z.get_data('/pookie', watcher=watcher)
        z.delete('/pookie', stat.version)

        z.close()

        inorder.verify(watcher).data_changed('/pookie')
        inorder.verify(watcher).node_deleted('/pookie')
        verifyNoMoreInteractions(watcher)
Exemple #14
0
    def test_secure_with_mycnf_error(self):
        mock_conn = mock_sql_connection()
        when(mock_conn).execute(any()).thenReturn(None)
        when(utils).execute_with_timeout("sudo", any(str), "stop").thenReturn(
            None)
        # skip writing the file for now
        when(os.path).isfile(any()).thenReturn(False)
        mock_status = mock()
        when(mock_status).wait_for_real_status_to_change_to(
            any(), any(), any()).thenReturn(True)
        app = MySqlApp(mock_status)

        self.assertRaises(TypeError, app.secure, None)

        verify(mock_conn, atleast=2).execute(any())
        inorder.verify(mock_status).wait_for_real_status_to_change_to(
            rd_instance.ServiceStatuses.SHUTDOWN, any(), any())
        verifyNoMoreInteractions(mock_status)
  def testFailsMixedVerifications(self):
    self.mock.second()
    self.mock.first()
    
    # first - normal verifications, they should pass
    verify(self.mock).first()
    verify(self.mock).second()

    # but, inorder verification should fail
    self.assertRaises(VerificationError, inorder.verify(self.mock).first)
Exemple #16
0
    def testFailsMixedVerifications(self):
        self.mock.second()
        self.mock.first()

        # first - normal verifications, they should pass
        verify(self.mock).first()
        verify(self.mock).second()

        # but, inorder verification should fail
        self.assertRaises(VerificationError, inorder.verify(self.mock).first)
 def test_schedules_job_with_two_children(self):
     self.workflow_file_content = "JOB A ls ssh://host/dir\n"
     self.workflow_file_content += "JOB B rm ssh://host/file\n"
     self.workflow_file_content += "JOB C ls ssh://host/dir2\n"
     self.workflow_file_content += "JOB D cat ssh://host/file2\n"
     self.workflow_file_content += "PARENT B D CHILD A C\n"
     self.workflow_file_content += "PARENT B CHILD D \n"
     self.workflow_file_content += "PARENT A CHILD C\n"
     self.run_workflow()
     inorder.verify(self.filesystem).remove(["ssh://host/file"])
     inorder.verify(self.filesystem).cat(["ssh://host/file2"])
     inorder.verify(self.filesystem).list_dir("ssh://host/dir")
     inorder.verify(self.filesystem).list_dir("ssh://host/dir2")
Exemple #18
0
    def test_should_get_nouns_for_sentence_given_id(self):
        sentence_map = {
            0: "This is a dumb sentence.",
            1: "This is a dumber sentence.",
            2: "This is a Noun Sentence, noun being good Network."
        }
        tokenised_sentence_map = {
            0: ["dumb", "sentence"],
            1: ["dumber", "sentence"],
            2: ["noun", "sentence", "noun", "good", "network"]
        }
        noun_tokens = ["noun", "sentence", "noun", "network"]
        tokens = ["dumb", "sentence", "sentence", "dumber", "noun", "sentence", "noun", "network"]
        sentence_id = 2
        text_processor = mock()
        when(text_processor).nouns(tokenised_sentence_map[sentence_id]).thenReturn(noun_tokens)

        processed_document = ProcessedDocument(sentence_map, tokenised_sentence_map, tokens)
        processed_document.nouns_in(sentence_id, text_processor=text_processor)
        verify(text_processor).nouns(tokenised_sentence_map[sentence_id])
Exemple #19
0
    def test_exists_default_watcher(self):
        watcher = mock()
        z = pookeeper.allocate(self.hosts, watcher=watcher)

        assert not z.exists('/pookie', watch=True)
        z.create('/pookie', CREATOR_ALL_ACL, Ephemeral(), data=_random_data())

        stat = z.exists('/pookie', watch=True)
        stat = z.set_data('/pookie', _random_data(), stat.version)
        # This data change will be ignored since the watch has been reset
        z.set_data('/pookie', _random_data(), stat.version)
        stat = z.exists('/pookie', watch=True)
        z.delete('/pookie', stat.version)

        z.close()

        inorder.verify(watcher).session_connected(matchers.any(long), matchers.any(str), False)
        inorder.verify(watcher).node_created('/pookie')
        inorder.verify(watcher).data_changed('/pookie')
        inorder.verify(watcher).node_deleted('/pookie')
        inorder.verify(watcher).connection_closed()
        verifyNoMoreInteractions(watcher)
 def testPassesIfMultipleInteractions(self):
   self.mock.first()
   self.mock.second()
   self.mock.third()
   
   inorder.verify(self.mock).first()
   inorder.verify(self.mock).second()
   inorder.verify(self.mock).third()
Exemple #21
0
    def testPassesIfMultipleInteractions(self):
        self.mock.first()
        self.mock.second()
        self.mock.third()

        inorder.verify(self.mock).first()
        inorder.verify(self.mock).second()
        inorder.verify(self.mock).third()
    def test_print_statement_containing_all_transactions(self):
        console = mock()
        clock = mock()

        when(clock).date_as_string().thenReturn('01/04/2015').thenReturn('02/04/2015').thenReturn('10/04/2015')

        account = Account(TransactionRepository(clock), StatementPrinter(console))
        account.deposit(1000)
        account.withdraw(100)
        account.deposit(500)

        account.print_statement()

        inorder.verify(console).print_line('DATE | AMOUNT | BALANCE')
        inorder.verify(console).print_line('10/04/2015 | 500.00 | 1400.00')
        inorder.verify(console).print_line('02/04/2015 | -100.00 | 900.00')
        inorder.verify(console).print_line('01/04/2015 | 1000.00 | 1000.00')
 def test_canAddCommentsToTicket(self):
     jira = JiraTracker()
     jiraInstance = self.getMockFor(jira)
     testing = Testing()
     item = self.itemWithComments(testing)
     jira.updateCommentsFor(item)
     inorder.verify(jiraInstance.service).login(any(),any())
     inorder.verify(jiraInstance.service).addComment(self.auth_, testing.issue.key, {"body":testing.comment1.text()})
     inorder.verify(jiraInstance.service).addComment(self.auth_, testing.issue.key, {"body":testing.comment2.text()})
     pass
Exemple #24
0
    def test_print_statement_containing_all_transactions(self):
        console = mock()
        clock = mock()

        when(clock).date_as_string().thenReturn('01/04/2015').thenReturn(
            '02/04/2015').thenReturn('10/04/2015')

        account = Account(TransactionRepository(clock),
                          StatementPrinter(console))
        account.deposit(1000)
        account.withdraw(100)
        account.deposit(500)

        account.print_statement()

        inorder.verify(console).print_line('DATE | AMOUNT | BALANCE')
        inorder.verify(console).print_line('10/04/2015 | 500.00 | 1400.00')
        inorder.verify(console).print_line('02/04/2015 | -100.00 | 900.00')
        inorder.verify(console).print_line('01/04/2015 | 1000.00 | 1000.00')
 def test_canGetCommentsForTicket(self):
     jira = JiraTracker()
     jiraInstance = self.getMockFor(jira)
     ticket = mock()
     key = "12345"
     twoComments = [RemoteComment("comment0"), RemoteComment("comment1")]        
     when(ticket).Id().thenReturn(key)
     when(jiraInstance.service).getComments(any(),any()).thenReturn(twoComments)
     jira.addCommentsTo(ticket)
     verify(jiraInstance.service).getComments(self.auth_, key)
     inorder.verify(ticket).Id()
     inorder.verify(ticket).addComment(JiraComment(twoComments[0]), 'existing')
     inorder.verify(ticket).addComment(JiraComment(twoComments[1]), 'existing')
     pass
 def test_gettingItemAlsoGetsCommentsForItem(self):
     tracker = self.makeValidTracker()
     trackerInstance = self.trackerInstance_
     story1 = Story()
     story1.story_id = 1234
     story2 = Story()
     story2.story_id = 1235
     when(trackerInstance).GetStories(any()).thenReturn([story1,story2])
     when(trackerInstance).GetComments(any()).thenReturn([])
     itemIterator = tracker.items()
     next(itemIterator)
     next(itemIterator)
     inorder.verify(trackerInstance).GetStories(any())
     inorder.verify(trackerInstance).GetComments(story1.GetStoryId())
     inorder.verify(trackerInstance).GetComments(story2.GetStoryId())
 def test_gettingItemAlsoGetsCommentsForItem(self):
     tracker = self.makeValidTracker()
     trackerInstance = self.trackerInstance_
     story1 = Story()
     story1.story_id = 1234
     story2 = Story()
     story2.story_id = 1235
     when(trackerInstance).GetStories(any()).thenReturn([story1, story2])
     when(trackerInstance).GetComments(any()).thenReturn([])
     itemIterator = tracker.items()
     next(itemIterator)
     next(itemIterator)
     inorder.verify(trackerInstance).GetStories(any())
     inorder.verify(trackerInstance).GetComments(story1.GetStoryId())
     inorder.verify(trackerInstance).GetComments(story2.GetStoryId())
Exemple #28
0
    def test_load_should_delegate_to_registered_providers(self):
        s_symbol = ""

        providerMock1 = mock(AbstractProvider)
        providerMock2 = mock(AbstractProvider)
        providerMock3 = mock(AbstractProvider)
        when(providerMock1).load(s_symbol).thenReturn(None)
        when(providerMock2).load(s_symbol).thenReturn(None)
        when(providerMock3).load(s_symbol).thenReturn(None)

        provider = Provider(providerMock1, providerMock2, providerMock3)
        provider.load(s_symbol)

        inorder.verify(providerMock1, times=1).load(s_symbol)
        inorder.verify(providerMock2, times=1).load(s_symbol)
        inorder.verify(providerMock3, times=1).load(s_symbol)
    def test_load_should_delegate_to_registered_providers(self):
        s_symbol = ""

        providerMock1 = mock(AbstractProvider)
        providerMock2 = mock(AbstractProvider)
        providerMock3 = mock(AbstractProvider)
        when(providerMock1).load(s_symbol).thenReturn(None)
        when(providerMock2).load(s_symbol).thenReturn(None)
        when(providerMock3).load(s_symbol).thenReturn(None)

        provider = Provider(providerMock1, providerMock2, providerMock3)
        provider.load(s_symbol)

        inorder.verify(providerMock1, times=1).load(s_symbol)
        inorder.verify(providerMock2, times=1).load(s_symbol)
        inorder.verify(providerMock3, times=1).load(s_symbol)
 def test_canAddNewItemNotInTrackerAndwhenAddingUpdateItemBeforeUpdatingDetails(self):
     toTracker = mock()
     fromTracker = mock()
     itemToBeAdded = mock()
     detectedItem = mock()
     itemWithDetails = mock()
     TrackerItemType = mock()
     when(fromTracker).items(any()).thenReturn([detectedItem])
     when(toTracker).items(any()).thenReturn([])
     when(TrackerItemType).called().thenReturn(itemToBeAdded)
     when(toTracker).update(itemToBeAdded).thenReturn(itemWithDetails)
     syncByAddingItems = TrackerSyncBy.addingItemsOfType(TrackerItemType.called)
     syncByAddingItems(fromTracker, toTracker)
     inorder.verify(toTracker).items(any())
     inorder.verify(toTracker).update(itemToBeAdded)
     inorder.verify(toTracker).update(itemWithDetails)
 def test_canAddNewItemNotInTrackerAndwhenAddingUpdateItemBeforeUpdatingDetails(
         self):
     toTracker = mock()
     fromTracker = mock()
     itemToBeAdded = mock()
     detectedItem = mock()
     itemWithDetails = mock()
     TrackerItemType = mock()
     when(fromTracker).items(any()).thenReturn([detectedItem])
     when(toTracker).items(any()).thenReturn([])
     when(TrackerItemType).called().thenReturn(itemToBeAdded)
     when(toTracker).update(itemToBeAdded).thenReturn(itemWithDetails)
     syncByAddingItems = TrackerSyncBy.addingItemsOfType(
         TrackerItemType.called)
     syncByAddingItems(fromTracker, toTracker)
     inorder.verify(toTracker).items(any())
     inorder.verify(toTracker).update(itemToBeAdded)
     inorder.verify(toTracker).update(itemWithDetails)
Exemple #32
0
    def test_load_should_delegate_sequentially_till_one_returns_data(self):
        s_symbol = ""
        l_data = ["Sample data"]

        providerMock1 = mock(AbstractProvider)
        providerMock2 = mock(AbstractProvider)
        providerMock3 = mock(AbstractProvider)
        when(providerMock1).load(s_symbol).thenReturn(None)
        when(providerMock2).load(s_symbol).thenReturn(l_data)
        when(providerMock3).load(s_symbol).thenReturn(None)

        provider = Provider(providerMock1, providerMock2, providerMock3)
        result = provider.load(s_symbol)

        assert result == l_data
        inorder.verify(providerMock1, times=1).load(s_symbol)
        inorder.verify(providerMock2, times=1).load(s_symbol)
        inorder.verify(providerMock3, times=0).load(s_symbol)
    def test_load_should_delegate_sequentially_till_one_returns_data(self):
        s_symbol = ""
        l_data = ["Sample data"]

        providerMock1 = mock(AbstractProvider)
        providerMock2 = mock(AbstractProvider)
        providerMock3 = mock(AbstractProvider)
        when(providerMock1).load(s_symbol).thenReturn(None)
        when(providerMock2).load(s_symbol).thenReturn(l_data)
        when(providerMock3).load(s_symbol).thenReturn(None)

        provider = Provider(providerMock1, providerMock2, providerMock3)
        result = provider.load(s_symbol)

        assert result == l_data
        inorder.verify(providerMock1, times=1).load(s_symbol)
        inorder.verify(providerMock2, times=1).load(s_symbol)
        inorder.verify(providerMock3, times=0).load(s_symbol)
 def test_canGetCommentsForTicket(self):
     tracker = self.makeValidTracker()
     trackerInstance = self.trackerInstance_
     story = mock()
     storyId = "12345"
     comment1 = Comment()
     comment1.text = "Comment 1"
     comment2 = Comment()
     comment2.text = "Comment 2"
     twoComments = [comment1, comment2]
     comment1 = PivotalComment(comment1)
     comment2 = PivotalComment(comment2)
     when(story).Id().thenReturn(storyId)
     when(trackerInstance).GetComments(any()).thenReturn(twoComments)
     tracker.addCommentsTo(story)
     verify(trackerInstance).GetComments(storyId)
     inorder.verify(story).Id()
     inorder.verify(story).addComment(comment1, 'existing')
     inorder.verify(story).addComment(comment2, 'existing')
     pass
Exemple #35
0
    def test_exists_watcher(self):
        watcher = mock()
        z = pookeeper.allocate(self.hosts)

        assert not z.exists('/pookie', watcher=watcher)
        z.create('/pookie', CREATOR_ALL_ACL, Ephemeral(), data=_random_data())

        stat = z.exists('/pookie', watcher=watcher)
        stat = z.set_data('/pookie', _random_data(), stat.version)
        # This data change will be ignored since the watch has been reset
        z.set_data('/pookie', _random_data(), stat.version)
        stat = z.exists('/pookie', watcher=watcher)
        z.delete('/pookie', stat.version)

        z.close()

        inorder.verify(watcher).node_created('/pookie')
        inorder.verify(watcher).data_changed('/pookie')
        inorder.verify(watcher).node_deleted('/pookie')
        verifyNoMoreInteractions(watcher)
 def test_canGetCommentsForTicket(self):
     tracker = self.makeValidTracker()
     trackerInstance = self.trackerInstance_
     story = mock()
     storyId = "12345"
     comment1 = Comment()
     comment1.text = "Comment 1"
     comment2 = Comment()
     comment2.text = "Comment 2"
     twoComments = [comment1, comment2]
     comment1 = PivotalComment(comment1)
     comment2 = PivotalComment(comment2)
     when(story).Id().thenReturn(storyId)
     when(trackerInstance).GetComments(any()).thenReturn(twoComments)
     tracker.addCommentsTo(story)
     verify(trackerInstance).GetComments(storyId)
     inorder.verify(story).Id()
     inorder.verify(story).addComment(comment1, 'existing')
     inorder.verify(story).addComment(comment2, 'existing')
     pass
 def testFailsIfWrongOrderOfInteractions(self):
   self.mock.first()
   self.mock.second()
   
   self.assertRaises(VerificationError, inorder.verify(self.mock).second) 
Exemple #38
0
 def test_when_process_is_called_the_instruccion_runs_and_ioDone_is_sent(self):
     self.packageOne = [self.pcb1, self.printLine1]
     self.device.proccess(self.packageOne)  # arrange
     
     verify(self.interruptor).ioDone(self.pcb1)  # assert
Exemple #39
0
 def testErrorMessage(self):
     self.mock.second()
     self.mock.first()
     self.assertRaisesMessage(
         "\nWanted first() to be invoked, got second() instead",
         inorder.verify(self.mock).first)
Exemple #40
0
    def testFailsIfWrongOrderOfInteractions(self):
        self.mock.first()
        self.mock.second()

        self.assertRaises(VerificationError, inorder.verify(self.mock).second)
Exemple #41
0
 def testFailsIfNoInteractions(self):
     self.assertRaises(VerificationError, inorder.verify(self.mock).first)
    def test_load_should_update_providers_that_had_no_data(self):
        s_symbol = ""
        l_data = ["Sample data"]

        providerMock1 = mock(AbstractProvider)
        providerMock2 = mock(AbstractProvider)
        providerMock3 = mock(AbstractProvider)
        when(providerMock1).load(s_symbol).thenReturn(None)
        when(providerMock2).load(s_symbol).thenReturn(None)
        when(providerMock3).load(s_symbol).thenReturn(l_data)

        provider = Provider(providerMock1, providerMock2, providerMock3)
        result = provider.load(s_symbol)

        assert result == l_data
        inorder.verify(providerMock1, times=1).load(s_symbol)
        inorder.verify(providerMock2, times=1).load(s_symbol)
        inorder.verify(providerMock3, times=1).load(s_symbol)

        inorder.verify(providerMock3, times=0).update(anyv(), anyv())
        inorder.verify(providerMock2, times=1).update(s_symbol, l_data)
        inorder.verify(providerMock1, times=1).update(s_symbol, l_data)
Exemple #43
0
 def testPassesIfOneIteraction(self):
     self.mock.first()
     inorder.verify(self.mock).first()
 def testErrorMessage(self):
   self.mock.second()
   self.mock.first()
   self.assertRaisesMessage("\nWanted first() to be invoked, got second() instead", inorder.verify(self.mock).first)
Exemple #45
0
    def test_load_should_update_providers_that_had_no_data(self):
        s_symbol = ""
        l_data = ["Sample data"]

        providerMock1 = mock(AbstractProvider)
        providerMock2 = mock(AbstractProvider)
        providerMock3 = mock(AbstractProvider)
        when(providerMock1).load(s_symbol).thenReturn(None)
        when(providerMock2).load(s_symbol).thenReturn(None)
        when(providerMock3).load(s_symbol).thenReturn(l_data)

        provider = Provider(providerMock1, providerMock2, providerMock3)
        result = provider.load(s_symbol)

        assert result == l_data
        inorder.verify(providerMock1, times=1).load(s_symbol)
        inorder.verify(providerMock2, times=1).load(s_symbol)
        inorder.verify(providerMock3, times=1).load(s_symbol)

        inorder.verify(providerMock3, times=0).update(anyv(), anyv())
        inorder.verify(providerMock2, times=1).update(s_symbol, l_data)
        inorder.verify(providerMock1, times=1).update(s_symbol, l_data)
 def testFailsIfNoInteractions(self):
   self.assertRaises(VerificationError, inorder.verify(self.mock).first)
Exemple #47
0
    def test_task_dependencies(self):
        import pybuilder.reactor

        when(pybuilder.reactor).Task().thenReturn(mock())

        @task
        def task1():
            pass

        @task
        @depends(task1)
        def task2():
            pass

        @task
        def task3():
            pass

        @task
        @depends(optional(task3))
        @dependents("task6")
        def task4():
            pass

        @task
        @dependents("task6", optional(task3))
        def task5():
            pass

        @task
        @depends(task1, optional(task2))
        def task6():
            pass

        module = mock()
        module.task1 = task1
        module.task2 = task2
        module.task3 = task3
        module.task4 = task4
        module.task5 = task5
        module.task6 = task6

        self.reactor.collect_tasks_and_actions_and_initializers(module)

        inorder.verify(pybuilder.reactor).Task("task1", task1, [], '')
        inorder.verify(pybuilder.reactor).Task("task2", task2,
                                               [TaskDependency(task1)], '')
        inorder.verify(pybuilder.reactor).Task("task3", task3,
                                               [TaskDependency(task5, True)],
                                               '')
        inorder.verify(pybuilder.reactor).Task("task4", task4,
                                               [TaskDependency(task3, True)],
                                               '')
        inorder.verify(pybuilder.reactor).Task("task5", task5, [], '')
        inorder.verify(pybuilder.reactor).Task("task6", task6, [
            TaskDependency(task1),
            TaskDependency(task2, True),
            TaskDependency(task4),
            TaskDependency(task5)
        ], '')
    def test_start_with_device_disconnected(self):
        '''
        Test that the add event does not get invoked on start-up.
        '''
        event = Event()
        event.clear()

        def _add_handler():
            self._logger.debug('Invoked')
            event.set()

        mock_monitor = MockDeviceMonitor(dormant=True)
        mock_device = mock()
        when(mock_device).get_vendor_id().thenReturn(0)
        when(mock_device).get_product_id().thenReturn(0)
        when(mock_device).is_open().thenReturn(False)

        # Execute
        controller = DeviceController(mock_device,
                                      usb_transfer_types.RAW,
                                      mock_monitor,
                                      add_event_handler=_add_handler,
                                      logger=self._logger)
        controller.start()
        self.assertTrue(controller.running)
        event.wait(0.1)
        controller.stop()
        self.assertFalse(controller.running)

        # The event must not have been raised
        self.assertFalse(event.is_set(), 'Add handler must not be invoked')

        # Verify mocks
        inorder.verify(mock_device, times=1).get_vendor_id()
        inorder.verify(mock_device, times=1).get_product_id()
        inorder.verify(mock_device, times=1).open()
        # Once on start-up and once on shutdown
        # But, it seems mockito needs it to be verified twice, otherwise
        # the verify.close will fail.
        inorder.verify(mock_device, times=2).is_open()
        inorder.verify(mock_device, times=2).is_open()
        inorder.verify(mock_device, times=0).close()
    def test_task_dependencies(self):
        import pybuilder.reactor

        when(pybuilder.reactor).Task().thenReturn(mock())

        @task
        def task1():
            pass

        @task
        @depends(task1)
        def task2():
            pass

        @task
        def task3():
            pass

        @task
        @depends(optional(task3))
        @dependents("task6")
        def task4():
            pass

        @task
        @dependents("task6", optional(task3))
        def task5():
            pass

        @task
        @depends(task1, optional(task2))
        def task6():
            pass

        module = mock()
        module.task1 = task1
        module.task2 = task2
        module.task3 = task3
        module.task4 = task4
        module.task5 = task5
        module.task6 = task6

        self.reactor.collect_tasks_and_actions_and_initializers(module)

        inorder.verify(pybuilder.reactor).Task("task1", task1, [], '')
        inorder.verify(pybuilder.reactor).Task("task2", task2, [TaskDependency(task1)], '')
        inorder.verify(pybuilder.reactor).Task("task3", task3, [TaskDependency(task5, True)], '')
        inorder.verify(pybuilder.reactor).Task("task4", task4, [TaskDependency(task3, True)], '')
        inorder.verify(pybuilder.reactor).Task("task5", task5, [], '')
        inorder.verify(pybuilder.reactor).Task("task6", task6, [TaskDependency(task1), TaskDependency(task2, True),
                                                                TaskDependency(task4), TaskDependency(task5)], '')
 def testPassesIfOneIteraction(self):
   self.mock.first()    
   inorder.verify(self.mock).first()