Skip to content

Commit

Permalink
Improve test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
areski committed Nov 13, 2014
1 parent 4b09b82 commit 2e67788
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docs/source/classes-doc/line-plus-bar-with-focus-chart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
:class:`linePlusBarWithFocusChart`
----------------------------------

.. autoclass:: LinePlusBarWithFocusChart
.. autoclass:: linePlusBarWithFocusChart
:noindex:

See the HTML source code of this page, to see the underlying javascript.
6 changes: 3 additions & 3 deletions examples/LinePlusBarWithFocusChart.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
Project location : https://github.com/areski/python-nvd3
"""

from nvd3.linePlusBarWithFocusChart import LinePlusBarWithFocusChart
from nvd3.linePlusBarWithFocusChart import linePlusBarWithFocusChart
import random
import datetime
import time
Expand All @@ -19,10 +19,10 @@
nb_element = 100

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

xdata = list(range(nb_element))
Expand Down
63 changes: 61 additions & 2 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
from nvd3 import discreteBarChart
from nvd3 import pieChart
from nvd3 import multiBarChart
from nvd3 import linePlusBarWithFocusChart
from nvd3.NVD3Chart import stab
from nvd3.translator import Function, AnonymousFunction, Assignment
import random
import unittest
Expand Down Expand Up @@ -52,6 +54,29 @@ def test_lineChart(self):
chart.add_serie(y=ydata, x=xdata)
chart.add_serie(y=ydata2, x=xdata)
chart.buildhtml()
#extra tests
chart.buildcontent()
chart.buildhtmlheader()

def test_lineChart_tooltip(self):
"""Test Line Chart"""
type = "lineChart"
chart = lineChart(name=type, date=True, height=350)
nb_element = 100
xdata = list(range(nb_element))
xdata = [1365026400000 + x * 100000 for x in xdata]
ydata = [i + random.randint(1, 10) for i in range(nb_element)]
ydata2 = [x * 2 for x in ydata]

kwargs1 = {'color': 'green'}
kwargs2 = {'color': 'red'}

extra_serie = {"tooltip": {"y_start": "There is ", "y_end": " random values"}}
chart.add_serie(name="Random X-Axis", y=ydata, x=xdata, extra=extra_serie, **kwargs1)
extra_serie = {"tooltip": {"y_start": "", "y_end": " double values"}}
chart.add_serie(name="Double X-Axis", y=ydata2, x=xdata, extra=extra_serie, **kwargs2)

chart.buildhtml()

def test_linePlusBarChart(self):
"""Test line Plus Bar Chart"""
Expand Down Expand Up @@ -89,7 +114,8 @@ def test_MultiBarChart(self):
nb_element = 10
xdata = list(range(nb_element))
ydata = [random.randint(1, 10) for i in range(nb_element)]
chart.add_serie(y=ydata, x=xdata)
extra = {"type": "bar", "yaxis": 1}
chart.add_serie(y=ydata, x=xdata, extra=extra)
chart.buildhtml()

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

def test_lineplusbarwithfocuschart(self):
"Test LinePlusBar With FocusChart"
type = "linePlusBarWithFocusChart"
chart = linePlusBarWithFocusChart(name=type, color_category='category20b',
x_is_date=True, x_axis_format="%d %b %Y")
chart.set_containerheader("\n\n<h2>" + type + "</h2>\n\n")
nb_element = 100
xdata = list(range(nb_element))
start_time = int(time.mktime(datetime.datetime(2012, 6, 1).timetuple()) * 1000)
#prepare series
xdata = [start_time + x * 1000000000 for x in xdata]
ydata = [i + random.randint(-10, 10) for i in range(nb_element)]
ydata2 = [200 - i + random.randint(-10, 10) for i in range(nb_element)]
extra_serie_1 = {
"tooltip": {"y_start": "$ ", "y_end": ""},
"date_format": "%d %b %Y",
}
kwargs = {"bar": "true"}
chart.add_serie(name="serie 1", y=ydata, x=xdata, extra=extra_serie_1, **kwargs)
extra_serie_2 = {
"tooltip": {"y_start": "$ ", "y_end": ""},
"date_format": "%d %b %Y",
}
chart.add_serie(name="serie 2", y=ydata2, x=xdata, extra=extra_serie_2)
chart.buildhtml()


class FuncTest(unittest.TestCase):

def test_stab(self):
self.assertEqual(" ", stab(1))


class TranslatorTest(unittest.TestCase):

Expand Down

0 comments on commit 2e67788

Please sign in to comment.