1# 2# Copyright (c) 2016 Google, Inc 3# Written by Simon Glass <sjg@chromium.org> 4# 5# SPDX-License-Identifier: GPL-2.0+ 6# 7# Test for the Entry class 8 9import collections 10import os 11import sys 12import unittest 13 14import fdt 15import fdt_util 16import tools 17 18class TestEntry(unittest.TestCase): 19 def GetNode(self): 20 binman_dir = os.path.dirname(os.path.realpath(sys.argv[0])) 21 tools.PrepareOutputDir(None) 22 fname = fdt_util.EnsureCompiled( 23 os.path.join(binman_dir,('test/05_simple.dts'))) 24 dtb = fdt.FdtScan(fname) 25 return dtb.GetNode('/binman/u-boot') 26 27 def test1EntryNoImportLib(self): 28 """Test that we can import Entry subclassess successfully""" 29 30 sys.modules['importlib'] = None 31 global entry 32 import entry 33 entry.Entry.Create(None, self.GetNode(), 'u-boot') 34 35 def test2EntryImportLib(self): 36 del sys.modules['importlib'] 37 global entry 38 reload(entry) 39 entry.Entry.Create(None, self.GetNode(), 'u-boot-spl') 40 tools._RemoveOutputDir() 41 del entry 42 43 def testEntryContents(self): 44 """Test the Entry bass class""" 45 import entry 46 base_entry = entry.Entry(None, None, None, read_node=False) 47 self.assertEqual(True, base_entry.ObtainContents()) 48 49 def testUnknownEntry(self): 50 """Test that unknown entry types are detected""" 51 import entry 52 Node = collections.namedtuple('Node', ['name', 'path']) 53 node = Node('invalid-name', 'invalid-path') 54 with self.assertRaises(ValueError) as e: 55 entry.Entry.Create(None, node, node.name) 56 self.assertIn("Unknown entry type 'invalid-name' in node " 57 "'invalid-path'", str(e.exception)) 58 59 60if __name__ == "__main__": 61 unittest.main() 62