def test_metadata(): all_datasets = Dataset.list_datasets() local_datasets = Dataset.list_local_datasets() for name in all_datasets: dataobj = getattr(data, name.replace("-", "_")) if name in local_datasets: # Local datasets should all have a description defined assert len(dataobj.description) > 0 assert len(dataobj.filepath) > 0 else: with pytest.raises(ValueError) as err: dataobj.filepath assert str( err.value) == "filepath is only valid for local datasets" # Descriptions should either be defined, or be None assert dataobj.description is None or len(dataobj.description) > 0 # References should either be a list, or be None assert dataobj.references is None or type(dataobj.references) is list
import pytest from vega_datasets import data, local_data from vega_datasets.core import Dataset def test_undefined_dataset(): with pytest.raises(AttributeError) as err: data("blahblahblah") assert str(err.value) == "No dataset named 'blahblahblah'" with pytest.raises(AttributeError) as err: local_data("blahblahblah") assert str(err.value) == "No dataset named 'blahblahblah'" def test_undefined_infodict(): with pytest.raises(ValueError) as err: Dataset._infodict("blahblahblah") assert str(err.value).startswith("No such dataset blahblahblah exists") @pytest.mark.parametrize( "name", (set(Dataset.list_datasets()) - set(Dataset.list_local_datasets()))) def test_local_dataset_error(name): with pytest.raises(ValueError) as err: local_data(name) assert str(err.value).startswith("'{0}' dataset is not available locally" "".format(name.replace("-", "_")))