Git Product home page Git Product logo

Comments (4)

dwlehman avatar dwlehman commented on June 21, 2024

One option would be to mask the mount cache while running the action tests, eg:

diff --git a/tests/storagetestcase.py b/tests/storagetestcase.py
index ad1216f..427a19c 100644
--- a/tests/storagetestcase.py
+++ b/tests/storagetestcase.py
@@ -69,6 +69,12 @@ class StorageTestCase(unittest.TestCase):
         self.partition_probe = PartitionDevice.probe
         PartitionDevice.probe = partition_probe

+        def nada():
+            pass
+
+        self.get_active_mounts = blivet.formats.fs.mountsCache._getActiveMounts
+        blivet.formats.fs.mountsCache._getActiveMounts = nada
+
     def tearDown(self):
         blivet.devices.StorageDevice.status = self.storage_status
         blivet.devices.DMDevice.status = self.dm_status
@@ -84,6 +90,8 @@ class StorageTestCase(unittest.TestCase):

         blivet.devices.PartitionDevice.probe = self.partition_probe

+        blivet.formats.fs.mountsCache._getActiveMounts = self.get_active_mounts
+
     def newDevice(self, *args, **kwargs):
         """ Return a new Device instance suitable for testing. """
         device_class = kwargs.pop("device_class")

Another option would be to adjust the names of those disks/partitions, eg:

diff --git a/tests/action_test.py b/tests/action_test.py
index 00d63ad..bafec96 100644
--- a/tests/action_test.py
+++ b/tests/action_test.py
@@ -34,7 +34,7 @@ class DeviceActionTestCase(StorageTestCase):
         """
         super(DeviceActionTestCase, self).setUp()

-        for name in ["sda", "sdb", "sdc", "sdd"]:
+        for name in ["mocksda", "mocksdb", "mocksdc", "mocksdd"]:
             disk = self.newDevice(device_class=DiskDevice,
                                   name=name, size=Size("100 GiB"))
             disk.format = self.newFormat("disklabel", path=disk.path,
@@ -42,11 +42,11 @@ class DeviceActionTestCase(StorageTestCase):
             self.storage.devicetree._addDevice(disk)

         # create a layout similar to autopart as a starting point
-        sda = self.storage.devicetree.getDeviceByName("sda")
-        sdb = self.storage.devicetree.getDeviceByName("sdb")
+        sda = self.storage.devicetree.getDeviceByName("mocksda")
+        sdb = self.storage.devicetree.getDeviceByName("mocksdb")

         sda1 = self.newDevice(device_class=PartitionDevice,
-                              exists=True, name="sda1", parents=[sda],
+                              exists=True, name="mocksda1", parents=[sda],
                               size=Size("500 MiB"))
         sda1.format = self.newFormat("ext4", mountpoint="/boot",
                                      device_instance=sda1,
@@ -54,13 +54,13 @@ class DeviceActionTestCase(StorageTestCase):
         self.storage.devicetree._addDevice(sda1)

         sda2 = self.newDevice(device_class=PartitionDevice,
-                              size=Size("99.5 GiB"), name="sda2",
+                              size=Size("99.5 GiB"), name="mocksda2",
                               parents=[sda], exists=True)
         sda2.format = self.newFormat("lvmpv", device=sda2.path, exists=True)
         self.storage.devicetree._addDevice(sda2)

         sdb1 = self.newDevice(device_class=PartitionDevice,
-                              size=Size("99.999 GiB"), name="sdb1",
+                              size=Size("99.999 GiB"), name="mocksdb1",
                               parents=[sdb], exists=True)
         sdb1.format = self.newFormat("lvmpv", device=sdb1.path, exists=True)
         self.storage.devicetree._addDevice(sdb1)

Which seems preferable?

from blivet.

mulkieran avatar mulkieran commented on June 21, 2024

It is hard for me to say. You already set the status property of lots of Device* methods to False; perhaps that is another reasonable option.

from blivet.

vpodzime avatar vpodzime commented on June 21, 2024

I am for the former suggested approach except that it should use python-mock and Mock instance(s). I've created many unit tests for the oscap-anaconda-addon that use Mock quite heavily and it was really worth it. See for example https://github.com/OpenSCAP/oscap-anaconda-addon/blob/master/tests/common_test.py

from blivet.

dwlehman avatar dwlehman commented on June 21, 2024

Fixed by 4627e65

from blivet.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.