Beispiel #1
0
def test_filerecord_check_if_must_change_no_file_or_content(tmpdir):
    """
    If there's no file at the path specified and the FileRecord indicates the
    file shouldn't exist, then nothing must change.
    """
    p = tmpdir.join('f')
    fr = runit_sv.FileRecord(p.strpath, 0, content=None)
    fr.check_if_must_change()
    assert not fr.must_change
Beispiel #2
0
def test_filerecord_propagates_unlink_exceptions(tmpdir):
    """
    If the unlink call in FileRecord's commit method raises an exception that
    isn't ENOENT, it will be propagated upward.
    """
    d = tmpdir.join('d')
    d.mkdir()
    fr = runit_sv.FileRecord(d.strpath, 0o644)
    fr.must_change = True
    with pytest.raises(OSError):
        fr.commit()
Beispiel #3
0
def test_filerecord_check_if_must_change(tmpdir, ops, content,
                                         content_expected, set_mode,
                                         check_mode, mode_expected):
    """
    FileRecord objects will indicate if their desired state is not the same as
    their referenced path's current state. The file's mode and content are
    independently considered as criteria for if the state must change.
    """
    p = make_path(tmpdir, ops, mode=set_mode)
    fr = runit_sv.FileRecord(p, check_mode, content)
    fr.check_if_must_change()
    assert fr.must_change == (content_expected or mode_expected)
Beispiel #4
0
def test_filerecord_commit(tmpdir, initial_state, mode, content, must_change):
    """
    FileRecord objects will make their referenced path's state match the
    desired state via the commit method, but only if must_change is true.
    """
    p = make_path(tmpdir, initial_state)
    fr = runit_sv.FileRecord(p, mode, content)
    fr.must_change = must_change
    fr.commit()
    pp = py.path.local(p)
    if must_change:
        if content is None:
            assert not pp.exists()
        else:
            assert pp.read() == content
            assert pp.stat().mode & runit_sv.SETTABLE_MASK == mode
        assert fr.changed
    else:
        assert not fr.changed
Beispiel #5
0
def test_filerecord_commit_content_true(tmpdir, initial_state, mode,
                                        must_change):
    """
    A FileRecord with a content of True will ensure the existence of the file
    and the mode of the file, but will not change the content of the file.
    """
    p = make_path(tmpdir, initial_state)
    pp = py.path.local(p)
    fr = runit_sv.FileRecord(p, mode, True)
    fr.must_change = must_change
    if pp.exists():
        content_before = pp.read()
        fr.commit()
    elif must_change:
        with pytest.raises(runit_sv.FileDoesNotExistError):
            fr.commit()
        return

    if must_change:
        assert pp.read() == content_before
        assert pp.stat().mode & runit_sv.SETTABLE_MASK == mode
        assert fr.changed
    else:
        assert not fr.changed
Beispiel #6
0
def test_filerecord_repr(path, mode, content, expected):
    """
    FileRecord has a predictable __repr__.
    """
    fr = runit_sv.FileRecord(path, mode, content)
    assert repr(fr) == expected.format(hex(id(fr)))