Exemple #1
0
def test_file_handle_write():
    handle = io.StringIO()

    fstab = Fstab().read_string(normal_spaces_tight)

    assert len(fstab.entries) == 2

    assert fstab.entries[0].device == "UUID=1234567890"
    assert fstab.entries[0].device_tag_type == "UUID"
    assert fstab.entries[0].device_tag_value == "1234567890"
    assert fstab.entries[0].dir == "/"
    assert fstab.entries[0].type == "ext4"
    assert fstab.entries[0].options == "rw,relatime"
    assert fstab.entries[0].dump == 0
    assert fstab.entries[0].fsck == 1

    assert fstab.entries[1].dir == "none"

    fstab.write_file(handle)

    handle.seek(0, 0)

    res = handle.read()

    assert res == normal_spaces_tight
Exemple #2
0
def test_fstab_repr():
    fstab = Fstab()
    assert repr(fstab) == "<Fstab [0 entries]>"

    fstab.read_string(comments)
    assert repr(fstab) == ("<Fstab [2 entries]\n"
                           "  UUID=1234567890 / ext4 rw,relatime 0 1\n"
                           "  UUID=1231231231 none swap defaults,pri=-2 0 0\n"
                           ">")
Exemple #3
0
def test_single_device_many_dirs():
    fstab = Fstab().read_string(single_device_many_dirs, only_valid=False)

    assert len(fstab.entries) == 2

    assert fstab.entries[0].device == "UUID=1234567890"
    assert fstab.entries[0].device_tag_type == "UUID"
    assert fstab.entries[0].device_tag_value == "1234567890"
Exemple #4
0
def test_many_devices_single_dir_only_valid():
    fstab = Fstab().read_string(many_devices_single_dir, only_valid=True)

    assert len(fstab.entries) == 1

    assert fstab.entries[0].device == "UUID=1231231231"
    assert fstab.entries[0].device_tag_type == "UUID"
    assert fstab.entries[0].device_tag_value == "1231231231"
Exemple #5
0
def test_many_devices_single_dir_filehandle():
    handle = io.StringIO(many_devices_single_dir)

    fstab = Fstab().read_file(handle, only_valid=False)

    assert len(fstab.entries) == 2

    assert fstab.entries[0].device == "UUID=1234567890"
    assert fstab.entries[0].device_tag_type == "UUID"
    assert fstab.entries[0].device_tag_value == "1234567890"
Exemple #6
0
def test_comments():
    fstab = Fstab().read_string(comments)

    assert len(fstab.entries) == 2

    assert fstab.entries[0].device == "UUID=1234567890"
    assert fstab.entries[0].device_tag_type == "UUID"
    assert fstab.entries[0].device_tag_value == "1234567890"
    assert fstab.entries[0].dir == "/"
    assert fstab.entries[0].type == "ext4"
    assert fstab.entries[0].options == "rw,relatime"
    assert fstab.entries[0].dump == 0
    assert fstab.entries[0].fsck == 1

    assert fstab.entries[1].dir == "none"
Exemple #7
0
def test_file_handle_read():
    handle = io.StringIO(comments)

    fstab = Fstab().read_file(handle)

    assert len(fstab.entries) == 2

    assert fstab.entries[0].device == "UUID=1234567890"
    assert fstab.entries[0].device_tag_type == "UUID"
    assert fstab.entries[0].device_tag_value == "1234567890"
    assert fstab.entries[0].dir == "/"
    assert fstab.entries[0].type == "ext4"
    assert fstab.entries[0].options == "rw,relatime"
    assert fstab.entries[0].dump == 0
    assert fstab.entries[0].fsck == 1

    assert fstab.entries[1].dir == "none"
Exemple #8
0
def test_bad_file():
    with pytest.raises(InvalidFstabLine):
        Fstab().read_string(bad_file)
Exemple #9
0
def test_empty():
    fstab = Fstab().read_string("")

    assert len(fstab.entries) == 0
Exemple #10
0
def test_fstab_bool():
    fstab = Fstab()
    assert not fstab

    fstab.read_string(comments)
    assert fstab