Skip to content

Commit 1c45b3f

Browse files
committed
Reintroduces tests for data normalizer
1 parent ea26761 commit 1c45b3f

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
@@ -3,6 +3,10 @@
33
import matplotlib.dates as mdates
44
import mplaltair._data as _data
55
import pytest
6+
from vega_datasets import data
7+
8+
from mplaltair._data import _normalize_data
9+
from mplaltair._exceptions import ValidationError
610

711
df = pd.DataFrame({
812
"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],
@@ -13,6 +17,36 @@
1317
"quantitative": [1.1, 2.1, 3.1, 4.1, 5.1]
1418
})
1519

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

1751
# _locate_channel_data() tests
1852

0 commit comments

Comments
 (0)