Skip to content

Commit 2e67788

Browse files
committed
Improve test coverage
1 parent 4b09b82 commit 2e67788

3 files changed

Lines changed: 65 additions & 6 deletions

File tree

‎docs/source/classes-doc/line-plus-bar-with-focus-chart.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
:class:`linePlusBarWithFocusChart`
66
----------------------------------
77

8-
.. autoclass:: LinePlusBarWithFocusChart
8+
.. autoclass:: linePlusBarWithFocusChart
99
:noindex:
1010

1111
See the HTML source code of this page, to see the underlying javascript.

‎examples/LinePlusBarWithFocusChart.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
Project location : https://github.com/areski/python-nvd3
1010
"""
1111

12-
from nvd3.linePlusBarWithFocusChart import LinePlusBarWithFocusChart
12+
from nvd3.linePlusBarWithFocusChart import linePlusBarWithFocusChart
1313
import random
1414
import datetime
1515
import time
@@ -19,10 +19,10 @@
1919
nb_element = 100
2020

2121
#Open File for test
22-
output_file = open('test_LinePlusBarWithFocusChart.html', 'w')
22+
output_file = open('test_linePlusBarWithFocusChart.html', 'w')
2323
#---------------------------------------
2424
type = "linePlusBarWithFocusChart"
25-
chart = LinePlusBarWithFocusChart(name=type, color_category='category20b', x_is_date=True, x_axis_format="%d %b %Y")
25+
chart = linePlusBarWithFocusChart(name=type, color_category='category20b', x_is_date=True, x_axis_format="%d %b %Y")
2626
chart.set_containerheader("\n\n<h2>" + type + "</h2>\n\n")
2727

2828
xdata = list(range(nb_element))

‎tests.py‎

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
from nvd3 import discreteBarChart
1212
from nvd3 import pieChart
1313
from nvd3 import multiBarChart
14+
from nvd3 import linePlusBarWithFocusChart
15+
from nvd3.NVD3Chart import stab
1416
from nvd3.translator import Function, AnonymousFunction, Assignment
1517
import random
1618
import unittest
@@ -52,6 +54,29 @@ def test_lineChart(self):
5254
chart.add_serie(y=ydata, x=xdata)
5355
chart.add_serie(y=ydata2, x=xdata)
5456
chart.buildhtml()
57+
#extra tests
58+
chart.buildcontent()
59+
chart.buildhtmlheader()
60+
61+
def test_lineChart_tooltip(self):
62+
"""Test Line Chart"""
63+
type = "lineChart"
64+
chart = lineChart(name=type, date=True, height=350)
65+
nb_element = 100
66+
xdata = list(range(nb_element))
67+
xdata = [1365026400000 + x * 100000 for x in xdata]
68+
ydata = [i + random.randint(1, 10) for i in range(nb_element)]
69+
ydata2 = [x * 2 for x in ydata]
70+
71+
kwargs1 = {'color': 'green'}
72+
kwargs2 = {'color': 'red'}
73+
74+
extra_serie = {"tooltip": {"y_start": "There is ", "y_end": " random values"}}
75+
chart.add_serie(name="Random X-Axis", y=ydata, x=xdata, extra=extra_serie, **kwargs1)
76+
extra_serie = {"tooltip": {"y_start": "", "y_end": " double values"}}
77+
chart.add_serie(name="Double X-Axis", y=ydata2, x=xdata, extra=extra_serie, **kwargs2)
78+
79+
chart.buildhtml()
5580

5681
def test_linePlusBarChart(self):
5782
"""Test line Plus Bar Chart"""
@@ -89,7 +114,8 @@ def test_MultiBarChart(self):
89114
nb_element = 10
90115
xdata = list(range(nb_element))
91116
ydata = [random.randint(1, 10) for i in range(nb_element)]
92-
chart.add_serie(y=ydata, x=xdata)
117+
extra = {"type": "bar", "yaxis": 1}
118+
chart.add_serie(y=ydata, x=xdata, extra=extra)
93119
chart.buildhtml()
94120

95121
def test_multiBarHorizontalChart(self):
@@ -154,7 +180,8 @@ def test_pieChart(self):
154180
type = "pieChart"
155181
chart = pieChart(name=type, color_category='category20c', height=400, width=400)
156182
xdata = ["Orange", "Banana", "Pear", "Kiwi", "Apple", "Strawberry", "Pineapple"]
157-
extra_serie = {"tooltip": {"y_start": "", "y_end": " cal"}}
183+
color_list = ['orange', 'yellow', '#C5E946', '#95b43f', 'red', '#FF2259', '#F6A641']
184+
extra_serie = {"tooltip": {"y_start": "", "y_end": " cal"}, "color_list": color_list}
158185
ydata = [3, 4, 0, 1, 5, 7, 3]
159186
chart.add_serie(y=ydata, x=xdata, extra=extra_serie)
160187
chart.buildhtml()
@@ -168,6 +195,38 @@ def test_donutPieChart(self):
168195
chart.add_serie(y=ydata, x=xdata)
169196
chart.buildhtml()
170197

198+
def test_lineplusbarwithfocuschart(self):
199+
"Test LinePlusBar With FocusChart"
200+
type = "linePlusBarWithFocusChart"
201+
chart = linePlusBarWithFocusChart(name=type, color_category='category20b',
202+
x_is_date=True, x_axis_format="%d %b %Y")
203+
chart.set_containerheader("\n\n<h2>" + type + "</h2>\n\n")
204+
nb_element = 100
205+
xdata = list(range(nb_element))
206+
start_time = int(time.mktime(datetime.datetime(2012, 6, 1).timetuple()) * 1000)
207+
#prepare series
208+
xdata = [start_time + x * 1000000000 for x in xdata]
209+
ydata = [i + random.randint(-10, 10) for i in range(nb_element)]
210+
ydata2 = [200 - i + random.randint(-10, 10) for i in range(nb_element)]
211+
extra_serie_1 = {
212+
"tooltip": {"y_start": "$ ", "y_end": ""},
213+
"date_format": "%d %b %Y",
214+
}
215+
kwargs = {"bar": "true"}
216+
chart.add_serie(name="serie 1", y=ydata, x=xdata, extra=extra_serie_1, **kwargs)
217+
extra_serie_2 = {
218+
"tooltip": {"y_start": "$ ", "y_end": ""},
219+
"date_format": "%d %b %Y",
220+
}
221+
chart.add_serie(name="serie 2", y=ydata2, x=xdata, extra=extra_serie_2)
222+
chart.buildhtml()
223+
224+
225+
class FuncTest(unittest.TestCase):
226+
227+
def test_stab(self):
228+
self.assertEqual(" ", stab(1))
229+
171230

172231
class TranslatorTest(unittest.TestCase):
173232

0 commit comments

Comments
 (0)