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

Side by Side Diff: tools/telemetry/telemetry/results/base_test_results_unittest.py

Issue 332513002: Add unittest for gtest_test_results. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 6 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
(Empty)
1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4 import unittest
5 import sys
6
7
8 class TestOutputStream(object):
9 def __init__(self):
10 self.output_data = []
11
12 def write(self, data):
13 assert isinstance(data, str)
14 self.output_data.append(data)
15
16 class BaseTestResultsUnittest(unittest.TestCase):
17
18 def CreateException(self):
tonyg 2014/06/11 23:08:51 I know you're just moving this. But while you're h
nednguyen 2014/06/11 23:30:36 Done.
19 try:
20 raise Exception('Intentional exception')
21 except Exception:
22 return sys.exc_info()
23
24 def assertEquals(self, ex, res):
25 # This helps diagnose result mismatches.
26 if ex != res and isinstance(ex, list):
27 def CleanList(l):
28 res = []
29 for x in l:
30 x = x.split('\n')
31 res.extend(x)
32 return res
33 ex = CleanList(ex)
34 res = CleanList(res)
35 max_len = max(len(ex), len(res))
36 max_width = max([len(x) for x in ex + res])
37 max_width = max(10, max_width)
38 print 'Lists differ!'
39 print '%*s | %*s' % (max_width, 'expected', max_width, 'result')
40 for i in range(max_len):
41 if i < len(ex):
42 e = ex[i]
43 else:
44 e = ''
45 if i < len(res):
46 r = res[i]
47 else:
48 r = ''
49 if e != r:
50 sep = '*'
51 else:
52 sep = '|'
53 print '%*s %s %*s' % (max_width, e, sep, max_width, r)
54 print ''
55 if ex != res and isinstance(ex, str) and isinstance(res, str):
56 print 'Strings differ!'
57 print 'exepected:\n%s' % repr(ex)
58 print 'result:\n%s\n' % repr(res)
59 super(BaseTestResultsUnittest, self).assertEquals(ex, res)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698