mirror of
https://xff.cz/git/u-boot/
synced 2025-09-02 09:12:08 +02:00
binman: Simplify the entry test
The current test for the 'entry' module is a bit convoluted since it has to import the module multiple times. It also relies on ordering, in that test1EntryNoImportLib() must run before test2EntryImportLib() if they are running in the same Python process. This is unreliable since neither the ordering of tests nor the process that they run in is defined. Fix this by always reloading the entry in these two tests. Also add a check that the expected value of have_importlib is obtained. This corrects a code-coverage problem in the 'entry' module on some systems. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
@@ -9,12 +9,11 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
|
import entry
|
||||||
import fdt
|
import fdt
|
||||||
import fdt_util
|
import fdt_util
|
||||||
import tools
|
import tools
|
||||||
|
|
||||||
entry = None
|
|
||||||
|
|
||||||
class TestEntry(unittest.TestCase):
|
class TestEntry(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
tools.PrepareOutputDir(None)
|
tools.PrepareOutputDir(None)
|
||||||
@@ -29,16 +28,7 @@ class TestEntry(unittest.TestCase):
|
|||||||
dtb = fdt.FdtScan(fname)
|
dtb = fdt.FdtScan(fname)
|
||||||
return dtb.GetNode('/binman/u-boot')
|
return dtb.GetNode('/binman/u-boot')
|
||||||
|
|
||||||
def test1EntryNoImportLib(self):
|
def _ReloadEntry(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
|
global entry
|
||||||
if entry:
|
if entry:
|
||||||
if sys.version_info[0] >= 3:
|
if sys.version_info[0] >= 3:
|
||||||
@@ -48,8 +38,21 @@ class TestEntry(unittest.TestCase):
|
|||||||
reload(entry)
|
reload(entry)
|
||||||
else:
|
else:
|
||||||
import entry
|
import entry
|
||||||
|
|
||||||
|
def test1EntryNoImportLib(self):
|
||||||
|
"""Test that we can import Entry subclassess successfully"""
|
||||||
|
sys.modules['importlib'] = None
|
||||||
|
global entry
|
||||||
|
self._ReloadEntry()
|
||||||
|
entry.Entry.Create(None, self.GetNode(), 'u-boot')
|
||||||
|
self.assertFalse(entry.have_importlib)
|
||||||
|
|
||||||
|
def test2EntryImportLib(self):
|
||||||
|
del sys.modules['importlib']
|
||||||
|
global entry
|
||||||
|
self._ReloadEntry()
|
||||||
entry.Entry.Create(None, self.GetNode(), 'u-boot-spl')
|
entry.Entry.Create(None, self.GetNode(), 'u-boot-spl')
|
||||||
del entry
|
self.assertTrue(entry.have_importlib)
|
||||||
|
|
||||||
def testEntryContents(self):
|
def testEntryContents(self):
|
||||||
"""Test the Entry bass class"""
|
"""Test the Entry bass class"""
|
||||||
@@ -59,7 +62,6 @@ class TestEntry(unittest.TestCase):
|
|||||||
|
|
||||||
def testUnknownEntry(self):
|
def testUnknownEntry(self):
|
||||||
"""Test that unknown entry types are detected"""
|
"""Test that unknown entry types are detected"""
|
||||||
import entry
|
|
||||||
Node = collections.namedtuple('Node', ['name', 'path'])
|
Node = collections.namedtuple('Node', ['name', 'path'])
|
||||||
node = Node('invalid-name', 'invalid-path')
|
node = Node('invalid-name', 'invalid-path')
|
||||||
with self.assertRaises(ValueError) as e:
|
with self.assertRaises(ValueError) as e:
|
||||||
@@ -69,7 +71,6 @@ class TestEntry(unittest.TestCase):
|
|||||||
|
|
||||||
def testUniqueName(self):
|
def testUniqueName(self):
|
||||||
"""Test Entry.GetUniqueName"""
|
"""Test Entry.GetUniqueName"""
|
||||||
import entry
|
|
||||||
Node = collections.namedtuple('Node', ['name', 'parent'])
|
Node = collections.namedtuple('Node', ['name', 'parent'])
|
||||||
base_node = Node('root', None)
|
base_node = Node('root', None)
|
||||||
base_entry = entry.Entry(None, None, base_node, read_node=False)
|
base_entry = entry.Entry(None, None, base_node, read_node=False)
|
||||||
@@ -80,7 +81,6 @@ class TestEntry(unittest.TestCase):
|
|||||||
|
|
||||||
def testGetDefaultFilename(self):
|
def testGetDefaultFilename(self):
|
||||||
"""Trivial test for this base class function"""
|
"""Trivial test for this base class function"""
|
||||||
import entry
|
|
||||||
base_entry = entry.Entry(None, None, None, read_node=False)
|
base_entry = entry.Entry(None, None, None, read_node=False)
|
||||||
self.assertIsNone(base_entry.GetDefaultFilename())
|
self.assertIsNone(base_entry.GetDefaultFilename())
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user