def test_without_lineage_sources(): def mk_sample(v): return dict(lineage={ 'source_datasets': v, 'a': 'a', 'b': 'b' }, aa='aa', bb=dict(bb='bb')) spec = mk_sample_product('tt') x = {'a': 1} assert without_lineage_sources(x, spec) == x assert without_lineage_sources(x, spec, inplace=True) == x x = {'a': 1, 'lineage': {}} assert without_lineage_sources(x, spec) == x assert without_lineage_sources(x, spec, inplace=True) == x x = mk_sample(1) assert without_lineage_sources(x, spec) != x assert x['lineage']['source_datasets'] == 1 x = mk_sample(2) assert without_lineage_sources(x, spec, inplace=True) == x assert x['lineage']['source_datasets'] == {} assert mk_sample(10) != mk_sample({}) assert without_lineage_sources(mk_sample(10), spec) == mk_sample({}) assert without_lineage_sources(mk_sample(10), spec, inplace=True) == mk_sample({}) # check behaviour when `sources` is not defined for the type no_sources_type = MetadataType( { 'name': 'eo', 'description': 'Sample', 'dataset': dict( id=['id'], label=['ga_label'], creation_time=['creation_dt'], measurements=['image', 'bands'], format=['format', 'name'], ) }, dataset_search_fields={}) assert without_lineage_sources(mk_sample(10), no_sources_type) == mk_sample(10) assert without_lineage_sources(mk_sample(10), no_sources_type, inplace=True) == mk_sample(10)
def metadata_doc_without_lineage(self) -> Dict[str, Any]: """ Return metadata document without nested lineage datasets """ return without_lineage_sources(self.metadata_doc, self.metadata_type)