2 # Copyright 2020 The Pigweed Authors
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
8 # https://www.apache.org/licenses/LICENSE-2.0
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
15 """Tests for presubmit tools."""
19 from pw_presubmit import presubmit
22 def _fake_function_1(_):
23 """Fake presubmit function."""
26 def _fake_function_2(_):
27 """Fake presubmit function."""
30 class ProgramsTest(unittest.TestCase):
31 """Tests the presubmit Programs abstraction."""
33 self._programs = presubmit.Programs(
34 first=[_fake_function_1, (), [(_fake_function_1, )]],
35 second=[_fake_function_2],
39 self.assertEqual({}, presubmit.Programs())
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']))
46 self.assertEqual('second', self._programs['second'].name)
47 self.assertEqual((_fake_function_2, ), tuple(self._programs['second']))
49 def test_access_missing_member(self):
50 with self.assertRaises(KeyError):
51 _ = self._programs['not_there']
53 def test_all_steps(self):
56 '_fake_function_1': _fake_function_1,
57 '_fake_function_2': _fake_function_2,
58 }, self._programs.all_steps())
61 if __name__ == '__main__':