Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: Test to make sure partition and disk names match libparted #93

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 70 additions & 15 deletions tests/test__ped_ped.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,56 @@

from tests.baseclass import BuildList, RequiresDevice, RequiresFileSystem

# One class per method, multiple tests per class. For these simple methods,
# that seems like good organization. More complicated methods may require
# multiple classes and their own test suite.
class PartitionFlagGetNameTestCase(unittest.TestCase):
def runTest(self):
for f in ['PARTITION_BOOT', 'PARTITION_ROOT', 'PARTITION_SWAP',

# Mapping of flags to names
disk_flags = ['DISK_CYLINDER_ALIGNMENT', 'DISK_GPT_PMBR_BOOT']
disk_names = ["cylinder_alignment", "pmbr_boot"]

partition_flags = ['PARTITION_BOOT', 'PARTITION_ROOT', 'PARTITION_SWAP',
'PARTITION_HIDDEN', 'PARTITION_RAID', 'PARTITION_LVM',
'PARTITION_LBA', 'PARTITION_HPSERVICE',
'PARTITION_PALO', 'PARTITION_PREP',
'PARTITION_MSFT_RESERVED',
'PARTITION_BIOS_GRUB',
'PARTITION_APPLE_TV_RECOVERY',
'PARTITION_BIOS_GRUB', 'PARTITION_DIAG',
'PARTITION_DIAG',
'PARTITION_LEGACY_BOOT',
'PARTITION_MSFT_DATA', 'PARTITION_IRST',
'PARTITION_ESP', 'PARTITION_NONFS',
'PARTITION_CHROMEOS_KERNEL', 'PARTITION_CHROMEOS_KERNEL']:
'PARTITION_ESP',
'PARTITION_CHROMEOS_KERNEL', 'PARTITION_BLS_BOOT',
'PARTITION_LINUX_HOME']
partition_names = ["boot", "root", "swap", "hidden", "raid", "lvm", "lba",
"hp-service", "palo", "prep", "msftres", "bios_grub",
"atvrecv", "diag", "legacy_boot", "msftdata", "irst",
"esp", "chromeos_kernel", "bls_boot", "linux-home"]

# One class per method, multiple tests per class. For these simple methods,
# that seems like good organization. More complicated methods may require
# multiple classes and their own test suite.

# This checks all the partition flags that libparted reports to make sure they
# have been compiled into pyparted as attributes
class PartitionFlagKnownNamesTestCase(unittest.TestCase):
def runTest(self):
all_flags = dict(zip(partition_names, partition_flags))
f = 0
while True:
f = _ped.partition_flag_next(f)
if f == 0:
break
n = _ped.partition_flag_get_name(f)
with self.subTest(n=n):
if n not in all_flags:
self.skipTest(f"Unknown flag: {n}")
attr = all_flags[n]

# Confirm that the build included this flag attr
self.assertTrue(hasattr(_ped, attr), attr)


class PartitionFlagGetNameTestCase(unittest.TestCase):
def runTest(self):
for f in partition_flags:
if not hasattr(_ped, f):
continue
attr = getattr(_ped, f)
Expand All @@ -53,9 +88,7 @@ def runTest(self):

class PartitionFlagGetByNameTestCase(unittest.TestCase):
def runTest(self):
for f in ["boot", "root", "swap", "hidden", "raid", "lvm", "lba",
"hp-service", "palo", "prep", "msftres", "bios_grub",
"msftdata", "irst", "esp", "nonfs"]:
for f in partition_names:
self.assertNotEqual(_ped.partition_flag_get_by_name(f), "", "Could not get flag %s" % f)

self.assertEqual(_ped.partition_flag_get_by_name("nosuchflag"), 0)
Expand All @@ -77,17 +110,39 @@ def runTest(self):
break
self.assertEqual(type(flag).__name__, 'int')

# This checks all the disk flags that libparted reports to make sure they
# have been compiled into pyparted as attributes
class DiskFlagKnownNamesTestCase(unittest.TestCase):
def runTest(self):
all_flags = dict(zip(disk_names, disk_flags))
f = 0
while True:
f = _ped.disk_flag_next(f)
if f == 0:
break
n = _ped.disk_flag_get_name(f)
with self.subTest(n=n):
if n not in all_flags:
self.skipTest(f"Unknown flag: {n}")
attr = all_flags[n]

# Confirm that the build included this flag attr
self.assertTrue(hasattr(_ped, attr), attr)

class DiskFlagGetNameTestCase(unittest.TestCase):
def runTest(self):
for f in [_ped.DISK_CYLINDER_ALIGNMENT]:
self.assertNotEqual(_ped.disk_flag_get_name(f), "", "Could not get name for flag %s" % f)
for f in disk_flags:
if not hasattr(_ped, f):
continue
attr = getattr(_ped, f)
self.assertNotEqual(_ped.disk_flag_get_name(attr), "", "Could not get name for flag %s" % f)

self.assertRaises(ValueError, _ped.disk_flag_get_name, -1)
self.assertRaises(_ped.PartedException, _ped.disk_flag_get_name, 1000)

class DiskFlagGetByNameTestCase(unittest.TestCase):
def runTest(self):
for f in ["cylinder_alignment"]:
for f in disk_names:
self.assertNotEqual(_ped.disk_flag_get_by_name(f), 0, "Could not get flag %s" % f)

self.assertEqual(_ped.disk_flag_get_by_name("nosuchflag"), 0)
Expand Down