]> git.proxmox.com Git - ceph.git/blob - ceph/src/ceph-volume/ceph_volume/tests/util/test_disk.py
import ceph nautilus 14.2.2
[ceph.git] / ceph / src / ceph-volume / ceph_volume / tests / util / test_disk.py
1 import os
2 import pytest
3 from ceph_volume.util import disk
4
5
6 class TestLsblkParser(object):
7
8 def test_parses_whitespace_values(self):
9 output = 'NAME="sdaa5" PARTLABEL="ceph data" RM="0" SIZE="10M" RO="0" TYPE="part"'
10 result = disk._lsblk_parser(output)
11 assert result['PARTLABEL'] == 'ceph data'
12
13 def test_ignores_bogus_pairs(self):
14 output = 'NAME="sdaa5" PARTLABEL RM="0" SIZE="10M" RO="0" TYPE="part" MOUNTPOINT=""'
15 result = disk._lsblk_parser(output)
16 assert result['SIZE'] == '10M'
17
18
19 class TestBlkidParser(object):
20
21 def test_parses_whitespace_values(self):
22 output = '''/dev/sdb1: UUID="62416664-cbaf-40bd-9689-10bd337379c3" TYPE="xfs" PART_ENTRY_SCHEME="gpt" PART_ENTRY_NAME="ceph data" PART_ENTRY_UUID="b89c03bc-bf58-4338-a8f8-a2f484852b4f"''' # noqa
23 result = disk._blkid_parser(output)
24 assert result['PARTLABEL'] == 'ceph data'
25
26 def test_ignores_unmapped(self):
27 output = '''/dev/sdb1: UUID="62416664-cbaf-40bd-9689-10bd337379c3" TYPE="xfs" PART_ENTRY_SCHEME="gpt" PART_ENTRY_NAME="ceph data" PART_ENTRY_UUID="b89c03bc-bf58-4338-a8f8-a2f484852b4f"''' # noqa
28 result = disk._blkid_parser(output)
29 assert len(result.keys()) == 4
30
31 def test_translates_to_partuuid(self):
32 output = '''/dev/sdb1: UUID="62416664-cbaf-40bd-9689-10bd337379c3" TYPE="xfs" PART_ENTRY_SCHEME="gpt" PART_ENTRY_NAME="ceph data" PART_ENTRY_UUID="b89c03bc-bf58-4338-a8f8-a2f484852b4f"''' # noqa
33 result = disk._blkid_parser(output)
34 assert result['PARTUUID'] == 'b89c03bc-bf58-4338-a8f8-a2f484852b4f'
35
36
37 class TestBlkid(object):
38
39 def test_parses_translated(self, stub_call):
40 output = '''/dev/sdb1: UUID="62416664-cbaf-40bd-9689-10bd337379c3" TYPE="xfs" PART_ENTRY_SCHEME="gpt" PART_ENTRY_NAME="ceph data" PART_ENTRY_UUID="b89c03bc-bf58-4338-a8f8-a2f484852b4f"''' # noqa
41 stub_call((output.split(), [], 0))
42 result = disk.blkid('/dev/sdb1')
43 assert result['PARTUUID'] == 'b89c03bc-bf58-4338-a8f8-a2f484852b4f'
44 assert result['PARTLABEL'] == 'ceph data'
45 assert result['UUID'] == '62416664-cbaf-40bd-9689-10bd337379c3'
46 assert result['TYPE'] == 'xfs'
47
48 class TestUdevadmProperty(object):
49
50 def test_good_output(self, stub_call):
51 output = """ID_MODEL=SK_hynix_SC311_SATA_512GB
52 ID_PART_TABLE_TYPE=gpt
53 ID_SERIAL_SHORT=MS83N71801150416A""".split()
54 stub_call((output, [], 0))
55 result = disk.udevadm_property('dev/sda')
56 assert result['ID_MODEL'] == 'SK_hynix_SC311_SATA_512GB'
57 assert result['ID_PART_TABLE_TYPE'] == 'gpt'
58 assert result['ID_SERIAL_SHORT'] == 'MS83N71801150416A'
59
60 def test_property_filter(self, stub_call):
61 output = """ID_MODEL=SK_hynix_SC311_SATA_512GB
62 ID_PART_TABLE_TYPE=gpt
63 ID_SERIAL_SHORT=MS83N71801150416A""".split()
64 stub_call((output, [], 0))
65 result = disk.udevadm_property('dev/sda', ['ID_MODEL',
66 'ID_SERIAL_SHORT'])
67 assert result['ID_MODEL'] == 'SK_hynix_SC311_SATA_512GB'
68 assert 'ID_PART_TABLE_TYPE' not in result
69
70 def test_fail_on_broken_output(self, stub_call):
71 output = ["ID_MODEL:SK_hynix_SC311_SATA_512GB"]
72 stub_call((output, [], 0))
73 with pytest.raises(ValueError):
74 disk.udevadm_property('dev/sda')
75
76
77 class TestDeviceFamily(object):
78
79 def test_groups_multiple_devices(self, stub_call):
80 out = [
81 'NAME="sdaa5" PARLABEL="ceph lockbox"',
82 'NAME="sdaa" RO="0"',
83 'NAME="sdaa1" PARLABEL="ceph data"',
84 'NAME="sdaa2" PARLABEL="ceph journal"',
85 ]
86 stub_call((out, '', 0))
87 result = disk.device_family('sdaa5')
88 assert len(result) == 4
89
90 def test_parses_output_correctly(self, stub_call):
91 names = ['sdaa', 'sdaa5', 'sdaa1', 'sdaa2']
92 out = [
93 'NAME="sdaa5" PARLABEL="ceph lockbox"',
94 'NAME="sdaa" RO="0"',
95 'NAME="sdaa1" PARLABEL="ceph data"',
96 'NAME="sdaa2" PARLABEL="ceph journal"',
97 ]
98 stub_call((out, '', 0))
99 result = disk.device_family('sdaa5')
100 for parsed in result:
101 assert parsed['NAME'] in names
102
103
104 class TestMapDevPaths(object):
105
106 def test_errors_return_empty_mapping(self, tmpdir):
107 bad_dir = os.path.join(str(tmpdir), 'nonexisting')
108 assert disk._map_dev_paths(bad_dir) == {}
109
110 def test_base_name_and_abspath(self, tmpfile):
111 sda_path = tmpfile(name='sda', contents='')
112 directory = os.path.dirname(sda_path)
113 result = disk._map_dev_paths(directory)
114 assert len(result.keys()) == 1
115 assert result['sda'] == sda_path
116
117 def test_abspath_included(self, tmpfile):
118 sda_path = tmpfile(name='sda', contents='')
119 directory = os.path.dirname(sda_path)
120 result = disk._map_dev_paths(directory, include_abspath=True)
121 assert sorted(result.keys()) == sorted(['sda', sda_path])
122 assert result['sda'] == sda_path
123 assert result[sda_path] == 'sda'
124
125 def test_realpath_included(self, tmpfile):
126 sda_path = tmpfile(name='sda', contents='')
127 directory = os.path.dirname(sda_path)
128 dm_path = os.path.join(directory, 'dm-0')
129 os.symlink(sda_path, os.path.join(directory, 'dm-0'))
130 result = disk._map_dev_paths(directory, include_realpath=True)
131 assert sorted(result.keys()) == sorted(['sda', 'dm-0'])
132 assert result['sda'] == dm_path
133 assert result['dm-0'] == dm_path
134
135 def test_absolute_and_realpath_included(self, tmpfile):
136 dm_path = tmpfile(name='dm-0', contents='')
137 directory = os.path.dirname(dm_path)
138 sda_path = os.path.join(directory, 'sda')
139 os.symlink(sda_path, os.path.join(directory, 'sda'))
140 result = disk._map_dev_paths(directory, include_realpath=True, include_abspath=True)
141 assert sorted(result.keys()) == sorted([dm_path, sda_path, 'sda', 'dm-0'])
142 assert result['sda'] == sda_path
143 assert result['dm-0'] == dm_path
144 assert result[sda_path] == sda_path
145 assert result[dm_path] == 'dm-0'
146
147
148 class TestGetBlockDevs(object):
149
150 def test_loop_devices_are_missing(self, tmpfile):
151 path = os.path.dirname(tmpfile(name='loop0', contents=''))
152 result = disk.get_block_devs(sys_block_path=path)
153 assert result == []
154
155 def test_loop_devices_are_included(self, tmpfile):
156 path = os.path.dirname(tmpfile(name='loop0', contents=''))
157 result = disk.get_block_devs(sys_block_path=path, skip_loop=False)
158 assert len(result) == 1
159 assert result == ['loop0']
160
161
162 class TestGetDevDevs(object):
163
164 def test_abspaths_are_included(self, tmpfile):
165 sda_path = tmpfile(name='sda', contents='')
166 directory = os.path.dirname(sda_path)
167 result = disk.get_dev_devs(directory)
168 assert sorted(result.keys()) == sorted(['sda', sda_path])
169 assert result['sda'] == sda_path
170 assert result[sda_path] == 'sda'
171
172
173 class TestGetMapperDevs(object):
174
175 def test_abspaths_and_realpaths_are_included(self, tmpfile):
176 dm_path = tmpfile(name='dm-0', contents='')
177 directory = os.path.dirname(dm_path)
178 sda_path = os.path.join(directory, 'sda')
179 os.symlink(sda_path, os.path.join(directory, 'sda'))
180 result = disk.get_mapper_devs(directory)
181 assert sorted(result.keys()) == sorted([dm_path, sda_path, 'sda', 'dm-0'])
182 assert result['sda'] == sda_path
183 assert result['dm-0'] == dm_path
184 assert result[sda_path] == sda_path
185 assert result[dm_path] == 'dm-0'
186
187
188 class TestHumanReadableSize(object):
189
190 def test_bytes(self):
191 result = disk.human_readable_size(800)
192 assert result == '800.00 B'
193
194 def test_kilobytes(self):
195 result = disk.human_readable_size(800*1024)
196 assert result == '800.00 KB'
197
198 def test_megabytes(self):
199 result = disk.human_readable_size(800*1024*1024)
200 assert result == '800.00 MB'
201
202 def test_gigabytes(self):
203 result = disk.human_readable_size(8.19*1024*1024*1024)
204 assert result == '8.19 GB'
205
206 def test_terabytes(self):
207 result = disk.human_readable_size(81.2*1024*1024*1024*1024)
208 assert result == '81.20 TB'
209
210
211 class TestSizeFromHumanReadable(object):
212
213 def test_bytes(self):
214 result = disk.size_from_human_readable('2')
215 assert result == disk.Size(b=2)
216
217 def test_kilobytes(self):
218 result = disk.size_from_human_readable('2 K')
219 assert result == disk.Size(kb=2)
220
221 def test_megabytes(self):
222 result = disk.size_from_human_readable('2 M')
223 assert result == disk.Size(mb=2)
224
225 def test_gigabytes(self):
226 result = disk.size_from_human_readable('2 G')
227 assert result == disk.Size(gb=2)
228
229 def test_terrabytes(self):
230 result = disk.size_from_human_readable('2 T')
231 assert result == disk.Size(tb=2)
232
233 def test_case(self):
234 result = disk.size_from_human_readable('2 t')
235 assert result == disk.Size(tb=2)
236
237 def test_space(self):
238 result = disk.size_from_human_readable('2T')
239 assert result == disk.Size(tb=2)
240
241 def test_float(self):
242 result = disk.size_from_human_readable('2.0')
243 assert result == disk.Size(b=2)
244 result = disk.size_from_human_readable('2.0T')
245 assert result == disk.Size(tb=2)
246 result = disk.size_from_human_readable('1.8T')
247 assert result == disk.Size(tb=1.8)
248
249
250 class TestGetDevices(object):
251
252 def setup_paths(self, tmpdir):
253 paths = []
254 for directory in ['block', 'dev', 'mapper']:
255 path = os.path.join(str(tmpdir), directory)
256 paths.append(path)
257 os.makedirs(path)
258 return paths
259
260 def test_no_devices_are_found(self, tmpdir):
261 result = disk.get_devices(
262 _sys_block_path=str(tmpdir),
263 _dev_path=str(tmpdir),
264 _mapper_path=str(tmpdir))
265 assert result == {}
266
267 def test_no_devices_are_found_errors(self, tmpdir):
268 block_path, dev_path, mapper_path = self.setup_paths(tmpdir)
269 os.makedirs(os.path.join(block_path, 'sda'))
270 result = disk.get_devices(
271 _sys_block_path=block_path, # has 1 device
272 _dev_path=str(tmpdir), # exists but no devices
273 _mapper_path='/does/not/exist/path') # does not exist
274 assert result == {}
275
276 def test_sda_block_is_found(self, tmpfile, tmpdir):
277 block_path, dev_path, mapper_path = self.setup_paths(tmpdir)
278 dev_sda_path = os.path.join(dev_path, 'sda')
279 os.makedirs(os.path.join(block_path, 'sda'))
280 os.makedirs(dev_sda_path)
281 result = disk.get_devices(
282 _sys_block_path=block_path,
283 _dev_path=dev_path,
284 _mapper_path=mapper_path)
285 assert len(result.keys()) == 1
286 assert result[dev_sda_path]['human_readable_size'] == '0.00 B'
287 assert result[dev_sda_path]['model'] == ''
288 assert result[dev_sda_path]['partitions'] == {}
289
290
291 def test_dm_device_is_not_used(self, monkeypatch, tmpdir):
292 # the link to the mapper is used instead
293 monkeypatch.setattr(disk.lvm, 'is_lv', lambda: True)
294 block_path, dev_path, mapper_path = self.setup_paths(tmpdir)
295 dev_dm_path = os.path.join(dev_path, 'dm-0')
296 ceph_data_path = os.path.join(mapper_path, 'ceph-data')
297 os.symlink(dev_dm_path, ceph_data_path)
298 block_dm_path = os.path.join(block_path, 'dm-0')
299 os.makedirs(block_dm_path)
300
301 result = disk.get_devices(
302 _sys_block_path=block_path,
303 _dev_path=dev_path,
304 _mapper_path=mapper_path)
305 result = list(result.keys())
306 assert len(result) == 1
307 assert result == [ceph_data_path]
308
309 def test_sda_size(self, tmpfile, tmpdir):
310 block_path, dev_path, mapper_path = self.setup_paths(tmpdir)
311 block_sda_path = os.path.join(block_path, 'sda')
312 dev_sda_path = os.path.join(dev_path, 'sda')
313 os.makedirs(block_sda_path)
314 os.makedirs(dev_sda_path)
315 tmpfile('size', '1024', directory=block_sda_path)
316 result = disk.get_devices(
317 _sys_block_path=block_path,
318 _dev_path=dev_path,
319 _mapper_path=mapper_path)
320 assert list(result.keys()) == [dev_sda_path]
321 assert result[dev_sda_path]['human_readable_size'] == '512.00 KB'
322
323 def test_sda_sectorsize_fallsback(self, tmpfile, tmpdir):
324 # if no sectorsize, it will use queue/hw_sector_size
325 block_path, dev_path, mapper_path = self.setup_paths(tmpdir)
326 block_sda_path = os.path.join(block_path, 'sda')
327 sda_queue_path = os.path.join(block_sda_path, 'queue')
328 dev_sda_path = os.path.join(dev_path, 'sda')
329 os.makedirs(block_sda_path)
330 os.makedirs(sda_queue_path)
331 os.makedirs(dev_sda_path)
332 tmpfile('hw_sector_size', contents='1024', directory=sda_queue_path)
333 result = disk.get_devices(
334 _sys_block_path=block_path,
335 _dev_path=dev_path,
336 _mapper_path=mapper_path)
337 assert list(result.keys()) == [dev_sda_path]
338 assert result[dev_sda_path]['sectorsize'] == '1024'
339
340 def test_sda_sectorsize_from_logical_block(self, tmpfile, tmpdir):
341 block_path, dev_path, mapper_path = self.setup_paths(tmpdir)
342 block_sda_path = os.path.join(block_path, 'sda')
343 sda_queue_path = os.path.join(block_sda_path, 'queue')
344 dev_sda_path = os.path.join(dev_path, 'sda')
345 os.makedirs(block_sda_path)
346 os.makedirs(sda_queue_path)
347 os.makedirs(dev_sda_path)
348 tmpfile('logical_block_size', contents='99', directory=sda_queue_path)
349 result = disk.get_devices(
350 _sys_block_path=block_path,
351 _dev_path=dev_path,
352 _mapper_path=mapper_path)
353 assert result[dev_sda_path]['sectorsize'] == '99'
354
355 def test_sda_sectorsize_does_not_fallback(self, tmpfile, tmpdir):
356 block_path, dev_path, mapper_path = self.setup_paths(tmpdir)
357 block_sda_path = os.path.join(block_path, 'sda')
358 sda_queue_path = os.path.join(block_sda_path, 'queue')
359 dev_sda_path = os.path.join(dev_path, 'sda')
360 os.makedirs(block_sda_path)
361 os.makedirs(sda_queue_path)
362 os.makedirs(dev_sda_path)
363 tmpfile('logical_block_size', contents='99', directory=sda_queue_path)
364 tmpfile('hw_sector_size', contents='1024', directory=sda_queue_path)
365 result = disk.get_devices(
366 _sys_block_path=block_path,
367 _dev_path=dev_path,
368 _mapper_path=mapper_path)
369 assert result[dev_sda_path]['sectorsize'] == '99'
370
371 def test_is_rotational(self, tmpfile, tmpdir):
372 block_path, dev_path, mapper_path = self.setup_paths(tmpdir)
373 block_sda_path = os.path.join(block_path, 'sda')
374 sda_queue_path = os.path.join(block_sda_path, 'queue')
375 dev_sda_path = os.path.join(dev_path, 'sda')
376 os.makedirs(block_sda_path)
377 os.makedirs(sda_queue_path)
378 os.makedirs(dev_sda_path)
379 tmpfile('rotational', contents='1', directory=sda_queue_path)
380 result = disk.get_devices(
381 _sys_block_path=block_path,
382 _dev_path=dev_path,
383 _mapper_path=mapper_path)
384 assert result[dev_sda_path]['rotational'] == '1'
385
386
387 class TestSizeCalculations(object):
388
389 @pytest.mark.parametrize('aliases', [
390 ('b', 'bytes'),
391 ('kb', 'kilobytes'),
392 ('mb', 'megabytes'),
393 ('gb', 'gigabytes'),
394 ('tb', 'terabytes'),
395 ])
396 def test_aliases(self, aliases):
397 short_alias, long_alias = aliases
398 s = disk.Size(b=1)
399 short_alias = getattr(s, short_alias)
400 long_alias = getattr(s, long_alias)
401 assert short_alias == long_alias
402
403 @pytest.mark.parametrize('values', [
404 ('b', 857619069665.28),
405 ('kb', 837518622.72),
406 ('mb', 817889.28),
407 ('gb', 798.72),
408 ('tb', 0.78),
409 ])
410 def test_terabytes(self, values):
411 # regardless of the input value, all the other values correlate to each
412 # other the same, every time
413 unit, value = values
414 s = disk.Size(**{unit: value})
415 assert s.b == 857619069665.28
416 assert s.kb == 837518622.72
417 assert s.mb == 817889.28
418 assert s.gb == 798.72
419 assert s.tb == 0.78
420
421
422 class TestSizeOperators(object):
423
424 @pytest.mark.parametrize('larger', [1025, 1024.1, 1024.001])
425 def test_gigabytes_is_smaller(self, larger):
426 assert disk.Size(gb=1) < disk.Size(mb=larger)
427
428 @pytest.mark.parametrize('smaller', [1023, 1023.9, 1023.001])
429 def test_gigabytes_is_larger(self, smaller):
430 assert disk.Size(gb=1) > disk.Size(mb=smaller)
431
432 @pytest.mark.parametrize('larger', [1025, 1024.1, 1024.001, 1024])
433 def test_gigabytes_is_smaller_or_equal(self, larger):
434 assert disk.Size(gb=1) <= disk.Size(mb=larger)
435
436 @pytest.mark.parametrize('smaller', [1023, 1023.9, 1023.001, 1024])
437 def test_gigabytes_is_larger_or_equal(self, smaller):
438 assert disk.Size(gb=1) >= disk.Size(mb=smaller)
439
440 @pytest.mark.parametrize('values', [
441 ('b', 857619069665.28),
442 ('kb', 837518622.72),
443 ('mb', 817889.28),
444 ('gb', 798.72),
445 ('tb', 0.78),
446 ])
447 def test_equality(self, values):
448 unit, value = values
449 s = disk.Size(**{unit: value})
450 # both tb and b, since b is always calculated regardless, and is useful
451 # when testing tb
452 assert disk.Size(tb=0.78) == s
453 assert disk.Size(b=857619069665.28) == s
454
455 @pytest.mark.parametrize('values', [
456 ('b', 857619069665.28),
457 ('kb', 837518622.72),
458 ('mb', 817889.28),
459 ('gb', 798.72),
460 ('tb', 0.78),
461 ])
462 def test_inequality(self, values):
463 unit, value = values
464 s = disk.Size(**{unit: value})
465 # both tb and b, since b is always calculated regardless, and is useful
466 # when testing tb
467 assert disk.Size(tb=1) != s
468 assert disk.Size(b=100) != s
469
470
471 class TestSizeOperations(object):
472
473 def test_assignment_addition_with_size_objects(self):
474 result = disk.Size(mb=256) + disk.Size(gb=1)
475 assert result.gb == 1.25
476 assert result.gb.as_int() == 1
477 assert result.gb.as_float() == 1.25
478
479 def test_self_addition_with_size_objects(self):
480 base = disk.Size(mb=256)
481 base += disk.Size(gb=1)
482 assert base.gb == 1.25
483
484 def test_self_addition_does_not_alter_state(self):
485 base = disk.Size(mb=256)
486 base + disk.Size(gb=1)
487 assert base.mb == 256
488
489 def test_addition_with_non_size_objects(self):
490 with pytest.raises(TypeError):
491 disk.Size(mb=100) + 4
492
493 def test_assignment_subtraction_with_size_objects(self):
494 base = disk.Size(gb=1)
495 base -= disk.Size(mb=256)
496 assert base.mb == 768
497
498 def test_self_subtraction_does_not_alter_state(self):
499 base = disk.Size(gb=1)
500 base - disk.Size(mb=256)
501 assert base.gb == 1
502
503 def test_subtraction_with_size_objects(self):
504 result = disk.Size(gb=1) - disk.Size(mb=256)
505 assert result.mb == 768
506
507 def test_subtraction_with_non_size_objects(self):
508 with pytest.raises(TypeError):
509 disk.Size(mb=100) - 4
510
511 def test_multiplication_with_size_objects(self):
512 with pytest.raises(TypeError):
513 disk.Size(mb=100) * disk.Size(mb=1)
514
515 def test_multiplication_with_non_size_objects(self):
516 base = disk.Size(gb=1)
517 result = base * 2
518 assert result.gb == 2
519 assert result.gb.as_int() == 2
520
521 def test_division_with_size_objects(self):
522 result = disk.Size(gb=1) / disk.Size(mb=1)
523 assert int(result) == 1024
524
525 def test_division_with_non_size_objects(self):
526 base = disk.Size(gb=1)
527 result = base / 2
528 assert result.mb == 512
529 assert result.mb.as_int() == 512
530
531 def test_division_with_non_size_objects_without_state(self):
532 base = disk.Size(gb=1)
533 base / 2
534 assert base.gb == 1
535 assert base.gb.as_int() == 1
536
537
538 class TestSizeAttributes(object):
539
540 def test_attribute_does_not_exist(self):
541 with pytest.raises(AttributeError):
542 disk.Size(mb=1).exabytes
543
544
545 class TestSizeFormatting(object):
546
547 def test_default_formatting_tb_to_b(self):
548 size = disk.Size(tb=0.0000000001)
549 result = "%s" % size
550 assert result == "109.95 B"
551
552 def test_default_formatting_tb_to_kb(self):
553 size = disk.Size(tb=0.00000001)
554 result = "%s" % size
555 assert result == "10.74 KB"
556
557 def test_default_formatting_tb_to_mb(self):
558 size = disk.Size(tb=0.000001)
559 result = "%s" % size
560 assert result == "1.05 MB"
561
562 def test_default_formatting_tb_to_gb(self):
563 size = disk.Size(tb=0.001)
564 result = "%s" % size
565 assert result == "1.02 GB"
566
567 def test_default_formatting_tb_to_tb(self):
568 size = disk.Size(tb=10)
569 result = "%s" % size
570 assert result == "10.00 TB"
571
572
573 class TestSizeSpecificFormatting(object):
574
575 def test_formatting_b(self):
576 size = disk.Size(b=2048)
577 result = "%s" % size.b
578 assert "%s" % size.b == "%s" % size.bytes
579 assert result == "2048.00 B"
580
581 def test_formatting_kb(self):
582 size = disk.Size(kb=5700)
583 result = "%s" % size.kb
584 assert "%s" % size.kb == "%s" % size.kilobytes
585 assert result == "5700.00 KB"
586
587 def test_formatting_mb(self):
588 size = disk.Size(mb=4000)
589 result = "%s" % size.mb
590 assert "%s" % size.mb == "%s" % size.megabytes
591 assert result == "4000.00 MB"
592
593 def test_formatting_gb(self):
594 size = disk.Size(gb=77777)
595 result = "%s" % size.gb
596 assert "%s" % size.gb == "%s" % size.gigabytes
597 assert result == "77777.00 GB"
598
599 def test_formatting_tb(self):
600 size = disk.Size(tb=1027)
601 result = "%s" % size.tb
602 assert "%s" % size.tb == "%s" % size.terabytes
603 assert result == "1027.00 TB"