Skip to content

Commit 15039e3

Browse files
committed
Improves test coverage
* Refactors tests * Adds more tests
1 parent 6e05448 commit 15039e3

File tree

1 file changed

+32
-7
lines changed

1 file changed

+32
-7
lines changed

mplaltair/tests/test_convert.py

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,22 @@
55

66
from mplaltair import convert
77

8-
df = pd.DataFrame({'quant': [1, 1.5, 2], 'ord': [0, 1, 2], 'nom': ['A', 'B', 'C']})
8+
df = pd.DataFrame({
9+
'quant': [1, 1.5, 2],
10+
'ord': [0, 1, 2],
11+
'nom': ['A', 'B', 'C'],
12+
'temp': [10, 20, 30]
13+
})
14+
15+
def test_encoding_not_provided():
16+
chart_spec = alt.Chart(df).mark_point().to_dict()
17+
with pytest.raises(ValueError):
18+
convert(chart_spec)
19+
20+
def test_invalid_encodings():
21+
chart_spec = alt.Chart(df).encode(x2='quant').mark_point().to_dict()
22+
with pytest.raises(ValueError):
23+
convert(chart_spec)
924

1025
@pytest.mark.parametrize('channel', ['quant', 'ord', 'nom'])
1126
def test_convert_x_success(channel):
@@ -45,9 +60,9 @@ def test_convert_color_fail():
4560
with pytest.raises(KeyError):
4661
convert(chart_spec)
4762

48-
@pytest.mark.parametrize('channel', ['quant', 'ord'])
49-
def test_convert_fill(channel):
50-
chart_spec = alt.Chart(df).encode(fill=channel).mark_point().to_dict()
63+
@pytest.mark.parametrize('channel,type', [('quant', 'Q'), ('ord', 'O')])
64+
def test_convert_fill(channel, type):
65+
chart_spec = alt.Chart(df).encode(fill='{}:{}'.format(channel, type)).mark_point().to_dict()
5166
mapping = convert(chart_spec)
5267
assert list(mapping['c']) == list(df[channel].values)
5368

@@ -56,14 +71,19 @@ def test_convert_fill_success_nominal():
5671
with pytest.raises(NotImplementedError):
5772
convert(chart_spec)
5873

74+
def test_convert_fill_success_temporal():
75+
chart_spec = alt.Chart(df).encode(fill='temp:T').mark_point().to_dict()
76+
with pytest.raises(NotImplementedError):
77+
convert(chart_spec)
78+
5979
def test_convert_fill_fail():
6080
chart_spec = alt.Chart(df).encode(fill='b:N').mark_point().to_dict()
6181
with pytest.raises(KeyError):
6282
convert(chart_spec)
6383

64-
@pytest.mark.parametrize('channel', ['quant', 'ord'])
65-
def test_convert_size_success(channel):
66-
chart_spec = alt.Chart(df).encode(size=channel).mark_point().to_dict()
84+
@pytest.mark.parametrize('channel,type', [('quant', 'Q'), ('ord', 'O')])
85+
def test_convert_size_success(channel, type):
86+
chart_spec = alt.Chart(df).encode(size='{}:{}'.format(channel, type)).mark_point().to_dict()
6787
mapping = convert(chart_spec)
6888
assert list(mapping['s']) == list(df[channel].values)
6989

@@ -72,6 +92,11 @@ def test_convert_size_success_nominal():
7292
with pytest.raises(NotImplementedError):
7393
convert(chart_spec)
7494

95+
def test_convert_size_success_temporal():
96+
chart_spec = alt.Chart(df).encode(size='temp:T').mark_point().to_dict()
97+
with pytest.raises(NotImplementedError):
98+
convert(chart_spec)
99+
75100
def test_convert_size_fail():
76101
chart_spec = alt.Chart(df).encode(size='b:N').mark_point().to_dict()
77102
with pytest.raises(KeyError):

0 commit comments

Comments
 (0)