Skip to content

Commit d62795e

Browse files
committed
Reintroduces tests for data normalizer
1 parent b79c3c2 commit d62795e

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

mplaltair/tests/test_data.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
import pandas as pd
33
import mplaltair._data as _data
44
import pytest
5+
from vega_datasets import data
6+
7+
from mplaltair._data import _normalize_data
8+
from mplaltair._exceptions import ValidationError
59

610
df = pd.DataFrame({
711
"a": [1, 2, 3, 4, 5], "b": [1.1, 2.2, 3.3, 4.4, 5.5], "c": [1, 2.2, 3, 4.4, 5],
@@ -12,6 +16,36 @@
1216
"quantitative": [1.1, 2.1, 3.1, 4.1, 5.1]
1317
})
1418

19+
def test_data_list():
20+
spec = {
21+
"data": {
22+
"values": [{"a": 1, "b": 2}, {"c": 3, "d": 4}]
23+
24+
}
25+
}
26+
assert type(_normalize_data(spec)["data"]) == pd.DataFrame
27+
28+
def test_data_url():
29+
spec = {
30+
"data": {
31+
"url": data.cars.url
32+
}
33+
}
34+
assert type(_normalize_data(spec)["data"]) == pd.DataFrame
35+
36+
def test_data_no_pass():
37+
spec = {}
38+
with pytest.raises(ValidationError):
39+
_normalize_data(spec)
40+
41+
def test_data_invalid():
42+
spec = {
43+
"data": {
44+
"source": "path"
45+
}
46+
}
47+
with pytest.raises(NotImplementedError):
48+
_normalize_data(spec)
1549

1650
# _locate_channel_data() tests
1751

0 commit comments

Comments
 (0)