示例#1
0
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
示例#2
0
def _download_datasets():
    """Utility to download datasets into package source"""
    def filepath(*args):
        return abspath(join(dirname(__file__), '..', 'vega_datasets', *args))
    dataset_listing = {}
    for name in DATASETS_TO_DOWNLOAD:
        data = Dataset(name)
        url = data.url
        filename = filepath('data', data.filename)
        print("retrieving data {0} -> {1}".format(url, filename))
        urlretrieve(url, filename)
        dataset_listing[name] = 'data/{0}'.format(data.filename)
    with open(filepath('local_datasets.json'), 'w') as f:
        json.dump(dataset_listing, f, indent=2)
def _download_datasets():
    """Utility to download datasets into package source"""
    def filepath(*args):
        return abspath(join(dirname(__file__), "..", "vega_datasets", *args))

    dataset_listing = {}
    for name in DATASETS_TO_DOWNLOAD:
        data = Dataset(name)
        url = data.url
        filename = filepath("_data", data.filename)
        print("retrieving data {0} -> {1}".format(url, filename))
        urlretrieve(url, filename)
        dataset_listing[name] = "_data/{0}".format(data.filename)
    with open(filepath("local_datasets.json"), "w") as f:
        json.dump(dataset_listing, f, indent=2, sort_keys=True)
示例#4
0
def test_local_data_dirlist():
    assert set(dir(local_data)) == {
        name.replace("-", "_")
        for name in Dataset.list_local_datasets()
    }
import pandas as pd
from pandas.testing import assert_frame_equal
import pytest

from vega_datasets import data, local_data
from vega_datasets.core import Dataset


@pytest.mark.parametrize("name", Dataset.list_local_datasets())
def test_load_local_dataset(name):
    loader = getattr(data, name.replace("-", "_"))
    local_loader = getattr(local_data, name.replace("-", "_"))

    df1 = data(name)
    df2 = loader()  # equivalent to data.dataset_name()
    df3 = local_data(name)
    df4 = local_loader()  # equivalent to local_data.dataset_name()
    assert_frame_equal(df1, df2)
    assert_frame_equal(df1, df3)
    assert_frame_equal(df1, df4)

    raw1 = loader.raw()
    raw2 = local_loader.raw()
    raw3 = data(name, return_raw=True)
    raw4 = local_data(name, return_raw=True)
    assert raw1 == raw2 == raw3 == raw4
    assert type(raw1) is type(raw2) is type(raw3) is type(raw4) is bytes


def test_iris_column_names():
    iris = data.iris()
示例#6
0
文件: alt.py 项目: wannaphong/kora
 def __init__(self, name):
     Dataset.__init__(self, name)
     self.url = 'https://raw.githubusercontent.com/korakot/thailand-hex-map/master/data/thailand-topo.json'
def test_undefined_infodict():
    with pytest.raises(ValueError) as err:
        Dataset._infodict("blahblahblah")
    assert str(err.value).startswith("No such dataset blahblahblah exists")
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("-", "_")))
示例#9
0
def test_undefined_infodict():
    with pytest.raises(ValueError) as err:
        info = Dataset._infodict('blahblahblah')
    assert str(err.value).startswith('No such dataset blahblahblah exists')