def testRun(self): pipeline = RevisionsDiffPipeline('Hello', 'Hello there', {}) pipeline.start_test() result = pipeline.outputs.default.value expected = Revision() expected.wordsAdded = 1 expected.wordsDeleted = 0 expected.wordCount = 2 self.assertEqual(result, expected.to_dict())
def main(cli_args): client = TreeherderClient(cli_args.repo, cli_args.csrf_token, cli_args.session_id) revision = Revision(client, cli_args.revision) results = revision.results jobs = [result.get_jobs_for(cli_args.job_type, job_number=cli_args.job_number, job_platform=cli_args.job_platform) for result in results] jobs = _flatten_list(jobs) for job in jobs: for i in range(1, cli_args.repeat + 1): print('Repeat #{}'.format(i)) job.__getattribute__(cli_args.command)()
def run(self, revisionTextA, revisionTextB, revisionDict): gdiff = diff_match_patch() revisionDiffs = gdiff.diff_main(revisionTextA, revisionTextB, False) gdiff.diff_cleanupSemantic(revisionDiffs) revisionDiffs = filter(self.isRemoveOrAdd, revisionDiffs) diffWordCount = map(self.countWords, revisionDiffs) addedWordCount = self.getAddWordCount(diffWordCount) deletedWordCount = self.getDeletedWordCount(diffWordCount) revision = Revision(**revisionDict) revision.wordsAdded = addedWordCount revision.wordsDeleted = deletedWordCount revision.wordCount = self.getWordCount(revisionTextB) return revision.to_dict()
def run(self, toEmail, documentId, credentialsAsJson): credentials = OAuth2Credentials.from_json(credentialsAsJson) http = credentials.authorize(httplib2.Http()) request = config.getService().revisions().list(fileId=documentId) response = request.execute(http=http) revisions = [] for item in response.get('items'): revision = Revision() revision.documentId = documentId revision.revisionNumber = item.get('id') revision.author = item.get('lastModifyingUserName') revision.exportLink = item.get('exportLinks').get('text/plain') revision.dateTime = item.get('modifiedDate') revisions.append(revision.to_dict()) return revisions
def run(self, toEmail, subject, body, documentsAnalyses): # TODO(michaelcupino): Move csv transforms into a service. csvFile = tempfile.TemporaryFile() writer = csv.writer(csvFile) values = [['Date', 'Time', 'Who in doc', 'Word count', 'Words added', 'Words deleted', 'Punct. cap', 'Words moved', 'Document ID', 'Document Name']] writer.writerows(values) for documentAnalyses in documentsAnalyses: for documentAnalysis in documentAnalyses: revision = Revision(**documentAnalysis) values = [[ revision.dateTime, # Date '', # Time revision.author, revision.wordCount, revision.wordsAdded, revision.wordsDeleted, '', # Punct. cap '', # Words moved revision.documentId, # Document ID '', # Document Name ]] writer.writerows(values) csvFile.seek(0) csvFileBytes = csvFile.read() csvFile.close() message = mail.EmailMessage() message.sender = '*****@*****.**' message.to = toEmail message.subject = subject message.body = str(body) message.attachments = [('export.csv', csvFileBytes)] message.send()
def testRun(self, mockUrlOpenMethod): exportLinks = [ 'docs.google.com/123', 'docs.google.com/456', 'docs.google.com/789' ] mockRevisions = [ Revision(exportLink=exportLinks[0]).to_dict(), Revision(exportLink=exportLinks[1]).to_dict(), Revision(exportLink=exportLinks[2]).to_dict() ] exportedText = { exportLinks[0]: StringIO('Hello'), exportLinks[1]: StringIO('Hello world.'), exportLinks[2]: StringIO('Hello.'), } mockUrlOpenMethod.side_effect = lambda url: exportedText[url] # TODO(michaelcupino): Fix tests pipeline = RevisionsAnalysisPipeline(mockRevisions, None) pipeline.start_test() result = pipeline.outputs.default.value revision1 = Revision() revision1.wordsAdded = 1 revision1.wordsDeleted = 0 revision1.wordCount = 1 revision1.exportLink = 'docs.google.com/123' revision2 = Revision() revision2.wordsAdded = 1 revision2.wordsDeleted = 0 revision2.wordCount = 2 revision2.exportLink = 'docs.google.com/456' revision3 = Revision() revision3.wordsAdded = 0 revision3.wordsDeleted = 1 revision3.wordCount = 1 revision3.exportLink = 'docs.google.com/789' self.assertEqual([revision1.to_dict(), revision2.to_dict(), revision3.to_dict()], result)
def testRun(self, mockOAuth2CredentialsFromJsonMethod, mockUrlOpenMethod): http = HttpMockSequence([ ({ 'status': '200' }, open(datafile('test-drive-revisions-list-0.json'), 'rb').read()), ]) mockCredentials = MagicMock(name='mockCredentials') mockCredentials.authorize = MagicMock(return_value=http) mockOAuth2CredentialsFromJsonMethod.return_value = mockCredentials exportLinks = [ ('https://docs.google.com/feeds/download/documents/export/Export?id=1Duz2' 'yYSTSgdWQhTgEJ3zPELKTHS3WGhPVLQk1PDJm3Q&revision=697&exportFormat=tx' 't'), ('https://docs.google.com/feeds/download/documents/export/Export?id=1Duz2' 'yYSTSgdWQhTgEJ3zPELKTHS3WGhPVLQk1PDJm3Q&revision=698&exportFormat=tx' 't'), ('https://docs.google.com/feeds/download/documents/export/Export?id=1Duz2' 'yYSTSgdWQhTgEJ3zPELKTHS3WGhPVLQk1PDJm3Q&revision=868&exportFormat=tx' 't'), ('https://docs.google.com/feeds/download/documents/export/Export?id=1Duz2' 'yYSTSgdWQhTgEJ3zPELKTHS3WGhPVLQk1PDJm3Q&revision=869&exportFormat=tx' 't'), ('https://docs.google.com/feeds/download/documents/export/Export?id=1Duz2' 'yYSTSgdWQhTgEJ3zPELKTHS3WGhPVLQk1PDJm3Q&revision=937&exportFormat=tx' 't'), ('https://docs.google.com/feeds/download/documents/export/Export?id=1Duz2' 'yYSTSgdWQhTgEJ3zPELKTHS3WGhPVLQk1PDJm3Q&revision=939&exportFormat=tx' 't'), ('https://docs.google.com/feeds/download/documents/export/Export?id=1Duz2' 'yYSTSgdWQhTgEJ3zPELKTHS3WGhPVLQk1PDJm3Q&revision=1035&exportFormat=t' 'xt'), ('https://docs.google.com/feeds/download/documents/export/Export?id=1Duz2' 'yYSTSgdWQhTgEJ3zPELKTHS3WGhPVLQk1PDJm3Q&revision=1036&exportFormat=t' 'xt'), ('https://docs.google.com/feeds/download/documents/export/Export?id=1Duz2' 'yYSTSgdWQhTgEJ3zPELKTHS3WGhPVLQk1PDJm3Q&revision=1048&exportFormat=t' 'xt'), ('https://docs.google.com/feeds/download/documents/export/Export?id=1Duz2' 'yYSTSgdWQhTgEJ3zPELKTHS3WGhPVLQk1PDJm3Q&revision=1049&exportFormat=t' 'xt'), ('https://docs.google.com/feeds/download/documents/export/Export?id=1Duz2' 'yYSTSgdWQhTgEJ3zPELKTHS3WGhPVLQk1PDJm3Q&revision=1057&exportFormat=t' 'xt') ] exportedText = { exportLinks[0]: StringIO('Hello'), exportLinks[1]: StringIO('Hello world.'), exportLinks[2]: StringIO('Hello'), exportLinks[3]: StringIO(''), exportLinks[4]: StringIO('Hello again, this is a longer sentence'), exportLinks[5]: StringIO(('Hello again, this is a longer sentence with ' 'another word')), exportLinks[6]: StringIO(('Hello again, this is a longer sentence with ' 'another word. Here is another sentence')), exportLinks[7]: StringIO( ('Hello again, this is a longer sentence with ' 'another word. Here is another sentence with another word')), exportLinks[8]: StringIO( ('Hello again, this is a longer sentence with ' 'another word. Here is another sentence with another word')), exportLinks[9]: StringIO(('Hello again, this is a longer sentence with ' 'another word. Here is another sentence.')), exportLinks[10]: StringIO(('Hello again, this is a longer sentence with ' 'another word. Here is another sentence. The end.')) } mockUrlOpenMethod.side_effect = lambda url: exportedText[url] # TODO(michaelcupino): Fix tests pipeline = DocumentAnalysisPipeline('*****@*****.**', 'abc123', None) pipeline.start_test() result = pipeline.outputs.default.value # TODO(michaelcupino): Updated expected data to match actual result. expectedResult = [] expectedResult.append( Revision( wordsAdded=1, wordsDeleted=0, wordCount=1, author='Jonathan H', dateTime='2014-03-15T17:49:32.768Z', exportLink= ('https://docs.google.com/feeds/download/documents/export/Ex' 'port?id=1Duz2yYSTSgdWQhTgEJ3zPELKTHS3WGhPVLQk1PDJm3Q&revision=697&' 'exportFormat=txt'), revisionNumber='697', documentId='abc123').to_dict()) expectedResult.append(Revision(wordsAdded=1, wordsDeleted=0).to_dict()) expectedResult.append(Revision(wordsAdded=0, wordsDeleted=1).to_dict()) expectedResult.append(Revision(wordsAdded=0, wordsDeleted=1).to_dict()) expectedResult.append(Revision(wordsAdded=7, wordsDeleted=0).to_dict()) expectedResult.append(Revision(wordsAdded=3, wordsDeleted=0).to_dict()) expectedResult.append(Revision(wordsAdded=5, wordsDeleted=0).to_dict()) expectedResult.append(Revision(wordsAdded=3, wordsDeleted=0).to_dict()) expectedResult.append(Revision(wordsAdded=0, wordsDeleted=0).to_dict()) # TODO(michaelcupino): I would have expected there to be no words added. # Figure out why this behavior occurrs. expectedResult.append(Revision(wordsAdded=1, wordsDeleted=3).to_dict()) expectedResult.append(Revision(wordsAdded=2, wordsDeleted=0).to_dict()) self.assertEqual(expectedResult, result)