#!/usr/bin/env python #-*- coding: utf-8 -*- # Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. # # Use of this source code is governed by a BSD-style license # that can be found in the LICENSE file in the root of the source # tree. An additional intellectual property rights grant can be found # in the file PATENTS. All contributing project authors may # be found in the AUTHORS file in the root of the source tree. """Contains functions for parsing the build master's transposed grid page.""" __author__ = 'phoglund@webrtc.org (Patrik Höglund)' import unittest import tgrid_parser SAMPLE_FILE = """ Buildbot
1570 OK OK OK OK OK OK OK OK OK OK OK OK
1571 OK OK OK OK OK OK OK OK failed
voe_auto_test
OK building OK
""" MINIMAL_OK = """ 1570 OK """ MINIMAL_FAIL = """ 1573 failed
voe_auto_test """ MINIMAL_BUILDING = """ 1576 building voe_auto_test """ class TGridParserTest(unittest.TestCase): def test_parser_throws_exception_on_empty_html(self): self.assertRaises(tgrid_parser.FailedToParseBuildStatus, tgrid_parser.parse_tgrid_page, ''); def test_parser_finds_successful_bot(self): result = tgrid_parser.parse_tgrid_page(MINIMAL_OK) self.assertEqual(1, len(result), 'There is only one bot in the sample.') first_mapping = result.items()[0] self.assertEqual('1570--Android', first_mapping[0]) self.assertEqual('121--OK', first_mapping[1]) def test_parser_finds_failed_bot(self): result = tgrid_parser.parse_tgrid_page(MINIMAL_FAIL) self.assertEqual(1, len(result), 'There is only one bot in the sample.') first_mapping = result.items()[0] self.assertEqual('1573--LinuxVideoTest', first_mapping[0]) self.assertEqual('347--failed', first_mapping[1]) def test_parser_finds_building_bot(self): result = tgrid_parser.parse_tgrid_page(MINIMAL_BUILDING) self.assertEqual(1, len(result), 'There is only one bot in the sample.') first_mapping = result.items()[0] self.assertEqual('1576--Win32Debug', first_mapping[0]) self.assertEqual('434--building', first_mapping[1]) def test_parser_finds_all_bots_and_revisions(self): result = tgrid_parser.parse_tgrid_page(SAMPLE_FILE) # 2 * 12 = 24 bots in sample self.assertEqual(24, len(result)) # Make some samples self.assertTrue(result.has_key('1570--ChromeOS')) self.assertEquals('578--OK', result['1570--ChromeOS']) self.assertTrue(result.has_key('1570--LinuxCLANG')) self.assertEquals('259--OK', result['1570--LinuxCLANG']) self.assertTrue(result.has_key('1570--Win32Release')) self.assertEquals('440--OK', result['1570--Win32Release']) self.assertTrue(result.has_key('1571--ChromeOS')) self.assertEquals('579--OK', result['1571--ChromeOS']) self.assertTrue(result.has_key('1571--LinuxVideoTest')) self.assertEquals('346--failed', result['1571--LinuxVideoTest']) self.assertTrue(result.has_key('1571--Win32Debug')) self.assertEquals('441--building', result['1571--Win32Debug']) if __name__ == '__main__': unittest.main()