def test_bind_overwrite(): context = Context() context.bind('a', lambda: 1) with pytest.raises(Exception) as e: context.bind('a', lambda: 2) assert str(e.value) == "Context variable 'a' has been already set." assert context.get('a') == 1
def pull(context: Context, dataset: Dataset, *, models: list = None): with context.enter(): tmpdir = context.attach( tempfile.TemporaryDirectory(prefix='spinta-pull-cache-')) context.bind('cache', Cache, path=pathlib.Path(tmpdir)) context.bind('requests', requests.Session) for model in dataset.objects.values(): if model.source is None: continue if models and model.name not in models: continue for dependency in _dependencies(context, model, model.dependencies): for source in model.source.commands: try: yield from _pull(context, model, source, dependency) except Exception as e: context.error( f"Error while pulling model {model.name!r}, with dependency: {dependency!r} and source: {source!r}. Error: {e}" )