Exemplo n.º 1
0
    def assert_file_is_current(self, reference, requirements=[], **kw):
        """Assert that the file given by the ``reference`` pathname has been
        created or updated after the given list of ``requirement`` file names,
        raise :py:class:`UpdateNeeded` otherwise.

        :param str reference: The file path you want to check for being
            current.

        :param list requirements: The list of filenames you want to check
            against.

        :param dict kw: Arguments that are passed through to
            ``last_update`` which can be used to use different time stamps
            than ``st_mtime``. See
            :py:meth:`batou.lib.file.File.last_updated` for possible values.

        :return: ``None``, if ``reference`` is as new or newer as all
            ``requirements``.

        :raises UpdateNeeded: if the reference file is older than any of the
            ``requirements``.

        """
        from batou.lib.file import Presence
        reference = Presence(reference)
        self |= reference
        reference.assert_component_is_current(
            [Presence(r) for r in requirements], **kw)
Exemplo n.º 2
0
 def verify(self):
     self.assert_file_is_current("bin/buildout")
     # XXX we can't be sure that all config objects are files!
     installed = Presence(".installed.cfg")
     self |= installed
     installed.assert_component_is_current([Presence("bin/buildout")] +
                                           self.config)
     self.assert_file_is_current(".batou.buildout.success",
                                 [".installed.cfg"])
     self.assert_no_subcomponent_changes()
Exemplo n.º 3
0
def test_presence_leaves_existing_file_with_content_intact(root):
    p = Presence("path")
    root.component += p
    with open(p.path, "w") as f:
        f.write("Hello there!")
    root.component.deploy()
    with open(p.path) as f:
        assert f.read() == "Hello there!"
Exemplo n.º 4
0
def test_presence_removes_conflicting_directories(root):
    p = Presence("dir")
    root.component += p
    os.mkdir(p.path)
    root.component.deploy()
    assert not os.path.isdir(p.path)
    with open(p.path) as f:
        assert f.read() == ""
Exemplo n.º 5
0
def test_presence_removes_conflicting_symlinks(root):
    p = Presence("link")
    root.component += p
    os.symlink("target", p.path)
    assert os.path.islink(p.path)
    with pytest.raises(IOError):
        open(p.path)
    root.component.deploy()
    assert not os.path.islink(p.path)
    with open(p.path) as f:
        assert f.read() == ""
Exemplo n.º 6
0
def test_presence_doesnt_create_directories_by_default(root):
    root.component += Presence("directory/file")
    with pytest.raises(IOError):
        root.component.deploy()
Exemplo n.º 7
0
def test_presence_creates_directories_if_configured(root):
    p = Presence("directory/file", leading=True)
    root.component += p
    root.component.deploy()
    with open(p.path) as f:
        assert f.read() == ""
Exemplo n.º 8
0
def test_presence_creates_nonexisting_file(root):
    p = Presence("path")
    root.component += p
    root.component.deploy()
    with open(p.path) as f:
        assert f.read() == ""