Home | History | Annotate | Download | only in perfbot_stats
      1 #!/usr/bin/env python2.7
      2 # Copyright 2015 The Chromium Authors. All rights reserved.
      3 # Use of this source code is governed by a BSD-style license that can be
      4 # found in the LICENSE file.
      5 
      6 import unittest
      7 
      8 from perfbot_stats import chrome_perf_stats
      9 
     10 
     11 class TestChromePerfStats(unittest.TestCase):
     12 
     13   def testUpdateSuccessRatesWithResult(self):
     14     success_rates = {}
     15     chrome_perf_stats._UpdateSuccessRatesWithResult(
     16         success_rates,
     17         {'count': 0},
     18         'invalid_date_str',
     19         'invalid_builder')
     20     self.assertDictEqual({}, success_rates)
     21     chrome_perf_stats._UpdateSuccessRatesWithResult(
     22         success_rates,
     23         {'count': 5, 'failure_count': 3},
     24         '20151010',
     25         'android_nexus_10')
     26     self.assertDictEqual(
     27         {'20151010': {'android_nexus_10': {'count': 5, 'success_count': 2}}},
     28         success_rates)
     29     chrome_perf_stats._UpdateSuccessRatesWithResult(
     30         success_rates,
     31         {'count': 5, 'failure_count': 4},
     32         '20151010',
     33         'android_nexus_4')
     34     self.assertDictEqual(
     35         {
     36             '20151010': {
     37                 'android_nexus_10': {'count': 5, 'success_count': 2},
     38                 'android_nexus_4': {'count': 5, 'success_count': 1},
     39             }
     40         },
     41         success_rates)
     42     chrome_perf_stats._UpdateSuccessRatesWithResult(
     43         success_rates,
     44         {'count': 5, 'failure_count': 0},
     45         '20151009',
     46         'win_xp')
     47     self.assertDictEqual(
     48         {
     49             '20151010': {
     50                 'android_nexus_10': {'count': 5, 'success_count': 2},
     51                 'android_nexus_4': {'count': 5, 'success_count': 1},
     52             },
     53             '20151009': {
     54                 'win_xp': {'count': 5, 'success_count': 5},
     55             },
     56         },
     57         success_rates)
     58 
     59   def testSummarizeSuccessRates(self):
     60     rates = chrome_perf_stats._SummarizeSuccessRates(
     61         {
     62             '20151010': {
     63                 'android_nexus_10': {'count': 5, 'success_count': 2},
     64                 'android_nexus_4': {'count': 5, 'success_count': 3},
     65             },
     66             '20151009': {
     67                 'win_xp': {'count': 5, 'success_count': 5},
     68             },
     69         })
     70     self.assertListEqual([['20151010', 0.5], ['20151009', 1.0]], rates)
     71 
     72 
     73 if __name__ == '__main__':
     74   unittest.main()
     75