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

Side by Side Diff: recipe_engine/unittests/checker_test.py

Issue 2387763003: Add initial postprocess unit test thingy. (Closed)
Patch Set: Implement partial checker_test, rewrite VerifySubset Created 4 years, 2 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 #!/usr/bin/env python
2 # Copyright 2016 The LUCI Authors. All rights reserved.
3 # Use of this source code is governed under the Apache License, Version 2.0
4 # that can be found in the LICENSE file.
5
6 import json
7 import os
8 import subprocess
9 import sys
10 import unittest
11 import copy
12
13 from collections import OrderedDict
14
15 import test_env
16 import mock
17
18 from recipe_engine import checker
19
20 class TestChecker(unittest.TestCase):
21 pass
22
23
24 class TestVerifySubset(unittest.TestCase):
25 @staticmethod
26 def mkData(*steps):
27 return OrderedDict([
28 (s, {
29 'cmd': ['list', 'of', 'things'],
30 'env': {
31 'dict': 'of',
32 'many': 'strings,'
33 },
34 'name': s,
35 'status_code': 1,
36 }) for s in steps
37 ])
38
39 def setUp(self):
40 self.v = checker.VerifySubset
41 self.d = self.mkData('a', 'b', 'c')
42 self.c = copy.deepcopy(self.d)
43
44 def test_types(self):
45 self.assertIn(
46 "type mismatch: 'str' v 'OrderedDict'",
47 self.v('hi', self.d))
48
49 self.assertIn(
50 "type mismatch: 'list' v 'OrderedDict'",
51 self.v(['hi'], self.d))
52
53 def test_empty(self):
54 self.assertIsNone(self.v({}, self.d))
55 self.assertIsNone(self.v(OrderedDict(), self.d))
56
57 def test_single_removal(self):
58 del self.c['c']
59 self.assertIsNone(self.v(self.c, self.d))
60
61 def test_add(self):
62 self.c['d'] = self.c['a']
63 self.assertIn(
64 "added key 'd'",
65 self.v(self.c, self.d))
66
67 def test_add_key(self):
68 self.c['c']['blort'] = 'cake'
69 self.assertIn(
70 "added key 'blort'",
71 self.v(self.c, self.d))
72
73 def test_key_alter(self):
74 self.c['c']['cmd'] = 'cake'
75 self.assertEqual(
76 "['c']['cmd']: type mismatch: 'str' v 'list'",
77 self.v(self.c, self.d))
78
79 def test_list_add(self):
80 self.c['c']['cmd'].append('something')
81 self.assertIn(
82 "['c']['cmd']: too long: 4 v 3",
83 self.v(self.c, self.d))
84
85 self.c['c']['cmd'].pop(0)
86 self.assertIn(
87 "['c']['cmd']: added 1 elements",
88 self.v(self.c, self.d))
89
90
91 if __name__ == '__main__':
92 sys.exit(unittest.main())
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698