image_test.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # SPDX-License-Identifier: GPL-2.0+
  2. # Copyright (c) 2017 Google, Inc
  3. # Written by Simon Glass <sjg@chromium.org>
  4. #
  5. # Test for the image module
  6. import unittest
  7. from image import Image
  8. from test_util import capture_sys_output
  9. class TestImage(unittest.TestCase):
  10. def testInvalidFormat(self):
  11. image = Image('name', 'node', test=True)
  12. section = image._section
  13. with self.assertRaises(ValueError) as e:
  14. section.LookupSymbol('_binman_something_prop_', False, 'msg')
  15. self.assertIn(
  16. "msg: Symbol '_binman_something_prop_' has invalid format",
  17. str(e.exception))
  18. def testMissingSymbol(self):
  19. image = Image('name', 'node', test=True)
  20. section = image._section
  21. section._entries = {}
  22. with self.assertRaises(ValueError) as e:
  23. section.LookupSymbol('_binman_type_prop_pname', False, 'msg')
  24. self.assertIn("msg: Entry 'type' not found in list ()",
  25. str(e.exception))
  26. def testMissingSymbolOptional(self):
  27. image = Image('name', 'node', test=True)
  28. section = image._section
  29. section._entries = {}
  30. with capture_sys_output() as (stdout, stderr):
  31. val = section.LookupSymbol('_binman_type_prop_pname', True, 'msg')
  32. self.assertEqual(val, None)
  33. self.assertEqual("Warning: msg: Entry 'type' not found in list ()\n",
  34. stderr.getvalue())
  35. self.assertEqual('', stdout.getvalue())
  36. def testBadProperty(self):
  37. image = Image('name', 'node', test=True)
  38. section = image._section
  39. section._entries = {'u-boot': 1}
  40. with self.assertRaises(ValueError) as e:
  41. section.LookupSymbol('_binman_u_boot_prop_bad', False, 'msg')
  42. self.assertIn("msg: No such property 'bad", str(e.exception))