-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_faq_python.py
More file actions
51 lines (42 loc) · 1.43 KB
/
test_faq_python.py
File metadata and controls
51 lines (42 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import unittest
import datetime
import matplotlib
from teachpyx.faq.faq_python import (
class_getitem,
get_day_name,
get_month_name,
graph_sankey,
)
matplotlib.use("Agg")
class TestFaqPython(unittest.TestCase):
def test_month_name(self):
dt = datetime.datetime(2016, 1, 25)
name = get_month_name(dt)
self.assertEqual(name, "January")
def test_day_name(self):
dt = datetime.datetime(2016, 1, 25)
name = get_day_name(dt)
self.assertEqual(name, "Monday")
def test_class_getitem(self):
class_getitem()
def test_graph_sankey(self):
ax, diagrams = graph_sankey(
[1, -0.25, -0.75],
labels=["input", "loss", "output"],
orientations=[0, 1, -1],
trunklength=2.0,
title="flux",
)
self.assertEqual(ax.get_title(), "flux")
self.assertEqual(len(diagrams), 1)
def test_graph_sankey_errors(self):
with self.assertRaisesRegex(ValueError, "at least two values"):
graph_sankey([1])
with self.assertRaisesRegex(ValueError, "must be 0"):
graph_sankey([1, -0.5])
with self.assertRaisesRegex(ValueError, "same length"):
graph_sankey([1, -1], labels=["only_one"])
with self.assertRaisesRegex(ValueError, "same length"):
graph_sankey([1, -1], orientations=[0, 1, -1])
if __name__ == "__main__":
unittest.main()