mirror of
https://github.com/kevingruesser/bootstrap-vz.git
synced 2025-08-24 15:36:27 +00:00

Up until now I didn't see the point of using spaces for indentation. However, the previous commit (a18bec3) was quite eye opening. Given that python is an indentation aware language, the amount of mistakes that went unnoticed because tabs and spaces were used at the same time (tabs for indentation and spaces for alignment) were unacceptable. E101,W191 have been re-enable in the tox flake8 checker and the documentation has been modified accordingly. The following files have been left as-is: * bootstrapvz/common/assets/extlinux/extlinux.conf * bootstrapvz/common/assets/init.d/expand-root * bootstrapvz/common/assets/init.d/generate-ssh-hostkeys * bootstrapvz/common/assets/init.d/squeeze/generate-ssh-hostkeys * bootstrapvz/plugins/docker_daemon/assets/init.d/docker * bootstrapvz/providers/ec2/assets/bin/growpart * bootstrapvz/providers/ec2/assets/grub.d/40_custom * bootstrapvz/providers/ec2/assets/init.d/ec2-get-credentials * bootstrapvz/providers/ec2/assets/init.d/ec2-run-user-data * docs/_static/taskoverview.coffee * docs/_static/taskoverview.less * tests/unit/subprocess.sh
127 lines
2.8 KiB
Python
127 lines
2.8 KiB
Python
from nose.tools import eq_
|
|
from nose.tools import raises
|
|
from bootstrapvz.common.sectors import Sectors
|
|
from bootstrapvz.common.bytes import Bytes
|
|
from bootstrapvz.common.exceptions import UnitError
|
|
|
|
std_secsz = Bytes(512)
|
|
|
|
|
|
def test_init_with_int():
|
|
secsize = 4096
|
|
eq_(Sectors('1MiB', secsize), Sectors(256, secsize))
|
|
|
|
|
|
def test_lt():
|
|
assert Sectors('1MiB', std_secsz) < Sectors('2MiB', std_secsz)
|
|
|
|
|
|
def test_le():
|
|
assert Sectors('1MiB', std_secsz) <= Sectors('2MiB', std_secsz)
|
|
assert Sectors('1MiB', std_secsz) <= Sectors('1MiB', std_secsz)
|
|
|
|
|
|
def test_eq():
|
|
eq_(Sectors('1MiB', std_secsz), Sectors('1MiB', std_secsz))
|
|
|
|
|
|
def test_neq():
|
|
assert Sectors('15MiB', std_secsz) != Sectors('1MiB', std_secsz)
|
|
|
|
|
|
def test_gt():
|
|
assert Sectors('2MiB', std_secsz) > Sectors('1MiB', std_secsz)
|
|
|
|
|
|
def test_ge():
|
|
assert Sectors('2MiB', std_secsz) >= Sectors('1MiB', std_secsz)
|
|
assert Sectors('2MiB', std_secsz) >= Sectors('2MiB', std_secsz)
|
|
|
|
|
|
def test_eq_unit():
|
|
eq_(Sectors('1024MiB', std_secsz), Sectors('1GiB', std_secsz))
|
|
|
|
|
|
def test_add():
|
|
eq_(Sectors('2GiB', std_secsz), Sectors('1GiB', std_secsz) + Sectors('1GiB', std_secsz))
|
|
|
|
|
|
@raises(UnitError)
|
|
def test_add_with_diff_secsize():
|
|
Sectors('1GiB', Bytes(512)) + Sectors('1GiB', Bytes(4096))
|
|
|
|
|
|
def test_iadd():
|
|
s = Sectors('1GiB', std_secsz)
|
|
s += Sectors('1GiB', std_secsz)
|
|
eq_(Sectors('2GiB', std_secsz), s)
|
|
|
|
|
|
def test_sub():
|
|
eq_(Sectors('1GiB', std_secsz), Sectors('2GiB', std_secsz) - Sectors('1GiB', std_secsz))
|
|
|
|
|
|
def test_sub_int():
|
|
secsize = Bytes('4KiB')
|
|
eq_(Sectors('1MiB', secsize), Sectors('1028KiB', secsize) - 1)
|
|
|
|
|
|
def test_isub():
|
|
s = Sectors('2GiB', std_secsz)
|
|
s -= Sectors('1GiB', std_secsz)
|
|
eq_(Sectors('1GiB', std_secsz), s)
|
|
|
|
|
|
def test_mul():
|
|
eq_(Sectors('2GiB', std_secsz), Sectors('1GiB', std_secsz) * 2)
|
|
|
|
|
|
@raises(UnitError)
|
|
def test_mul_bytes():
|
|
Sectors('1GiB', std_secsz) * Sectors('1GiB', std_secsz)
|
|
|
|
|
|
def test_imul():
|
|
s = Sectors('1GiB', std_secsz)
|
|
s *= 2
|
|
eq_(Sectors('2GiB', std_secsz), s)
|
|
|
|
|
|
def test_div():
|
|
eq_(Sectors('1GiB', std_secsz), Sectors('2GiB', std_secsz) / 2)
|
|
|
|
|
|
def test_div_bytes():
|
|
eq_(2, Sectors('2GiB', std_secsz) / Sectors('1GiB', std_secsz))
|
|
|
|
|
|
def test_idiv():
|
|
s = Sectors('2GiB', std_secsz)
|
|
s /= 2
|
|
eq_(Sectors('1GiB', std_secsz), s)
|
|
|
|
|
|
def test_mod():
|
|
eq_(Sectors('256MiB', std_secsz), Sectors('1GiB', std_secsz) % Sectors('768MiB', std_secsz))
|
|
|
|
|
|
@raises(UnitError)
|
|
def test_mod_int():
|
|
Sectors('1GiB', std_secsz) % 768
|
|
|
|
|
|
def test_imod():
|
|
s = Sectors('1GiB', std_secsz)
|
|
s %= Sectors('768MiB', std_secsz)
|
|
eq_(Sectors('256MiB', std_secsz), s)
|
|
|
|
|
|
@raises(UnitError)
|
|
def test_imod_int():
|
|
s = Sectors('1GiB', std_secsz)
|
|
s %= 5
|
|
|
|
|
|
def test_convert_int():
|
|
secsize = 512
|
|
eq_(pow(1024, 3) / secsize, int(Sectors('1GiB', secsize)))
|