Show More
@@ -0,0 +1,10 b'' | |||||
|
1 | from test_pr import load_results, post_logs, post_results_comment, print_results | |||
|
2 | ||||
|
3 | num, results, pr = load_results() | |||
|
4 | results_urls = post_logs(results) | |||
|
5 | print_results(pr, results_urls) | |||
|
6 | post_results_comment(pr, results_urls, num) | |||
|
7 | ||||
|
8 | print() | |||
|
9 | print("Posted test results to pull request") | |||
|
10 | print(" " + pr['html_url']) |
@@ -13,6 +13,7 b' from glob import glob' | |||||
13 | import io |
|
13 | import io | |
14 | import json |
|
14 | import json | |
15 | import os |
|
15 | import os | |
|
16 | import pickle | |||
16 | import re |
|
17 | import re | |
17 | import requests |
|
18 | import requests | |
18 | import shutil |
|
19 | import shutil | |
@@ -106,7 +107,7 b' def run_tests(venv):' | |||||
106 | except CalledProcessError as e: |
|
107 | except CalledProcessError as e: | |
107 | return False, e.output.decode('utf-8') |
|
108 | return False, e.output.decode('utf-8') | |
108 |
|
109 | |||
109 | def markdown_format(pr, results): |
|
110 | def markdown_format(pr, results_urls): | |
110 | def format_result(py, passed, gist_url, missing_libraries): |
|
111 | def format_result(py, passed, gist_url, missing_libraries): | |
111 | s = "* %s: " % py |
|
112 | s = "* %s: " % py | |
112 | if passed: |
|
113 | if passed: | |
@@ -124,7 +125,7 b' def markdown_format(pr, results):' | |||||
124 | lines = ["**Test results for commit %s**" % com, |
|
125 | lines = ["**Test results for commit %s**" % com, | |
125 | "Platform: " + sys.platform, |
|
126 | "Platform: " + sys.platform, | |
126 | ""] + \ |
|
127 | ""] + \ | |
127 | [format_result(*r) for r in results] + \ |
|
128 | [format_result(*r) for r in results_urls] + \ | |
128 | ["", |
|
129 | ["", | |
129 | "Not available for testing: " + ", ".join(unavailable_pythons)] |
|
130 | "Not available for testing: " + ", ".join(unavailable_pythons)] | |
130 | return "\n".join(lines) |
|
131 | return "\n".join(lines) | |
@@ -133,14 +134,14 b' def post_results_comment(pr, results, num):' | |||||
133 | body = markdown_format(pr, results) |
|
134 | body = markdown_format(pr, results) | |
134 | gh_api.post_issue_comment(gh_project, num, body) |
|
135 | gh_api.post_issue_comment(gh_project, num, body) | |
135 |
|
136 | |||
136 | def print_results(pr, results): |
|
137 | def print_results(pr, results_urls): | |
137 | print("\n") |
|
138 | print("\n") | |
138 | if pr['mergeable']: |
|
139 | if pr['mergeable']: | |
139 | print("**Test results for commit %s merged into master**" % pr['head']['sha'][:7]) |
|
140 | print("**Test results for commit %s merged into master**" % pr['head']['sha'][:7]) | |
140 | else: |
|
141 | else: | |
141 | print("**Test results for commit %s (can't merge cleanly)**" % pr['head']['sha'][:7]) |
|
142 | print("**Test results for commit %s (can't merge cleanly)**" % pr['head']['sha'][:7]) | |
142 | print("Platform:", sys.platform) |
|
143 | print("Platform:", sys.platform) | |
143 | for py, passed, gist_url, missing_libraries in results: |
|
144 | for py, passed, gist_url, missing_libraries in results_urls: | |
144 | if passed: |
|
145 | if passed: | |
145 | print(py, ":", "OK") |
|
146 | print(py, ":", "OK") | |
146 | else: |
|
147 | else: | |
@@ -150,6 +151,42 b' def print_results(pr, results):' | |||||
150 | print(" Libraries not available:", missing_libraries) |
|
151 | print(" Libraries not available:", missing_libraries) | |
151 | print("Not available for testing:", ", ".join(unavailable_pythons)) |
|
152 | print("Not available for testing:", ", ".join(unavailable_pythons)) | |
152 |
|
153 | |||
|
154 | def dump_results(num, results, pr): | |||
|
155 | with open(os.path.join(basedir, 'lastresults.pkl'), 'wb') as f: | |||
|
156 | pickle.dump((num, results, pr), f) | |||
|
157 | ||||
|
158 | def load_results(): | |||
|
159 | with open(os.path.join(basedir, 'lastresults.pkl'), 'rb') as f: | |||
|
160 | return pickle.load(f) | |||
|
161 | ||||
|
162 | def save_logs(results, pr): | |||
|
163 | results_paths = [] | |||
|
164 | for py, passed, log, missing_libraries in results: | |||
|
165 | if passed: | |||
|
166 | results_paths.append((py, passed, None, missing_libraries)) | |||
|
167 | else: | |||
|
168 | ||||
|
169 | result_locn = os.path.abspath(os.path.join('venv-%s' % py, | |||
|
170 | pr['head']['sha'][:7]+".log")) | |||
|
171 | with io.open(result_locn, 'w', encoding='utf-8') as f: | |||
|
172 | f.write(log) | |||
|
173 | ||||
|
174 | results_paths.append((py, False, result_locn, missing_libraries)) | |||
|
175 | ||||
|
176 | return results_paths | |||
|
177 | ||||
|
178 | def post_logs(results): | |||
|
179 | results_urls = [] | |||
|
180 | for py, passed, log, missing_libraries in results: | |||
|
181 | if passed: | |||
|
182 | results_urls.append((py, passed, None, missing_libraries)) | |||
|
183 | else: | |||
|
184 | result_locn = gh_api.post_gist(log, description='IPython test log', | |||
|
185 | filename="results.log", auth=True) | |||
|
186 | results_urls.append((py, False, result_locn, missing_libraries)) | |||
|
187 | ||||
|
188 | return results_urls | |||
|
189 | ||||
153 | def test_pr(num, post_results=True): |
|
190 | def test_pr(num, post_results=True): | |
154 | # Get Github authorisation first, so that the user is prompted straight away |
|
191 | # Get Github authorisation first, so that the user is prompted straight away | |
155 | # if their login is needed. |
|
192 | # if their login is needed. | |
@@ -171,28 +208,28 b' def test_pr(num, post_results=True):' | |||||
171 | if passed: |
|
208 | if passed: | |
172 | results.append((py, True, None, missing_libraries)) |
|
209 | results.append((py, True, None, missing_libraries)) | |
173 | else: |
|
210 | else: | |
174 | if post_results: |
|
211 | results.append((py, False, log, missing_libraries)) | |
175 | result_locn = gh_api.post_gist(log, description='IPython test log', |
|
212 | ||
176 | filename="results.log", auth=True) |
|
213 | dump_results(num, results, pr) | |
177 | else: |
|
214 | ||
178 | result_locn = os.path.abspath(os.path.join(venv, |
|
215 | results_paths = save_logs(results, pr) | |
179 | pr['head']['sha'][:7]+".log")) |
|
216 | print_results(pr, results_paths) | |
180 | with io.open(result_locn, 'w', encoding='utf-8') as f: |
|
|||
181 | f.write(log) |
|
|||
182 | results.append((py, False, result_locn, missing_libraries)) |
|
|||
183 |
|
217 | |||
184 | print_results(pr, results) |
|
|||
185 | if post_results: |
|
218 | if post_results: | |
186 |
|
|
219 | results_urls = post_logs(results) | |
|
220 | post_results_comment(pr, results_urls, num) | |||
187 | print("(Posted to Github)") |
|
221 | print("(Posted to Github)") | |
|
222 | else: | |||
|
223 | post_script = os.path.join(os.path.dirname(sys.argv[0]), "post_pr_test.py") | |||
|
224 | print("To post the results to Github, run", post_script) | |||
188 |
|
225 | |||
189 |
|
226 | |||
190 | if __name__ == '__main__': |
|
227 | if __name__ == '__main__': | |
191 | import argparse |
|
228 | import argparse | |
192 | parser = argparse.ArgumentParser(description="Test an IPython pull request") |
|
229 | parser = argparse.ArgumentParser(description="Test an IPython pull request") | |
193 |
parser.add_argument('- |
|
230 | parser.add_argument('-p', '--publish', action='store_true', | |
194 |
help=" |
|
231 | help="Publish the results to Github") | |
195 | parser.add_argument('number', type=int, help="The pull request number") |
|
232 | parser.add_argument('number', type=int, help="The pull request number") | |
196 |
|
233 | |||
197 | args = parser.parse_args() |
|
234 | args = parser.parse_args() | |
198 |
test_pr(args.number, post_results= |
|
235 | test_pr(args.number, post_results=args.publish) |
General Comments 0
You need to be logged in to leave comments.
Login now