image_test.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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 binman.image import Image
  8. from patman.test_util import capture_sys_output
  9. class TestImage(unittest.TestCase):
  10. def testInvalidFormat(self):
  11. image = Image('name', 'node', test=True)
  12. with self.assertRaises(ValueError) as e:
  13. image.LookupSymbol('_binman_something_prop_', False, 'msg', 0)
  14. self.assertIn(
  15. "msg: Symbol '_binman_something_prop_' has invalid format",
  16. str(e.exception))
  17. def testMissingSymbol(self):
  18. image = Image('name', 'node', test=True)
  19. image._entries = {}
  20. with self.assertRaises(ValueError) as e:
  21. image.LookupSymbol('_binman_type_prop_pname', False, 'msg', 0)
  22. self.assertIn("msg: Entry 'type' not found in list ()",
  23. str(e.exception))
  24. def testMissingSymbolOptional(self):
  25. image = Image('name', 'node', test=True)
  26. image._entries = {}
  27. with capture_sys_output() as (stdout, stderr):
  28. val = image.LookupSymbol('_binman_type_prop_pname', True, 'msg', 0)
  29. self.assertEqual(val, None)
  30. self.assertEqual("Warning: msg: Entry 'type' not found in list ()\n",
  31. stderr.getvalue())
  32. self.assertEqual('', stdout.getvalue())
  33. def testBadProperty(self):
  34. image = Image('name', 'node', test=True)
  35. image._entries = {'u-boot': 1}
  36. with self.assertRaises(ValueError) as e:
  37. image.LookupSymbol('_binman_u_boot_prop_bad', False, 'msg', 0)
  38. self.assertIn("msg: No such property 'bad", str(e.exception))