1 # SPDX-License-Identifier: GPL-2.0+
2 # Copyright (c) 2016 Google, Inc
3 # Written by Simon Glass <sjg@chromium.org>
5 # Test for the Entry class
17 class TestEntry(unittest.TestCase):
19 tools.PrepareOutputDir(None)
22 tools.FinaliseOutputDir()
25 binman_dir = os.path.dirname(os.path.realpath(sys.argv[0]))
26 fname = fdt_util.EnsureCompiled(
27 os.path.join(binman_dir,('test/005_simple.dts')))
28 dtb = fdt.FdtScan(fname)
29 return dtb.GetNode('/binman/u-boot')
31 def _ReloadEntry(self):
34 if sys.version_info[0] >= 3:
36 importlib.reload(entry)
42 def test1EntryNoImportLib(self):
43 """Test that we can import Entry subclassess successfully"""
44 sys.modules['importlib'] = None
47 entry.Entry.Create(None, self.GetNode(), 'u-boot')
48 self.assertFalse(entry.have_importlib)
50 def test2EntryImportLib(self):
51 del sys.modules['importlib']
54 entry.Entry.Create(None, self.GetNode(), 'u-boot-spl')
55 self.assertTrue(entry.have_importlib)
57 def testEntryContents(self):
58 """Test the Entry bass class"""
60 base_entry = entry.Entry(None, None, None, read_node=False)
61 self.assertEqual(True, base_entry.ObtainContents())
63 def testUnknownEntry(self):
64 """Test that unknown entry types are detected"""
65 Node = collections.namedtuple('Node', ['name', 'path'])
66 node = Node('invalid-name', 'invalid-path')
67 with self.assertRaises(ValueError) as e:
68 entry.Entry.Create(None, node, node.name)
69 self.assertIn("Unknown entry type 'invalid-name' in node "
70 "'invalid-path'", str(e.exception))
72 def testUniqueName(self):
73 """Test Entry.GetUniqueName"""
74 Node = collections.namedtuple('Node', ['name', 'parent'])
75 base_node = Node('root', None)
76 base_entry = entry.Entry(None, None, base_node, read_node=False)
77 self.assertEqual('root', base_entry.GetUniqueName())
78 sub_node = Node('subnode', base_node)
79 sub_entry = entry.Entry(None, None, sub_node, read_node=False)
80 self.assertEqual('root.subnode', sub_entry.GetUniqueName())
82 def testGetDefaultFilename(self):
83 """Trivial test for this base class function"""
84 base_entry = entry.Entry(None, None, None, read_node=False)
85 self.assertIsNone(base_entry.GetDefaultFilename())
87 if __name__ == "__main__":