Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / third_party / pigweed / repo / pw_presubmit / py / presubmit_test.py
1 #!/usr/bin/env python3
2 # Copyright 2020 The Pigweed Authors
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 # use this file except in compliance with the License. You may obtain a copy of
6 # the License at
7 #
8 #     https://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 # License for the specific language governing permissions and limitations under
14 # the License.
15 """Tests for presubmit tools."""
16
17 import unittest
18
19 from pw_presubmit import presubmit
20
21
22 def _fake_function_1(_):
23     """Fake presubmit function."""
24
25
26 def _fake_function_2(_):
27     """Fake presubmit function."""
28
29
30 class ProgramsTest(unittest.TestCase):
31     """Tests the presubmit Programs abstraction."""
32     def setUp(self):
33         self._programs = presubmit.Programs(
34             first=[_fake_function_1, (), [(_fake_function_1, )]],
35             second=[_fake_function_2],
36         )
37
38     def test_empty(self):
39         self.assertEqual({}, presubmit.Programs())
40
41     def test_access_present_members(self):
42         self.assertEqual('first', self._programs['first'].name)
43         self.assertEqual((_fake_function_1, _fake_function_1),
44                          tuple(self._programs['first']))
45
46         self.assertEqual('second', self._programs['second'].name)
47         self.assertEqual((_fake_function_2, ), tuple(self._programs['second']))
48
49     def test_access_missing_member(self):
50         with self.assertRaises(KeyError):
51             _ = self._programs['not_there']
52
53     def test_all_steps(self):
54         self.assertEqual(
55             {
56                 '_fake_function_1': _fake_function_1,
57                 '_fake_function_2': _fake_function_2,
58             }, self._programs.all_steps())
59
60
61 if __name__ == '__main__':
62     unittest.main()