Пример #1
0
    def deploy(self, predict_only=False):
        # Remember: this is a tight loop - we need to keep this code fast.

        # Reset changed flag here to support triggering deploy() multiple
        # times. This is mostly helpful for testing, but who knows.
        self.changed = False
        for sub_component in self.sub_components:
            sub_component.deploy(predict_only)
            if sub_component.changed:
                self.changed = True

        output.buffer("annotate", self.host.name + " > " + self._breadcrumbs)

        if not os.path.exists(self.workdir):
            os.makedirs(self.workdir)
        with self.chdir(self.workdir), self:
            try:
                with batou.utils.Timer("{} verify()".format(
                        self._breadcrumbs)):
                    call_with_optional_args(self.verify,
                                            predicting=predict_only)
            except AssertionError:
                self.__trigger_event__("before-update",
                                       predict_only=predict_only)
                output.flush_buffer()
                if not predict_only:
                    self.update()
                self.changed = True

        output.clear_buffer()
Пример #2
0
def test_call_with_optional_args():
    def foo():
        return 1

    def bar(x):
        return x

    def baz(**kw):
        return kw["x"]

    def quux(x, y):
        return x

    # The function doesn't expect x, but we're happy to call it.
    assert call_with_optional_args(foo, x=1)
    # The function expect x and it gets passed through
    assert call_with_optional_args(bar, x=4) == 4
    # The function accepts kw args and sees x
    assert call_with_optional_args(baz, x=3) == 3
    # The function accepts x but also expects y and thus breaks
    with pytest.raises(TypeError):
        call_with_optional_args(quux, x=1)