Fix creator tests
authorReto Buerki <reet@codelabs.ch>
Fri, 29 Sep 2017 14:02:19 +0000 (16:02 +0200)
committerReto Buerki <reet@codelabs.ch>
Fri, 29 Sep 2017 14:59:32 +0000 (16:59 +0200)
Delete unneeded variable declarations and assert empty lists. Also fix
assertion of filterDevicePaths.

test/test_creator.py

index fc40dd5..50d85c9 100644 (file)
 #   along with mugenhwcfg.  If not, see <http://www.gnu.org/licenses/>.
 
 import os
-from collections import namedtuple
 
 import testpaths
 import mock
 import pytest
 
-import paths
 import src.creator as creator
 import src.dmar as dmar
 import src.fadt as fadt
@@ -93,7 +91,6 @@ class TestProcessorCreator:
                                                   vmxTimerRate=5)
 
         VMX_OFFSET = 0x485
-        VMX_BITSIZE = 5
         with open(msr, "wb") as f:
             f.seek(VMX_OFFSET)
             f.write(b"\x05\x0e")
@@ -110,7 +107,6 @@ class TestProcessorCreator:
         dmesgloc2 = os.path.join(self.testdir, "dmesg_tsc_detected")
         dmesg_nokey = os.path.join(self.testdir, "dmesg_nokey")
         invalidloc = os.path.join(self.testdir, "invalidlocdmesg")
-        KEY = "Refined TSC clocksource calibration"
         assert self.procreator.getSpeed(dmesgloc) == 3192.746
         assert self.procreator.getSpeed(dmesgloc2) == 3192.667
         with pytest.raises(customExceptions.ForceQuit):
@@ -204,10 +200,12 @@ class TestMemoryCreator():
 
         # Test getMemoryBlocks
         memoryBlockList_invalid = self.memcreator.getMemoryBlocks(invalidloc)
+        assert not memoryBlockList_invalid
         memoryBlockList_incomplete = self.memcreator.getMemoryBlocks(
             incompleteloc)
-        memoryBlockList = self.memcreator.getMemoryBlocks(loc)
+        assert not memoryBlockList_incomplete
 
+        memoryBlockList = self.memcreator.getMemoryBlocks(loc)
         assert len(memoryBlockList) == 2
 
         memoryBlock0 = memoryBlockList[0]
@@ -279,7 +277,6 @@ class TestDevicesCreator:
         testinvalidloc = os.path.join(testdir, "testgetpciconfig_invalidloc")
         testnokey = os.path.join(testdir, "test_iomem_nopciconfig")
 
-        devcreator = creator.DevicesCreator()
         assert creator.getPciConfigAddress(testiomem) == "e0000000"
         assert not creator.getPciConfigAddress(testinvalidloc)
         assert not creator.getPciConfigAddress(testnokey)
@@ -325,10 +322,8 @@ class TestPciDevicesCreator:
         devicecapmgr = devicecap.DevicecapManager()
         devicecapmgr.extractCapabilities(devicepaths)
 
-        assert (len(self.pcicreator.filterDevicePaths(
-            devicepaths,
-            devicecapmgr)) == 8,
-            "filterDevicePaths not working")
+        assert len(self.pcicreator.filterDevicePaths(devicepaths,
+                                                     devicecapmgr)) == 2
 
     def test_isDeviceName(self):
         assert self.pcicreator.isDeviceName("0000:01:00.0") is True
@@ -591,9 +586,7 @@ class TestPciDevicesCreator:
         dev1_loc = os.path.join(testloc, "dev1")
         dev2_loc = os.path.join(testloc, "dev2")
         dev3_loc = os.path.join(testloc, "dev3")
-        dev_noresource = os.path.join(testloc, "dev_noresource")
         dev_emptyresource = os.path.join(testloc, "dev_emptyresource")
-        Irq = namedtuple("Irq", ["name", "number"])
         dev1_testirqs = [src.schemadata.schema.irqType(name="irq1", number=15)]
         dev2_testirqs = [
             src.schemadata.schema.irqType(name="irq1", number=40),
@@ -652,13 +645,7 @@ class TestPciDevicesCreator:
                     revisionId="16#04#"))
 
         irq = src.schemadata.schema.irqType(name="irq1", number=3)
-
-        memory = src.schemadata.schema.deviceMemoryType(
-            caching="UC", name="mem1", physicalAddress="16#fb22_4000#",
-            size="16#1000#")
-
         rmrr = src.schemadata.schema.namedRefType(ref="rmrr42")
-
         ioport = src.schemadata.schema.ioPortType(
             name="ioport1", start="16#f000#", end="16#f01f#")
 
@@ -837,11 +824,6 @@ class TestIommuDevicesCreator:
                                               AGAW_BIT_START) == "agaw"
 
     def test_createDeviceFromAddr(self):
-        DEVMEM = paths.DEVMEM
-        AGAW_BIT_START = 8
-        IOMMU_SIZE = "1000"
-
-        iommuaddr = "0xfed91000"
         testiommuaddr = "0x0"
         devmemloc = os.path.join(self.testdir, "testdevmem")