-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
First PR for Gantt Charts - Adding Tests Very Soon #460
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
0eeae61
fe67a2b
e228307
e7a1596
3035dba
675ba7d
29dbb44
6671106
7ac7d9b
f165b73
00f8162
66382e2
86f61bc
abff982
e6aa0e4
3b75d48
cfa066e
ba65217
9e52ce4
ac64ff3
b28f040
866f5c9
2142397
bfbe24c
afd45a1
3ac0da4
0ab3ad1
a7be116
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1125,6 +1125,246 @@ def test_table_with_index(self): | |
'zeroline': False}}} | ||
self.assertEqual(index_table, exp_index_table) | ||
|
||
|
||
class TestGantt(TestCase): | ||
|
||
def test_validate_gantt(self): | ||
|
||
# validate the basic gantt inputs | ||
|
||
df = [{'Task': 'Job A', | ||
'Start': '2009-02-01', | ||
'Finish': '2009-08-30', | ||
'Complete': 'a'}] | ||
|
||
pattern2 = ('In order to use an indexing column and assign colors to ' | ||
'the values of the index, you must choose an actual ' | ||
'column name in the dataframe or key if a list of ' | ||
'dictionaries is being used.') | ||
|
||
self.assertRaisesRegexp(PlotlyError, pattern2, | ||
tls.FigureFactory.create_gantt, | ||
df, index_col='foo') | ||
|
||
df = 'foo' | ||
|
||
pattern3 = ('You must input either a dataframe or a list of ' | ||
'dictionaries.') | ||
|
||
self.assertRaisesRegexp(PlotlyError, pattern3, | ||
tls.FigureFactory.create_gantt, df) | ||
|
||
df = [] | ||
|
||
pattern4 = ('Your list is empty. It must contain at least one ' | ||
'dictionary.') | ||
|
||
self.assertRaisesRegexp(PlotlyError, pattern4, | ||
tls.FigureFactory.create_gantt, df) | ||
|
||
df = ['foo'] | ||
|
||
pattern5 = ('Your list must only include dictionaries.') | ||
|
||
self.assertRaisesRegexp(PlotlyError, pattern5, | ||
tls.FigureFactory.create_gantt, df) | ||
|
||
def test_gantt_index(self): | ||
|
||
# validate the index used for gantt | ||
|
||
df = [{'Task': 'Job A', | ||
'Start': '2009-02-01', | ||
'Finish': '2009-08-30', | ||
'Complete': 50}] | ||
|
||
pattern = ('In order to use an indexing column and assign colors to ' | ||
'the values of the index, you must choose an actual ' | ||
'column name in the dataframe or key if a list of ' | ||
'dictionaries is being used.') | ||
|
||
self.assertRaisesRegexp(PlotlyError, pattern, | ||
tls.FigureFactory.create_gantt, | ||
df, index_col='foo') | ||
|
||
df = [{'Task': 'Job A', 'Start': '2009-02-01', | ||
'Finish': '2009-08-30', 'Complete': 'a'}, | ||
{'Task': 'Job A', 'Start': '2009-02-01', | ||
'Finish': '2009-08-30', 'Complete': 50}] | ||
|
||
pattern2 = ('Error in indexing column. Make sure all entries of each ' | ||
'column are all numbers or all strings.') | ||
|
||
self.assertRaisesRegexp(PlotlyError, pattern2, | ||
tls.FigureFactory.create_gantt, | ||
df, index_col='Complete') | ||
|
||
def test_gantt_validate_colors(self): | ||
|
||
# validate the gantt colors variable | ||
|
||
df = [{'Task': 'Job A', 'Start': '2009-02-01', | ||
'Finish': '2009-08-30', 'Complete': 75, 'Resource': 'A'}, | ||
{'Task': 'Job B', 'Start': '2009-02-01', | ||
'Finish': '2009-08-30', 'Complete': 50, 'Resource': 'B'}] | ||
|
||
pattern = ('Whoops! The elements in your rgb colors tuples cannot ' | ||
'exceed 255.0.') | ||
|
||
self.assertRaisesRegexp(PlotlyError, pattern, | ||
tls.FigureFactory.create_gantt, df, | ||
index_col='Complete', colors='rgb(300,1,1)') | ||
|
||
self.assertRaises(PlotlyError, tls.FigureFactory.create_gantt, | ||
df, index_col='Complete', colors='foo') | ||
|
||
pattern2 = ('Whoops! The elements in your colors tuples cannot ' | ||
'exceed 1.0.') | ||
|
||
self.assertRaisesRegexp(PlotlyError, pattern2, | ||
tls.FigureFactory.create_gantt, df, | ||
index_col='Complete', colors=(2, 1, 1)) | ||
|
||
# verify that if colors is a dictionary, its keys span all the | ||
# values in the index column | ||
colors_dict = {75: 'rgb(1, 2, 3)'} | ||
|
||
pattern3 = ('If you are using colors as a dictionary, all of its ' | ||
'keys must be all the values in the index column.') | ||
|
||
self.assertRaisesRegexp(PlotlyError, pattern3, | ||
tls.FigureFactory.create_gantt, df, | ||
index_col='Complete', colors=colors_dict) | ||
|
||
# check: index is set if colors is a dictionary | ||
colors_dict_good = {50: 'rgb(1, 2, 3)', 75: 'rgb(5, 10, 15)'} | ||
|
||
pattern4 = ('Error. You have set colors to a dictionary but have not ' | ||
'picked an index. An index is required if you are ' | ||
'assigning colors to particular values in a dictioanry.') | ||
|
||
self.assertRaisesRegexp(PlotlyError, pattern4, | ||
tls.FigureFactory.create_gantt, df, | ||
colors=colors_dict_good) | ||
|
||
# check: number of colors is equal to or greater than number of | ||
# unique index string values | ||
pattern5 = ("Error. The number of colors in 'colors' must be no less " | ||
"than the number of unique index values in your group " | ||
"column.") | ||
|
||
self.assertRaisesRegexp(PlotlyError, pattern5, | ||
tls.FigureFactory.create_gantt, df, | ||
index_col='Resource', | ||
colors=['#ffffff']) | ||
|
||
# check: if index is numeric, colors has at least 2 colors in it | ||
pattern6 = ("You must use at least 2 colors in 'colors' if you " | ||
"are using a colorscale. However only the first two " | ||
"colors given will be used for the lower and upper " | ||
"bounds on the colormap.") | ||
|
||
self.assertRaisesRegexp(PlotlyError, pattern6, | ||
tls.FigureFactory.create_gantt, df, | ||
index_col='Complete', | ||
colors=['#ffffff']) | ||
|
||
def test_gantt_all_args(self): | ||
|
||
# check if gantt chart matches with expected output | ||
|
||
df = [{'Task': 'Run', | ||
'Start': '2010-01-01', | ||
'Finish': '2011-02-02', | ||
'Complete': 0}, | ||
{'Task': 'Fast', | ||
'Start': '2011-01-01', | ||
'Finish': '2012-06-05', | ||
'Complete': 25}] | ||
|
||
test_gantt_chart = tls.FigureFactory.create_gantt( | ||
df, colors='Blues', index_col='Complete', reverse_colors=True, | ||
title='Title', bar_width=0.5, showgrid_x=True, showgrid_y=True, | ||
height=500, width=500 | ||
) | ||
|
||
exp_gantt_chart = { | ||
'data': [{'marker': {'color': 'white'}, | ||
'name': '', | ||
'x': ['2010-01-01', '2011-02-02'], | ||
'y': [0, 0]}, | ||
{'marker': {'color': 'white'}, | ||
'name': '', | ||
'x': ['2011-01-01', '2012-06-05'], | ||
'y': [1, 1]}], | ||
'layout': {'height': 500, | ||
'hovermode': 'closest', | ||
'shapes': [{'fillcolor': 'rgb(220.0, 220.0, 220.0)', | ||
'line': {'width': 0}, | ||
'opacity': 1, | ||
'type': 'rect', | ||
'x0': '2010-01-01', | ||
'x1': '2011-02-02', | ||
'xref': 'x', | ||
'y0': -0.5, | ||
'y1': 0.5, | ||
'yref': 'y'}, | ||
{'fillcolor': 'rgb(166.25, 167.5, 208.0)', | ||
'line': {'width': 0}, | ||
'opacity': 1, | ||
'type': 'rect', | ||
'x0': '2011-01-01', | ||
'x1': '2012-06-05', | ||
'xref': 'x', | ||
'y0': 0.5, | ||
'y1': 1.5, | ||
'yref': 'y'}], | ||
'showlegend': False, | ||
'title': 'Title', | ||
'width': 500, | ||
'xaxis': {'rangeselector': {'buttons': [ | ||
{'count': 7, | ||
'label': '1w', | ||
'step': 'day', | ||
'stepmode': 'backward'}, | ||
{'count': 1, | ||
'label': '1m', | ||
'step': 'month', | ||
'stepmode': 'backward'}, | ||
{'count': 6, | ||
'label': '6m', | ||
'step': 'month', | ||
'stepmode': 'backward'}, | ||
{'count': 1, | ||
'label': 'YTD', | ||
'step': 'year', | ||
'stepmode': 'todate'}, | ||
{'count': 1, | ||
'label': '1y', | ||
'step': 'year', | ||
'stepmode': 'backward'}, | ||
{'step': 'all'} | ||
]}, | ||
'showgrid': True, | ||
'type': 'date', | ||
'zeroline': False}, | ||
'yaxis': {'autorange': False, | ||
'range': [-1, 3], | ||
'showgrid': True, | ||
'ticktext': ['Run', 'Fast'], | ||
'tickvals': [0, 1], | ||
'zeroline': False}} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. excellent! Love this full-test 🐅! |
||
|
||
self.assertEqual(test_gantt_chart['data'][0], | ||
exp_gantt_chart['data'][0]) | ||
|
||
self.assertEqual(test_gantt_chart['data'][1], | ||
exp_gantt_chart['data'][1]) | ||
|
||
self.assertEqual(test_gantt_chart['layout'], | ||
exp_gantt_chart['layout']) | ||
|
||
# class TestDistplot(TestCase): | ||
|
||
# def test_scipy_import_error(self): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1267,6 +1267,85 @@ def test_scatter_plot_matrix_kwargs(self): | |
exp_scatter_plot_matrix['layout']) | ||
|
||
|
||
class TestGantt(NumpyTestUtilsMixin, TestCase): | ||
|
||
def test_df_dataframe(self): | ||
|
||
# validate dataframe has correct column names | ||
df1 = pd.DataFrame([[2, 'Apple']], columns=['Numbers', 'Fruit']) | ||
self.assertRaises(PlotlyError, tls.FigureFactory.create_gantt, df1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't look like you have a test that indeed inputs a dataframe. The other test in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Sure. How thorough should these sets of tests be? Or are you thinking of an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not thorough necessarily, just an |
||
|
||
def test_df_dataframe_all_args(self): | ||
|
||
# check if gantt chart matches with expected output | ||
|
||
df = pd.DataFrame([['Job A', '2009-01-01', '2009-02-30'], | ||
['Job B', '2009-03-05', '2009-04-15']], | ||
columns=['Task', 'Start', 'Finish']) | ||
|
||
test_gantt_chart = tls.FigureFactory.create_gantt(df) | ||
|
||
exp_gantt_chart = { | ||
'data': [{'marker': {'color': 'white'}, | ||
'name': '', | ||
'x': ['2009-01-01', '2009-02-30'], | ||
'y': [0, 0]}], | ||
'layout': {'height': 600, | ||
'hovermode': 'closest', | ||
'shapes': [{'opacity': 1, | ||
'y1': 0.2, | ||
'xref': 'x', | ||
'fillcolor': 'rgb(31.0, 119.0, 180.0)', | ||
'yref': 'y', | ||
'y0': -0.2, | ||
'x0': '2009-01-01', | ||
'x1': '2009-02-30', | ||
'type': 'rect', | ||
'line': {'width': 0}}, | ||
{'opacity': 1, | ||
'y1': 1.2, | ||
'xref': 'x', | ||
'fillcolor': 'rgb(255.0, 127.0, 14.0)', | ||
'yref': 'y', | ||
'y0': 0.8, | ||
'x0': '2009-03-05', | ||
'x1': '2009-04-15', | ||
'type': 'rect', | ||
'line': {'width': 0}}], | ||
'showlegend': False, | ||
'title': 'Gantt Chart', | ||
'width': 900, | ||
'xaxis': {'rangeselector': {'buttons': [ | ||
{'count': 7, 'label': '1w', | ||
'step': 'day', 'stepmode': 'backward'}, | ||
{'count': 1, 'label': '1m', | ||
'step': 'month', 'stepmode': 'backward'}, | ||
{'count': 6, 'label': '6m', | ||
'step': 'month', 'stepmode': 'backward'}, | ||
{'count': 1, 'label': 'YTD', | ||
'step': 'year', 'stepmode': 'todate'}, | ||
{'count': 1, 'label': '1y', | ||
'step': 'year', 'stepmode': 'backward'}, | ||
{'step': 'all'} | ||
]}, | ||
'showgrid': False, | ||
'type': 'date', | ||
'zeroline': False}, | ||
'yaxis': {'autorange': False, | ||
'range': [-1, 3], | ||
'showgrid': False, | ||
'ticktext': ['Job A', 'Job B'], | ||
'tickvals': [0, 1], | ||
'zeroline': False}} | ||
} | ||
|
||
self.assertEqual(test_gantt_chart['data'][0], | ||
exp_gantt_chart['data'][0]) | ||
|
||
self.assert_dict_equal(test_gantt_chart['layout'], | ||
exp_gantt_chart['layout']) | ||
|
||
|
||
class TestViolin(NumpyTestUtilsMixin, TestCase): | ||
|
||
def test_colors_validation(self): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great test!