File: test__ped_disk.py

package info (click to toggle)
pyparted 3.13.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 952 kB
  • sloc: ansic: 7,453; python: 4,579; makefile: 91; sh: 4
file content (247 lines) | stat: -rwxr-xr-x 7,356 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
#
# Copyright The pyparted Project Authors
# SPDX-License-Identifier: GPL-2.0-or-later
#

import _ped
import unittest

from tests.baseclass import RequiresDevice, RequiresLabeledDevice, RequiresDisk

# 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 DiskNewUnlabeledTestCase(RequiresDevice):
    def runTest(self):
        self.assertRaises(_ped.DiskLabelException, _ped.Disk, self._device)


@unittest.skip("Debian CI tests")
class DiskNewLabeledTestCase(RequiresLabeledDevice):
    def runTest(self):
        result = _ped.Disk(self._device)
        self.assertIsInstance(result, _ped.Disk)
        self.assertEqual(result.type.name, "msdos")


@unittest.skip("Unimplemented test case.")
class DiskGetSetTestCase(unittest.TestCase):
    # TODO
    def runTest(self):
        self.fail("Unimplemented test case.")


@unittest.skip("Unimplemented test case.")
class DiskClobberTestCase(unittest.TestCase):
    # TODO
    def runTest(self):
        self.fail("Unimplemented test case.")


@unittest.skip("Unimplemented test case.")
class DiskClobberExcludeTestCase(unittest.TestCase):
    # TODO
    def runTest(self):
        self.fail("Unimplemented test case.")


@unittest.skip("Unimplemented test case.")
class DiskDuplicateTestCase(unittest.TestCase):
    # TODO
    def runTest(self):
        self.fail("Unimplemented test case.")


@unittest.skip("Unimplemented test case.")
class DiskDestroyTestCase(unittest.TestCase):
    # TODO
    def runTest(self):
        self.fail("Unimplemented test case.")


class DiskCommitTestCase(RequiresDisk):
    def runTest(self):
        self.assertTrue(self._disk.commit())


class DiskCommitToDevTestCase(RequiresDisk):
    def runTest(self):
        self.assertTrue(self._disk.commit_to_dev())


class DiskCommitToOsTestCase(RequiresDisk):
    def runTest(self):
        self.assertTrue(self._disk.commit_to_os())


class DiskCheckTestCase(RequiresDisk):
    def runTest(self):
        self.assertTrue(self._disk.check())


@unittest.skip("Unimplemented test case.")
class DiskPrintTestCase(unittest.TestCase):
    # TODO
    def runTest(self):
        self.fail("Unimplemented test case.")


class DiskGetPrimaryPartitionCountTestCase(RequiresDisk):
    def runTest(self):
        # XXX: this could probably test more
        self.assertEqual(self._disk.get_primary_partition_count(), 0)


class DiskGetLastPartitionNumTestCase(RequiresDisk):
    def runTest(self):
        # XXX: this could probably test more
        self.assertEqual(self._disk.get_last_partition_num(), -1)


class DiskGetMaxPrimaryPartitionCountTestCase(RequiresDisk):
    def runTest(self):
        self.assertEqual(self._disk.get_max_primary_partition_count(), 4)


class DiskGetMaxSupportedPartitionCountTestCase(RequiresDisk):
    def runTest(self):
        self.assertEqual(self._disk.get_max_supported_partition_count(), 64)


class DiskGetPartitionAlignmentTestCase(RequiresDisk):
    def runTest(self):
        alignment = self._disk.get_partition_alignment()
        self.assertIsInstance(alignment, _ped.Alignment)
        # These 2 tests assume an MSDOS label as given by RequiresDisk
        self.assertEqual(alignment.offset, 0)
        self.assertEqual(alignment.grain_size, 1)


class DiskMaxPartitionLengthTestCase(RequiresDisk):
    def runTest(self):
        # This test assumes an MSDOS label as given by RequiresDisk
        self.assertEqual(self._disk.max_partition_length(), 4294967295)


class DiskMaxPartitionStartSectorTestCase(RequiresDisk):
    def runTest(self):
        # This test assumes an MSDOS label as given by RequiresDisk
        self.assertEqual(self._disk.max_partition_start_sector(), 4294967295)


class DiskSetFlagTestCase(RequiresDisk):
    def runTest(self):
        # These 2 tests assume an MSDOS label as given by RequiresDisk
        self._disk.set_flag(_ped.DISK_CYLINDER_ALIGNMENT, 1)
        self.assertEqual(self._disk.get_flag(_ped.DISK_CYLINDER_ALIGNMENT), True)
        self._disk.set_flag(_ped.DISK_CYLINDER_ALIGNMENT, 0)
        self.assertEqual(self._disk.get_flag(_ped.DISK_CYLINDER_ALIGNMENT), False)


class DiskGetFlagTestCase(RequiresDisk):
    def runTest(self):
        flag = self._disk.get_flag(_ped.DISK_CYLINDER_ALIGNMENT)
        self.assertIsInstance(flag, bool)


class DiskIsFlagAvailableTestCase(RequiresDisk):
    def runTest(self):
        # We don't know which flags should be available and which shouldn't,
        # but we can at least check that there aren't any tracebacks from
        # trying all of the valid ones.
        for flag in [_ped.DISK_CYLINDER_ALIGNMENT, _ped.DISK_GPT_PMBR_BOOT]:
            self.assertIsInstance(self._disk.is_flag_available(flag), bool)

        # However, an invalid flag should definitely not be available.
        self.assertFalse(self._disk.is_flag_available(1000))


@unittest.skip("Unimplemented test case.")
class DiskAddPartitionTestCase(unittest.TestCase):
    # TODO
    def runTest(self):
        self.fail("Unimplemented test case.")


@unittest.skip("Unimplemented test case.")
class DiskRemovePartitionTestCase(unittest.TestCase):
    # TODO
    def runTest(self):
        self.fail("Unimplemented test case.")


@unittest.skip("Unimplemented test case.")
class DiskDeletePartitionTestCase(unittest.TestCase):
    # TODO
    def runTest(self):
        self.fail("Unimplemented test case.")


@unittest.skip("Unimplemented test case.")
class DiskDeleteAllTestCase(unittest.TestCase):
    # TODO
    def runTest(self):
        self.fail("Unimplemented test case.")


@unittest.skip("Unimplemented test case.")
class DiskSetPartitionGeomTestCase(unittest.TestCase):
    # TODO
    def runTest(self):
        self.fail("Unimplemented test case.")


@unittest.skip("Unimplemented test case.")
class DiskMaxmimzePartitionTestCase(unittest.TestCase):
    # TODO
    def runTest(self):
        self.fail("Unimplemented test case.")


@unittest.skip("Unimplemented test case.")
class DiskGetMaxPartitionGeoemtryTestCase(unittest.TestCase):
    # TODO
    def runTest(self):
        self.fail("Unimplemented test case.")


@unittest.skip("Unimplemented test case.")
class DiskMinimizeExtendedPartitionTestCase(unittest.TestCase):
    # TODO
    def runTest(self):
        self.fail("Unimplemented test case.")


@unittest.skip("Unimplemented test case.")
class DiskNextPartitionTestCase(unittest.TestCase):
    # TODO
    def runTest(self):
        self.fail("Unimplemented test case.")


@unittest.skip("Unimplemented test case.")
class DiskGetPartitionTestCase(unittest.TestCase):
    # TODO
    def runTest(self):
        self.fail("Unimplemented test case.")


@unittest.skip("Unimplemented test case.")
class DiskGetPartitionBySectorTestCase(unittest.TestCase):
    # TODO
    def runTest(self):
        self.fail("Unimplemented test case.")


class DiskExtendedPartitionTestCase(RequiresDisk):
    def runTest(self):
        self.assertRaises(_ped.PartitionException, self._disk.extended_partition)


class DiskStrTestCase(RequiresDisk):
    def runTest(self):
        expected = "_ped.Disk instance --\n  dev: %s  type: %s" % (
            repr(self._disk.dev),
            repr(self._disk.type),
        )
        self.assertEqual(expected, str(self._disk))