forked from kubernetes/test-infra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pull_request_test.py
64 lines (51 loc) · 2.58 KB
/
pull_request_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python
# Copyright 2016 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import unittest
import pull_request
def make(number, version, result, start_time=1000):
started = None if version is None else {
'timestamp': start_time, 'version': version}
finished = result and {'result': result}
return (number, started, finished)
def makePodutil(number, revision, result, start_time=1000):
started = {'timestamp': start_time}
finished = result and {'result': result, 'revision': revision}
return (number, started, finished)
class TableTest(unittest.TestCase):
def test_builds_to_table(self):
jobs = {'J1': [make(4, 'v2', 'A', 9), make(3, 'v2', 'B', 10)],
'J2': [make(5, 'v1', 'C', 7), make(4, 'v1', 'D', 6)]}
max_builds, headings, rows = pull_request.builds_to_table(jobs)
self.assertEqual(max_builds, 4)
self.assertEqual(headings, [('v2', 2, 9), ('v1', 2, 6)])
self.assertEqual(rows, [('J1', [(4, 'A'), (3, 'B')]),
('J2', [None, None, (5, 'C'), (4, 'D')])])
def test_builds_to_table_no_header(self):
jobs = {'J': [make(5, None, 'A', 3), make(4, '', 'B', 2)]}
self.assertEqual(pull_request.builds_to_table(jobs),
(0, [], [('J', [(5, 'A'), (4, 'B')])]))
def test_pull_ref_commit(self):
jobs = {'J1': [make(4, 'v2', 'A', 9)]}
jobs['J1'][0][1]['pull'] = 'master:1234,35:abcd'
_, headings, _ = pull_request.builds_to_table(jobs)
self.assertEqual(headings, [('abcd', 1, 9)])
def test_builds_to_table_podutils(self):
jobs = {'J1': [makePodutil(4, 'v2', 'A', 9), makePodutil(3, 'v2', 'B', 10)],
'J2': [makePodutil(5, 'v1', 'C', 7), makePodutil(4, 'v1', 'D', 6)]}
max_builds, headings, rows = pull_request.builds_to_table(jobs)
self.assertEqual(max_builds, 4)
self.assertEqual(headings, [('v2', 2, 9), ('v1', 2, 6)])
self.assertEqual(rows, [('J1', [(4, 'A'), (3, 'B')]),
('J2', [None, None, (5, 'C'), (4, 'D')])])