def test_creator_parse(creators, data_file): """Test that different options for specifying creators work.""" dataset = Dataset(name="dataset", creators=creators) creator = Person(name="me", email="*****@*****.**") assert creator in dataset.creators # email check with pytest.raises(ValueError): Person(name="me", email="meexample.com") # creators must be a set or list of dicts or Person with pytest.raises(ValueError): Dataset(name="dataset", creators=["name"])
def create_dataset( self, short_name=None, title=None, description=None, creators=None, keywords=None, ): """Create a dataset.""" if not short_name: raise errors.ParameterError('Dataset short_name must be provided.') if not is_dataset_short_name_valid(short_name): raise errors.ParameterError( 'Dataset short_name "{}" is not valid.'.format(short_name)) if self.load_dataset(short_name=short_name): raise errors.DatasetExistsError( 'Dataset exists: "{}".'.format(short_name)) if not title: title = short_name identifier = str(uuid.uuid4()) path = self.renku_datasets_path / identifier / self.METADATA if path.exists(): raise errors.DatasetExistsError( 'Dataset with reference {} exists'.format(path)) path.parent.mkdir(parents=True, exist_ok=True) if creators is None: creators = [Person.from_git(self.repo)] keywords = keywords or () with with_reference(path): dataset = Dataset( client=self, identifier=identifier, short_name=short_name, name=title, description=description, creator=creators, keywords=keywords, ) dataset_ref = LinkReference.create(client=self, name='datasets/' + short_name) dataset_ref.set_reference(path) dataset.path = Path(dataset.path).relative_to(self.path) dataset.to_yaml() return dataset, path, dataset_ref
def test_creators_with_same_email(tmp_path): """Test creators with different names and same email address.""" creators = [Person(name="me", email="*****@*****.**"), Person(name="me2", email="*****@*****.**")] dataset = Dataset(name="dataset", creators=creators) path = tmp_path / "dataset.yml" dataset.__reference__ = path dataset.to_yaml() dataset = Dataset.from_yaml(path) assert 1 == len(dataset.creators) assert dataset.creators[0].name in ["me", "me2"]
def edit_dataset(client, dataset_id, transform_fn, commit_message=None): """Edit dataset metadata.""" dataset = client.load_dataset(dataset_id) if not dataset: raise DatasetNotFound() edited = yaml.safe_load(transform_fn(dataset)) updated_ = Dataset(client=client, **edited) dataset.update_metadata(updated_) dataset.to_yaml()
def create_dataset(self, name, short_name=None, description='', creators=None): """Create a dataset.""" if not name: raise errors.ParameterError('Dataset name must be provided.') if not short_name: short_name = generate_default_short_name(name, None) if not is_dataset_name_valid(short_name): raise errors.ParameterError( 'Dataset name "{}" is not valid.'.format(short_name)) if self.load_dataset(name=short_name): raise errors.DatasetExistsError( 'Dataset exists: "{}".'.format(short_name)) identifier = str(uuid.uuid4()) path = self.renku_datasets_path / identifier / self.METADATA if path.exists(): raise errors.DatasetExistsError( 'Dataset with reference {} exists'.format(path)) path.parent.mkdir(parents=True, exist_ok=True) if creators is None: creators = [Person.from_git(self.repo)] with with_reference(path): dataset = Dataset(client=self, identifier=identifier, name=name, short_name=short_name, description=description, creator=creators) dataset_ref = LinkReference.create(client=self, name='datasets/' + short_name) dataset_ref.set_reference(path) dataset.to_yaml() return dataset, path, dataset_ref