Skip to content

Commit 7cb183f

Browse files
authored
Update Plot test, pyproject.toml and README.md (#27)
1 parent fcf62a6 commit 7cb183f

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed
Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,36 @@
1+
import json
12
import unittest
23

4+
import pandas as pd
5+
import altair as alt
6+
7+
from dashipy.components import Plot
8+
39

410
class PlotTest(unittest.TestCase):
11+
def setUp(self):
12+
dataset = pd.DataFrame(
13+
{"x": ["A", "B", "C", "D", "E"], "a": [28, 55, 43, 91, 81]}
14+
)
15+
self.chart = (
16+
alt.Chart(dataset)
17+
.mark_bar()
18+
.encode(
19+
x=alt.X("x:N", title="x"),
20+
y=alt.Y("a:Q", title="a"),
21+
)
22+
)
523

624
def test_is_json_serializable(self):
7-
pass
25+
26+
plot = Plot(id="plot", chart=self.chart)
27+
p = plot.to_dict()
28+
29+
print(p)
30+
self.assertIsInstance(p, dict)
31+
self.assertEqual(p["type"], "Plot")
32+
self.assertIsInstance(p["chart"], dict)
33+
self.assertEqual(p["chart"]["mark"], {"type": "bar"})
34+
json_text = json.dumps(p)
35+
self.assertEqual("{", json_text[0])
36+
self.assertEqual("}", json_text[-1])

0 commit comments

Comments
 (0)