Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import datetime | |
| 5 import unittest | 6 import unittest |
| 6 | 7 |
| 7 from infra.tools.antibody import compute_stats | 8 from infra.tools.antibody import compute_stats |
| 8 | 9 |
| 9 | 10 |
| 11 class Cursor(object): | |
| 12 def execute(self, arg): | |
| 13 pass | |
| 14 | |
| 15 def fetchall(self): | |
| 16 results = (('https://codereview.chromium.org/1148323006', | |
| 17 datetime.datetime(2015, 5, 28, 16, 8, 33), | |
| 18 'suppress-uninit-error-from-sessions-SessionBackend-' | |
| 19 'AppendCommandsToFile', | |
| 20 'bf1cf11bb721eb52bf46868cb831afd1f53567af'), | |
| 21 ('https://codereview.chromium.org/1159593004', | |
| 22 datetime.datetime(2015, 6, 1, 3, 37, 20), | |
| 23 'Revert-of-Converted-some-extension-browser-tests-into-using-' | |
| 24 'event-pages-patchset-1-id-60001-of-https-codereview.chromium.' | |
| 25 'org-1108133002', | |
| 26 'cda8c938f06f9955ac895099d05a9db3b61f3ab5'), | |
| 27 ('https://codereview.chromium.org/1156073004', | |
| 28 datetime.datetime(2015, 5, 26, 20, 52, 41), | |
| 29 'MemSheriff-Expand-suppressions-for-sqlite3-uninitialized-' | |
| 30 'reads', | |
| 31 'f48757cfe41e83e770095253b90775eb70f024b3'), | |
| 32 ('https://codereview.chromium.org/1124083006', | |
| 33 datetime.datetime(2015, 5, 20, 0, 26, 31), | |
| 34 'Revert-of-Temporarily-disable-a-webgl-conformance-test-on-' | |
| 35 'D3D9-only.-patchset-1-id-1-of-https-codereview.chromium.org-' | |
| 36 '1135333004', | |
| 37 '0b0b636093a7dbb56cc8712e2263b1c9a1ad8079')) | |
| 38 return results | |
| 39 | |
| 10 class TestComputeStats(unittest.TestCase): | 40 class TestComputeStats(unittest.TestCase): |
| 41 def setUp(self): | |
| 42 self.cc = Cursor() | |
| 43 | |
| 11 def test_ratio_calculator(self): | 44 def test_ratio_calculator(self): |
| 12 reg_num = [['2014-01', 1], ['2014-02', 3], ['2014-07', 5]] | 45 reg_num = [['2014-01', 1], ['2014-02', 3], ['2014-07', 5]] |
| 13 reg_den = [['2014-07', 10], ['2014-02', 6], ['2014-01', 9]] | 46 reg_den = [['2014-07', 10], ['2014-02', 6], ['2014-01', 9]] |
| 14 reg_ratio = compute_stats.ratio_calculator(reg_num, reg_den) | 47 reg_ratio = compute_stats.ratio_calculator(reg_num, reg_den) |
| 15 self.assertEqual(reg_ratio, | 48 self.assertEqual(reg_ratio, |
| 16 [['2014-01', 0.111], ['2014-02', 0.5], ['2014-07', 0.5]]) | 49 [['2014-01', 0.111], ['2014-02', 0.5], ['2014-07', 0.5]]) |
| 17 | 50 |
| 18 zero_num = [['2014-01', 1], ['2014-02', 0], ['2014-07', 5]] | 51 zero_num = [['2014-01', 1], ['2014-02', 0], ['2014-07', 5]] |
| 19 zero_den = [['2014-07', 10], ['2014-02', 0], ['2014-01', 0]] | 52 zero_den = [['2014-07', 10], ['2014-02', 0], ['2014-01', 0]] |
| 20 zero_ratio = compute_stats.ratio_calculator(zero_num, zero_den) | 53 zero_ratio = compute_stats.ratio_calculator(zero_num, zero_den) |
| 21 self.assertEqual(zero_ratio, | 54 self.assertEqual(zero_ratio, |
| 22 [['2014-01', 0], ['2014-02', 0], ['2014-07', 0.5]]) | 55 [['2014-01', 0], ['2014-02', 0], ['2014-07', 0.5]]) |
| 23 | 56 |
| 24 missing_num = [['2014-01', 1], ['2014-02', 3], ['2014-07', 5]] | 57 missing_num = [['2014-01', 1], ['2014-02', 3], ['2014-07', 5]] |
| 25 missing_den = [['2014-02', 3], ['2014-07', 10]] | 58 missing_den = [['2014-02', 3], ['2014-07', 10]] |
| 26 missing_ratio = compute_stats.ratio_calculator(missing_num, missing_den) | 59 missing_ratio = compute_stats.ratio_calculator(missing_num, missing_den) |
| 27 self.assertEqual(missing_ratio, | 60 self.assertEqual(missing_ratio, |
| 28 [['2014-02', 1.0], ['2014-07', 0.5]]) | 61 [['2014-02', 1.0], ['2014-07', 0.5]]) |
| 29 | 62 |
| 30 extra_num = [['2014-01', 1], ['2014-02', 3], ['2014-07', 5]] | 63 extra_num = [['2014-01', 1], ['2014-02', 3], ['2014-07', 5]] |
| 31 extra_den = [['2014-02', 3], ['2015-07', 5], ['2015-07', 5]] | 64 extra_den = [['2014-02', 3], ['2015-07', 5], ['2015-07', 5]] |
| 32 extra_ratio = compute_stats.ratio_calculator(extra_num, extra_den) | 65 extra_ratio = compute_stats.ratio_calculator(extra_num, extra_den) |
| 33 self.assertEqual(extra_ratio, [['2014-02', 1.0]]) | 66 self.assertEqual(extra_ratio, [['2014-02', 1.0]]) |
| 34 | 67 |
| 35 def test_totaled_ratio_calculator(self): | 68 def test_totaled_ratio_calculator(self): |
| 36 ratio = compute_stats.totaled_ratio_calculator(3, 7) | 69 ratio = compute_stats.totaled_ratio_calculator(3, 7) |
| 37 self.assertEqual(ratio, 0.429) | 70 self.assertEqual(ratio, 0.429) |
| 38 self.assertRaises(ZeroDivisionError, | 71 zero_ratio = compute_stats.totaled_ratio_calculator(5, 0) |
| 39 compute_stats.totaled_ratio_calculator, 5, 0) | 72 self.assertEqual(zero_ratio, 0) |
| 73 | |
| 74 def test_totaled_tbr_no_lgtm(self): | |
|
pgervais
2015/07/27 23:14:07
This method and the following two are basically th
| |
| 75 sql_time_specification = 'DATEDIFF(git_commit.timestamp, NOW()) < 0' | |
| 76 total_num, output = compute_stats.totaled_tbr_no_lgtm(self.cc, | |
| 77 sql_time_specification) | |
| 78 self.assertEqual(total_num, 4) | |
| 79 self.assertEqual(output, | |
| 80 [['https://codereview.chromium.org/1148323006', | |
| 81 '2015-05-28 16:08:33', | |
| 82 'suppress-uninit-error-from-sessions-SessionBackend-' | |
| 83 'AppendCommandsToFile', | |
| 84 'bf1cf11bb721eb52bf46868cb831afd1f53567af'], | |
| 85 ['https://codereview.chromium.org/1159593004', | |
| 86 '2015-06-01 03:37:20', | |
| 87 'Revert-of-Converted-some-extension-browser-tests-into-using-' | |
| 88 'event-pages-patchset-1-id-60001-of-https-codereview.chromium.' | |
| 89 'org-1108133002', | |
| 90 'cda8c938f06f9955ac895099d05a9db3b61f3ab5'], | |
| 91 ['https://codereview.chromium.org/1156073004', | |
| 92 '2015-05-26 20:52:41', | |
| 93 'MemSheriff-Expand-suppressions-for-sqlite3-uninitialized-' | |
| 94 'reads', | |
| 95 'f48757cfe41e83e770095253b90775eb70f024b3'], | |
| 96 ['https://codereview.chromium.org/1124083006', | |
| 97 '2015-05-20 00:26:31', | |
| 98 'Revert-of-Temporarily-disable-a-webgl-conformance-test-on-' | |
| 99 'D3D9-only.-patchset-1-id-1-of-https-codereview.chromium.org-' | |
| 100 '1135333004', | |
| 101 '0b0b636093a7dbb56cc8712e2263b1c9a1ad8079']]) | |
| 102 | |
| 103 def test_totaled_blank_tbr(self): | |
| 104 sql_time_specification = 'DATEDIFF(git_commit.timestamp, NOW()) < 0' | |
| 105 total_num, output = compute_stats.totaled_blank_tbr(self.cc, | |
| 106 sql_time_specification) | |
| 107 self.assertEqual(total_num, 4) | |
| 108 self.assertEqual(output, | |
| 109 [['https://codereview.chromium.org/1148323006', | |
| 110 '2015-05-28 16:08:33', | |
| 111 'suppress-uninit-error-from-sessions-SessionBackend-' | |
| 112 'AppendCommandsToFile', | |
| 113 'bf1cf11bb721eb52bf46868cb831afd1f53567af'], | |
| 114 ['https://codereview.chromium.org/1159593004', | |
| 115 '2015-06-01 03:37:20', | |
| 116 'Revert-of-Converted-some-extension-browser-tests-into-using-' | |
| 117 'event-pages-patchset-1-id-60001-of-https-codereview.chromium.' | |
| 118 'org-1108133002', | |
| 119 'cda8c938f06f9955ac895099d05a9db3b61f3ab5'], | |
| 120 ['https://codereview.chromium.org/1156073004', | |
| 121 '2015-05-26 20:52:41', | |
| 122 'MemSheriff-Expand-suppressions-for-sqlite3-uninitialized-' | |
| 123 'reads', | |
| 124 'f48757cfe41e83e770095253b90775eb70f024b3'], | |
| 125 ['https://codereview.chromium.org/1124083006', | |
| 126 '2015-05-20 00:26:31', | |
| 127 'Revert-of-Temporarily-disable-a-webgl-conformance-test-on-' | |
| 128 'D3D9-only.-patchset-1-id-1-of-https-codereview.chromium.org-' | |
| 129 '1135333004', | |
| 130 '0b0b636093a7dbb56cc8712e2263b1c9a1ad8079']]) | |
| 131 | |
| 132 def test_totaled_no_review_url(self): | |
| 133 sql_time_specification = 'DATEDIFF(git_commit.timestamp, NOW()) < 0' | |
| 134 total_num, output = compute_stats.totaled_no_review_url(self.cc, | |
| 135 sql_time_specification) | |
| 136 self.assertEqual(total_num, 4) | |
| 137 self.assertEqual(output, | |
| 138 [['https://codereview.chromium.org/1148323006', | |
| 139 '2015-05-28 16:08:33', | |
| 140 'suppress-uninit-error-from-sessions-SessionBackend-' | |
| 141 'AppendCommandsToFile', | |
| 142 'bf1cf11bb721eb52bf46868cb831afd1f53567af'], | |
| 143 ['https://codereview.chromium.org/1159593004', | |
| 144 '2015-06-01 03:37:20', | |
| 145 'Revert-of-Converted-some-extension-browser-tests-into-using-' | |
| 146 'event-pages-patchset-1-id-60001-of-https-codereview.chromium.' | |
| 147 'org-1108133002', | |
| 148 'cda8c938f06f9955ac895099d05a9db3b61f3ab5'], | |
| 149 ['https://codereview.chromium.org/1156073004', | |
| 150 '2015-05-26 20:52:41', | |
| 151 'MemSheriff-Expand-suppressions-for-sqlite3-uninitialized-' | |
| 152 'reads', | |
| 153 'f48757cfe41e83e770095253b90775eb70f024b3'], | |
| 154 ['https://codereview.chromium.org/1124083006', | |
| 155 '2015-05-20 00:26:31', | |
| 156 'Revert-of-Temporarily-disable-a-webgl-conformance-test-on-' | |
| 157 'D3D9-only.-patchset-1-id-1-of-https-codereview.chromium.org-' | |
| 158 '1135333004', | |
| 159 '0b0b636093a7dbb56cc8712e2263b1c9a1ad8079']]) | |
| OLD | NEW |