Ejemplo n.º 1
0
def test_dataset_3(test_data):
    with pytest.raises(RuntimeError, match='is not a legal path'):
        Dataset.from_http(test_data[1], 'not_exist')

    tmp = Dataset.from_http(test_data[1], save_to=test_data[2])
    assert tmp == str(test_data[2] / 'fetch_test.txt')
    assert Path(tmp).exists()
    with open(tmp, 'r') as f:
        assert f.readline() == 'Test xenonpy.utils.Loader._fetch_data'

    tmp = Dataset.from_http(test_data[1], save_to=test_data[2], filename=test_data[0])
    assert tmp == str(test_data[2] / 'rename.txt')
    assert Path(tmp).exists()
    with open(tmp, 'r') as f:
        assert f.readline() == 'Test xenonpy.utils.Loader._fetch_data'
Ejemplo n.º 2
0
def test_dataset_1(test_data):
    path = Path(__file__).parents[0]

    ds = Dataset()
    assert ds._backend == 'pandas'
    assert ds._paths == ('.', )
    assert ds._prefix == ()

    with pytest.warns(RuntimeWarning):
        Dataset(str(path), str(path))

    with pytest.raises(RuntimeError):
        Dataset('no_exist_dir')

    ds = Dataset(str(path), backend='pickle', prefix=('datatools', ))
    assert hasattr(ds, 'datatools_test')
    tmp = '%s' % ds
    assert 'Dataset' in tmp
Ejemplo n.º 3
0
def test_dataset_2(test_data):
    path = Path(__file__).parents[0]

    ds = Dataset(str(path), backend='pickle')
    assert hasattr(ds, 'test')

    tmp = ds.test
    assert isinstance(tmp, list)
    assert tmp == [[1, 2], [3, 4]]

    tmp = ds.csv
    assert hasattr(tmp, 'test')
    tmp = tmp.test
    assert isinstance(tmp, pd.DataFrame)
    assert np.all(np.array([[0, 1, 2], [1, 3, 4]]) == tmp.values)

    tmp = ds.csv(str(path / 'test.csv'))
    assert np.all(np.array([[0, 1, 2], [1, 3, 4]]) == tmp.values)

    tmp = ds.pandas
    assert hasattr(tmp, 'test')
    tmp = tmp.test
    assert isinstance(tmp, pd.DataFrame)
    assert np.all(np.array([[1, 2], [3, 4]]) == tmp.values)

    tmp = ds.pandas(str(path / 'test.pd.xz'))
    assert np.all(np.array([[1, 2], [3, 4]]) == tmp.values)

    tmp = ds.pickle
    assert hasattr(tmp, 'test')
    tmp = tmp.test
    assert isinstance(tmp, list)
    assert [[1, 2], [3, 4]] == tmp

    tmp = ds.pickle(str(path / 'test.pkl.z'))
    assert [[1, 2], [3, 4]] == tmp
Ejemplo n.º 4
0
def test_dateset_4(test_data):
    file_path = test_data[2]
    data = pd.DataFrame([[1, 2], [3, 4]])

    file = file_path / 'test.pd'
    Dataset.to(data, file)
    assert file.exists()

    file = file_path / 'test.str'
    Dataset.to(data, str(file))
    assert file.exists()

    file = file_path / 'test.pkl'
    Dataset.to(data.values, file)
    assert file.exists()