Beispiel #1
0
    def _render_product(self):
        params_names = list(self.params)

        # add upstream product identifiers to params, if any
        # Params are read-only for users, but we have to add upstream
        # dependencies so we do it directly to the dictionary
        if self.upstream:
            self.params._setitem(
                'upstream',
                Upstream({n: t.product
                          for n, t in self.upstream.items()},
                         name=self.name))

        # render the current product
        try:
            # using the upstream products to define the current product
            # is optional, using the parameters passed in params is also
            # optional
            self.product.render(self.params,
                                optional=set(params_names + ['upstream']))
        except Exception as e:
            raise type(e)('Error rendering Product from Task "{}", '
                          ' check the full traceback above for details'.format(
                              repr(self))) from e

        try:
            self.product.download()
        except Exception as e:
            raise TaskRenderError(
                f'Error downloading Product {self.product!r} '
                f'from task {self!r}. Check the full traceback above for '
                'details') from e
Beispiel #2
0
def test_error_if_missing_upstream():
    p = Placeholder('SELECT * FROM {{upstream["name"]}}')
    upstream = Upstream({'a': 1}, name='task')

    with pytest.raises(UpstreamKeyError) as excinfo:
        p.render({'upstream': upstream})

    assert ('Cannot obtain upstream dependency "name" for task "task"'
            in str(excinfo.value))
Beispiel #3
0
def test_shows_warning_if_unused_parameters():
    p = Upstream()

    p['a'] = 0
    p['b'] = 1

    with pytest.warns(UserWarning):
        with p:
            p['a']
Beispiel #4
0
def test_error_if_no_upstream():
    p = Placeholder('SELECT * FROM {{upstream["name"]}}')
    upstream = Upstream({}, name='task')

    with pytest.raises(UpstreamKeyError) as excinfo:
        p.render({'upstream': upstream})

    msg = ('Cannot obtain upstream dependency "name". '
           'Task "task" has no upstream dependencies')
    assert msg == str(excinfo.value)
Beispiel #5
0
    def _render_product(self):
        params_names = list(self.params)

        # add upstream product identifiers to params, if any
        # Params are read-only for users, but we have to add upstream
        # dependencies so we do it directly to the dictionary
        # TODO: process wilcards such as fit-*
        if self.upstream:
            self.params._setitem(
                'upstream',
                Upstream(self._upstream_product_grouped, name=self.name))

        # render the current product
        try:
            # using the upstream products to define the current product
            # is optional, using the parameters passed in params is also
            # optional
            self.product.render(self.params,
                                optional=set(params_names + ['upstream']))
        except Exception as e:
            raise type(e)('Error rendering Product from Task "{}", '
                          ' check the full traceback above for details'.format(
                              repr(self))) from e
Beispiel #6
0
def test_can_get_first():
    p = Upstream()

    p['a'] = 0

    assert p.first == 0