| Index: recipe_engine/unittests/checker_test.py
|
| diff --git a/recipe_engine/unittests/checker_test.py b/recipe_engine/unittests/checker_test.py
|
| new file mode 100755
|
| index 0000000000000000000000000000000000000000..ead50906a18f1277c56d23e2b4261b3225c8fb3a
|
| --- /dev/null
|
| +++ b/recipe_engine/unittests/checker_test.py
|
| @@ -0,0 +1,92 @@
|
| +#!/usr/bin/env python
|
| +# Copyright 2016 The LUCI Authors. All rights reserved.
|
| +# Use of this source code is governed under the Apache License, Version 2.0
|
| +# that can be found in the LICENSE file.
|
| +
|
| +import json
|
| +import os
|
| +import subprocess
|
| +import sys
|
| +import unittest
|
| +import copy
|
| +
|
| +from collections import OrderedDict
|
| +
|
| +import test_env
|
| +import mock
|
| +
|
| +from recipe_engine import checker
|
| +
|
| +class TestChecker(unittest.TestCase):
|
| + pass
|
| +
|
| +
|
| +class TestVerifySubset(unittest.TestCase):
|
| + @staticmethod
|
| + def mkData(*steps):
|
| + return OrderedDict([
|
| + (s, {
|
| + 'cmd': ['list', 'of', 'things'],
|
| + 'env': {
|
| + 'dict': 'of',
|
| + 'many': 'strings,'
|
| + },
|
| + 'name': s,
|
| + 'status_code': 1,
|
| + }) for s in steps
|
| + ])
|
| +
|
| + def setUp(self):
|
| + self.v = checker.VerifySubset
|
| + self.d = self.mkData('a', 'b', 'c')
|
| + self.c = copy.deepcopy(self.d)
|
| +
|
| + def test_types(self):
|
| + self.assertIn(
|
| + "type mismatch: 'str' v 'OrderedDict'",
|
| + self.v('hi', self.d))
|
| +
|
| + self.assertIn(
|
| + "type mismatch: 'list' v 'OrderedDict'",
|
| + self.v(['hi'], self.d))
|
| +
|
| + def test_empty(self):
|
| + self.assertIsNone(self.v({}, self.d))
|
| + self.assertIsNone(self.v(OrderedDict(), self.d))
|
| +
|
| + def test_single_removal(self):
|
| + del self.c['c']
|
| + self.assertIsNone(self.v(self.c, self.d))
|
| +
|
| + def test_add(self):
|
| + self.c['d'] = self.c['a']
|
| + self.assertIn(
|
| + "added key 'd'",
|
| + self.v(self.c, self.d))
|
| +
|
| + def test_add_key(self):
|
| + self.c['c']['blort'] = 'cake'
|
| + self.assertIn(
|
| + "added key 'blort'",
|
| + self.v(self.c, self.d))
|
| +
|
| + def test_key_alter(self):
|
| + self.c['c']['cmd'] = 'cake'
|
| + self.assertEqual(
|
| + "['c']['cmd']: type mismatch: 'str' v 'list'",
|
| + self.v(self.c, self.d))
|
| +
|
| + def test_list_add(self):
|
| + self.c['c']['cmd'].append('something')
|
| + self.assertIn(
|
| + "['c']['cmd']: too long: 4 v 3",
|
| + self.v(self.c, self.d))
|
| +
|
| + self.c['c']['cmd'].pop(0)
|
| + self.assertIn(
|
| + "['c']['cmd']: added 1 elements",
|
| + self.v(self.c, self.d))
|
| +
|
| +
|
| +if __name__ == '__main__':
|
| + sys.exit(unittest.main())
|
|
|