binman: Add tests for importlib availability
authorSimon Glass <sjg@chromium.org>
Mon, 13 Nov 2017 04:52:21 +0000 (21:52 -0700)
committerSimon Glass <sjg@chromium.org>
Thu, 23 Nov 2017 01:05:38 +0000 (18:05 -0700)
Add a test that the 'entry' module works with or without importlib.
The tests are numbered so that they are executed in the correct order.

Signed-off-by: Simon Glass <sjg@chromium.org>
tools/binman/binman.py
tools/binman/entry_test.py

index 963d43a3761a6953a5116d7e6a1afd4919199550..cf83edfd04446eed50da7c57469ddc7e84e742f6 100755 (executable)
@@ -44,8 +44,12 @@ def RunTests():
         suite.run(result)
 
     sys.argv = [sys.argv[0]]
-    for module in (ftest.TestFunctional, fdt_test.TestFdt,
-                   entry_test.TestEntry):
+
+    # Run the entry tests first ,since these need to be the first to import the
+    # 'entry' module.
+    suite = unittest.TestLoader().loadTestsFromTestCase(entry_test.TestEntry)
+    suite.run(result)
+    for module in (ftest.TestFunctional, fdt_test.TestFdt):
         suite = unittest.TestLoader().loadTestsFromTestCase(module)
         suite.run(result)
 
index 85c4196892fc948b236210c45f0321d048b40043..789b26fd9f55c37e6f33489a2eb306adafae957b 100644 (file)
@@ -7,9 +7,39 @@
 # Test for the Entry class
 
 import collections
+import os
+import sys
 import unittest
 
+import fdt
+import fdt_util
+import tools
+
 class TestEntry(unittest.TestCase):
+    def GetNode(self):
+        binman_dir = os.path.dirname(os.path.realpath(sys.argv[0]))
+        tools.PrepareOutputDir(None)
+        fname = fdt_util.EnsureCompiled(
+            os.path.join(binman_dir,('test/05_simple.dts')))
+        dtb = fdt.FdtScan(fname)
+        return dtb.GetNode('/binman/u-boot')
+
+    def test1EntryNoImportLib(self):
+        """Test that we can import Entry subclassess successfully"""
+
+        sys.modules['importlib'] = None
+        global entry
+        import entry
+        entry.Entry.Create(None, self.GetNode(), 'u-boot')
+
+    def test2EntryImportLib(self):
+        del sys.modules['importlib']
+        global entry
+        reload(entry)
+        entry.Entry.Create(None, self.GetNode(), 'u-boot-spl')
+        tools._RemoveOutputDir()
+        del entry
+
     def testEntryContents(self):
         """Test the Entry bass class"""
         import entry