|
| 1 | +#!/usr/bin/python |
| 2 | +# This program is free software; you can redistribute it and/or modify |
| 3 | +# it under the terms of the GNU General Public License as published by |
| 4 | +# the Free Software Foundation; either version 2 of the License, or |
| 5 | +# (at your option) any later version. |
| 6 | +# |
| 7 | +# This program is distributed in the hope that it will be useful, |
| 8 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | +# GNU Library General Public License for more details. |
| 11 | +# |
| 12 | +# You should have received a copy of the GNU General Public License |
| 13 | +# along with this program; if not, write to the Free Software |
| 14 | +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 15 | +# |
| 16 | +# controller_test.py |
| 17 | +# Copyright (C) 2017 Peter Newman |
| 18 | + |
| 19 | +import unittest |
| 20 | + |
| 21 | +class TestControllerData(unittest.TestCase): |
| 22 | + """ Test the controller data files are valid.""" |
| 23 | + def setUp(self): |
| 24 | + globals = {} |
| 25 | + locals = {} |
| 26 | + execfile("data/controller_data.py", globals, locals) |
| 27 | + self.data = locals['CONTROLLER_DATA'] |
| 28 | + |
| 29 | + def test_ControllerData(self): |
| 30 | + # Check the type |
| 31 | + self.assertEqual(type(self.data), dict) |
| 32 | + |
| 33 | + for esta_id in self.data: |
| 34 | + self.assertEqual(int, type(esta_id)) |
| 35 | + self.assertEqual(list, type(self.data[esta_id])) |
| 36 | + |
| 37 | + seen_names = set() |
| 38 | + |
| 39 | + for controller in self.data[esta_id]: |
| 40 | + name = controller['name'] |
| 41 | + self.assertNotIn(name, seen_names, |
| 42 | + "Name %s for ESTA ID 0x%04x is present twice" % (name, esta_id)) |
| 43 | + seen_names.add(name) |
| 44 | + |
| 45 | + |
| 46 | +if __name__ == '__main__': |
| 47 | + unittest.main() |
0 commit comments