Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(197)

Side by Side Diff: infra/tools/antibody/test/antibody_test.py

Issue 1235373004: Added script to generate stats on a git checkout (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@new_antibody_db_schema
Patch Set: Rebase Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 """Tool-specific testable functions for antibody.""" 5 """Tool-specific testable functions for antibody."""
6 6
7 import argparse 7 import argparse
8 import datetime 8 import datetime
9 import json 9 import json
10 import os 10 import os
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 self.assertTrue(args.parse_git_rietveld) 43 self.assertTrue(args.parse_git_rietveld)
44 self.assertEqual(args.output_dir_path, '/efg') 44 self.assertEqual(args.output_dir_path, '/efg')
45 self.assertEqual(args.since, '2000') 45 self.assertEqual(args.since, '2000')
46 46
47 def test_generate_antibody_ui(self): 47 def test_generate_antibody_ui(self):
48 with infra_libs.temporary_directory(prefix='antibody-test') as dirname: 48 with infra_libs.temporary_directory(prefix='antibody-test') as dirname:
49 commit_data = 'data/sample_suspicious_commits.txt' 49 commit_data = 'data/sample_suspicious_commits.txt'
50 with open(os.path.join(THIS_DIR, commit_data), 'r') as f: 50 with open(os.path.join(THIS_DIR, commit_data), 'r') as f:
51 suspicious_commits_data = [line.rstrip('\n').split(',') for line in f] 51 suspicious_commits_data = [line.rstrip('\n').split(',') for line in f]
52 temp_data_gitiles="https://chromium.googlesource.com/infra/infra/+/" 52 temp_data_gitiles="https://chromium.googlesource.com/infra/infra/+/"
53 sample_monthly_stats = {
54 '7_days': {
55 'suspicious_to_total_ratio': 1,
56 'total_commits': 2,
57 'tbr_no_lgtm': 3,
58 'no_review_url': 4,
59 'blank_tbr': 5,
60 },
61 '30_days': {
62 'suspicious_to_total_ratio': 1,
63 'total_commits': 2,
64 'tbr_no_lgtm': 3,
65 'no_review_url': 4,
66 'blank_tbr': 5,
67 },
68 'all_time': {
69 'suspicious_to_total_ratio': 1,
70 'total_commits': 2,
71 'tbr_no_lgtm': 3,
72 'no_review_url': 4,
73 'blank_tbr': 5,
74 },
75 }
76 with open(os.path.join(dirname, 'all_monthly_stats.json'), 'w') as f:
77 json.dump(sample_monthly_stats, f)
53 antibody.generate_antibody_ui(suspicious_commits_data, temp_data_gitiles, 78 antibody.generate_antibody_ui(suspicious_commits_data, temp_data_gitiles,
54 dirname) 79 dirname)
55 with open( 80 with open(
56 os.path.join(dirname, antibody.ANTIBODY_UI_MAIN_NAME), 'r') as f: 81 os.path.join(dirname, antibody.ANTIBODY_UI_MAIN_NAME), 'r') as f:
57 file_string = f.read() 82 file_string = f.read()
58 self.assertTrue(file_string) 83 self.assertTrue(file_string)
59 self.assertFalse('{{' in file_string) 84 self.assertFalse('{{' in file_string)
60 self.assertFalse('}}' in file_string) 85 self.assertFalse('}}' in file_string)
61 86
62 with open(os.path.join(dirname, antibody.TBR_BY_USER_NAME), 'r') as f: 87 with open(os.path.join(dirname, antibody.TBR_BY_USER_NAME), 'r') as f:
63 file_string = f.read() 88 file_string = f.read()
64 self.assertTrue(file_string) 89 self.assertTrue(file_string)
65 self.assertFalse('{{' in file_string) 90 self.assertFalse('{{' in file_string)
66 self.assertFalse('}}' in file_string) 91 self.assertFalse('}}' in file_string)
92
93 with open(os.path.join(dirname, antibody.STATS_NAME), 'r') as f:
94 file_string = f.read()
95 self.assertTrue(file_string)
96 self.assertFalse('{{' in file_string)
97 self.assertFalse('}}' in file_string)
98
99 with open(os.path.join(dirname, antibody.LEADERBOARD_NAME), 'r') as f:
100 file_string = f.read()
101 self.assertTrue(file_string)
102 self.assertFalse('{{' in file_string)
103 self.assertFalse('}}' in file_string)
67 104
68 self.assertTrue(os.path.exists(os.path.join(dirname, 'static'))) 105 self.assertTrue(os.path.exists(os.path.join(dirname, 'static')))
69 106
70 def test_get_tbr_by_user(self): 107 def test_get_tbr_by_user(self):
71 with infra_libs.temporary_directory(prefix='antibody-test') as dirname: 108 with infra_libs.temporary_directory(prefix='antibody-test') as dirname:
72 # tbr_no_lgtm: review_url, request_timestamp, hash, people_email_address 109 # tbr_no_lgtm: review_url, request_timestamp, subject,
110 # people_email_address, hash
73 tbr_no_lgtm = ( 111 tbr_no_lgtm = (
74 ('https://codereview.chromium.org/1175993003', 112 ('hello', '2015-07-13 11:11:11', 'pgervais@chromium.org',
75 datetime.datetime(2015, 7, 13, 11, 11, 11), 113 'git_hash_1', 'https://codereview.chromium.org/1175993003'),
76 'git_hash_1', 'pgervais@chromium.org'), 114 ('hello', '2015-07-13 11:11:11', 'hinoka@chromium.org',
77 ('https://codereview.chromium.org/1175993003', 115 'git_hash_1', 'https://codereview.chromium.org/1175993003'),
78 datetime.datetime(2015, 7, 13, 11, 11, 11), 116 ('world', '2015-07-13 22:22:22', 'hinoka@chromium.org',
79 'git_hash_1', 'hinoka@chromium.org'), 117 'git_hash_2', 'https://codereview.chromium.org/1171763002'),
80 ('https://codereview.chromium.org/1171763002', 118 ('world', '2015-07-13 22:22:22', 'keelerh@google.com',
81 datetime.datetime(2015, 7, 13, 22, 22, 22), 119 'git_hash_2', 'https://codereview.chromium.org/1171763002'),
82 'git_hash_2', 'hinoka@google.com'),
83 ('https://codereview.chromium.org/1171763002',
84 datetime.datetime(2015, 7, 13, 22, 22, 22),
85 'git_hash_2', 'keelerh@google.com'),
86 ) 120 )
87 antibody.get_tbr_by_user(tbr_no_lgtm, 121 antibody.get_tbr_by_user(tbr_no_lgtm,
88 'https://chromium.googlesource.com/infra/infra/+/', dirname) 122 'https://chromium.googlesource.com/infra/infra/+/', dirname)
89 expected_out = { 123 expected_out = {
90 "by_user" : { 124 "by_user" : {
91 "pgervais" : [['git_hash_1', 125 "pgervais" : [['git_hash_1',
92 'https://codereview.chromium.org/1175993003', 126 'https://codereview.chromium.org/1175993003',
93 '2015-07-13 11:11:11']], 127 '2015-07-13 11:11:11']],
94 "hinoka" : [['git_hash_1', 128 "hinoka" : [['git_hash_1',
95 'https://codereview.chromium.org/1175993003', 129 'https://codereview.chromium.org/1175993003',
(...skipping 24 matching lines...) Expand all
120 ]) 154 ])
121 self.assertEqual(antibody.get_gitiles_prefix(dirname), 155 self.assertEqual(antibody.get_gitiles_prefix(dirname),
122 'https://chromium.googlesource.com/infra/infra/+/') 156 'https://chromium.googlesource.com/infra/infra/+/')
123 157
124 with open(os.path.join(dirname, 'codereview.settings'), 'w') as f: 158 with open(os.path.join(dirname, 'codereview.settings'), 'w') as f:
125 f.writelines([ 159 f.writelines([
126 'CC_LIST: chromium-reviews@chromium.org\n', 160 'CC_LIST: chromium-reviews@chromium.org\n',
127 'PROJECT: infra\n', 161 'PROJECT: infra\n',
128 ]) 162 ])
129 self.assertEqual(antibody.get_gitiles_prefix(dirname), None) 163 self.assertEqual(antibody.get_gitiles_prefix(dirname), None)
OLDNEW
« no previous file with comments | « infra/tools/antibody/templates/tbr_by_user.jinja ('k') | infra/tools/antibody/test/compute_stats_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698