Skip to content

Commit 00f8162

Browse files
committed
Rewrote tests in core and optional
1 parent f165b73 commit 00f8162

File tree

2 files changed

+97
-214
lines changed

2 files changed

+97
-214
lines changed

plotly/tests/test_core/test_tools/test_figure_factory.py

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,6 +1228,102 @@ def test_gantt_validate_colors(self):
12281228
tls.FigureFactory.create_gantt, df,
12291229
index_col='Complete', colors=5)
12301230

1231+
def test_gantt_all_args(self):
1232+
1233+
# check if gantt chart matches with expected output
1234+
1235+
df = [dict(Task="Run",
1236+
Start='2010-01-01',
1237+
Finish='2011-02-02',
1238+
Complete=0),
1239+
dict(Task="Fast",
1240+
Start='2011-01-01',
1241+
Finish='2012-06-05',
1242+
Complete=25)]
1243+
1244+
test_gantt_chart = tls.FigureFactory.create_gantt(
1245+
df, colors='Blues', index_col='Complete', reverse_colors=True,
1246+
title='Title', bar_width=0.5, showgrid_x=True, showgrid_y=True,
1247+
height=500, width=500
1248+
)
1249+
1250+
exp_gantt_chart = {
1251+
'data': [{'marker': {'color': 'white'},
1252+
'name': '',
1253+
'x': ['2010-01-01', '2011-02-02'],
1254+
'y': [0, 0]},
1255+
{'marker': {'color': 'white'},
1256+
'name': '',
1257+
'x': ['2011-01-01', '2012-06-05'],
1258+
'y': [1, 1]}],
1259+
'layout': {'height': 500,
1260+
'hovermode': 'closest',
1261+
'shapes': [{'fillcolor': 'rgb(220.0, 220.0, 220.0)',
1262+
'line': {'width': 0},
1263+
'opacity': 1,
1264+
'type': 'rect',
1265+
'x0': '2010-01-01',
1266+
'x1': '2011-02-02',
1267+
'xref': 'x',
1268+
'y0': -0.5,
1269+
'y1': 0.5,
1270+
'yref': 'y'},
1271+
{'fillcolor': 'rgb(166.25, 167.5, 208.0)',
1272+
'line': {'width': 0},
1273+
'opacity': 1,
1274+
'type': 'rect',
1275+
'x0': '2011-01-01',
1276+
'x1': '2012-06-05',
1277+
'xref': 'x',
1278+
'y0': 0.5,
1279+
'y1': 1.5,
1280+
'yref': 'y'}],
1281+
'showlegend': False,
1282+
'title': 'Title',
1283+
'width': 500,
1284+
'xaxis': {'rangeselector': {'buttons': [
1285+
{'count': 7,
1286+
'label': '1w',
1287+
'step': 'day',
1288+
'stepmode': 'backward'},
1289+
{'count': 1,
1290+
'label': '1m',
1291+
'step': 'month',
1292+
'stepmode': 'backward'},
1293+
{'count': 6,
1294+
'label': '6m',
1295+
'step': 'month',
1296+
'stepmode': 'backward'},
1297+
{'count': 1,
1298+
'label': 'YTD',
1299+
'step': 'year',
1300+
'stepmode': 'todate'},
1301+
{'count': 1,
1302+
'label': '1y',
1303+
'step': 'year',
1304+
'stepmode': 'backward'},
1305+
{'step': 'all'}
1306+
]},
1307+
'showgrid': True,
1308+
'type': 'date',
1309+
'zeroline': False},
1310+
'yaxis': {'autorange': False,
1311+
'range': [-1, 3],
1312+
'showgrid': True,
1313+
'ticktext': ['Run', 'Fast'],
1314+
'tickvals': [0, 1],
1315+
'zeroline': False}}
1316+
}
1317+
1318+
self.assertEqual(test_gantt_chart['data'][0],
1319+
exp_gantt_chart['data'][0])
1320+
1321+
self.assertEqual(test_gantt_chart['data'][1],
1322+
exp_gantt_chart['data'][1])
1323+
1324+
self.assertEqual(test_gantt_chart['layout'],
1325+
exp_gantt_chart['layout'])
1326+
12311327
# class TestDistplot(TestCase):
12321328

12331329
# def test_scipy_import_error(self):

plotly/tests/test_optional/test_figure_factory.py

Lines changed: 1 addition & 214 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,219 +1018,6 @@ class TestGantt(NumpyTestUtilsMixin, TestCase):
10181018

10191019
def test_df_dataframe(self):
10201020

1021-
# validate df when it is a dataframe
1022-
1021+
# validate dataframe has correct column names
10231022
df1 = pd.DataFrame([[2, 'Apple']], columns=['Numbers', 'Fruit'])
10241023
self.assertRaises(PlotlyError, tls.FigureFactory.create_gantt, df1)
1025-
1026-
df2 = pd.DataFrame([['Job A', '2009-01-01', '2009-02-30', 25],
1027-
['Job B', '2009-01-01', '2009-02-30', '25']],
1028-
columns=['Task', 'Start', 'Finish', 'Complete'])
1029-
self.assertRaisesRegexp(PlotlyError,
1030-
"The values in the 'Complete' column must "
1031-
"be between 0 and 100.",
1032-
tls.FigureFactory.create_gantt, df2)
1033-
1034-
def test_df_list(self):
1035-
1036-
# validate df when it is a list
1037-
1038-
df1 = 42
1039-
self.assertRaisesRegexp(PlotlyError,
1040-
"You must input either a dataframe or a list "
1041-
"of dictionaries.",
1042-
tls.FigureFactory.create_gantt, df1)
1043-
1044-
df2 = []
1045-
self.assertRaisesRegexp(PlotlyError,
1046-
"Your list is empty. It must contain "
1047-
"at least one dictionary.",
1048-
tls.FigureFactory.create_gantt, df2)
1049-
1050-
df3 = [42]
1051-
self.assertRaisesRegexp(PlotlyError,
1052-
"Your list must only include dictionaries.",
1053-
tls.FigureFactory.create_gantt, df3)
1054-
1055-
df4 = [{'apple': 2}]
1056-
self.assertRaises(PlotlyError, tls.FigureFactory.create_gantt, df4)
1057-
1058-
df5 = [{'Task': 'A Job',
1059-
'Start': '2009-01-01',
1060-
'Finish': '2009-02-30'},
1061-
{'Task': 'A Job',
1062-
'Start': '2009-01-01',
1063-
'Finish': '2009-02-30',
1064-
'Complete': 25}]
1065-
self.assertRaisesRegexp(PlotlyError,
1066-
"If you are using 'Complete' as a dictionary "
1067-
"key, make sure each dictionary has this key "
1068-
"with an assigned value between 0 and 100.",
1069-
tls.FigureFactory.create_gantt, df5)
1070-
1071-
df6 = [{'Task': 'A Job',
1072-
'Start': '2009-01-01',
1073-
'Finish': '2009-02-30',
1074-
'Complete': 55},
1075-
{'Task': 'A Job',
1076-
'Start': '2009-01-01',
1077-
'Finish': '2009-02-30',
1078-
'Complete': 'string'}]
1079-
self.assertRaisesRegexp(PlotlyError,
1080-
"The values in the 'Complete' column must "
1081-
"be between 0 and 100.",
1082-
tls.FigureFactory.create_gantt, df6)
1083-
1084-
def test_valid_colors(self):
1085-
1086-
# check: if color choices are valid
1087-
1088-
df = [{'Task': 'A Job',
1089-
'Start': '2009-01-01',
1090-
'Finish': '2009-02-30',
1091-
'Complete': 55},
1092-
{'Task': 'A Job',
1093-
'Start': '2009-01-01',
1094-
'Finish': '2009-02-30',
1095-
'Complete': 65}]
1096-
1097-
self.assertRaises(PlotlyError, tls.FigureFactory.create_gantt,
1098-
df, colors='Weird')
1099-
1100-
pattern1 = (
1101-
"If 'colors' is a list then its items must be tripets of the "
1102-
"form a,b,c or 'rgbx,y,z' where a,b,c are between 0 and 1 "
1103-
"inclusive and x,y,z are between 0 and 255 inclusive."
1104-
)
1105-
1106-
self.assertRaisesRegexp(PlotlyError, pattern1,
1107-
tls.FigureFactory.create_gantt, df, colors=25)
1108-
1109-
pattern2 = (
1110-
"Whoops! The elements in your rgb colors tuples "
1111-
"cannot exceed 255.0."
1112-
)
1113-
1114-
self.assertRaisesRegexp(PlotlyError, pattern2,
1115-
tls.FigureFactory.create_gantt, df,
1116-
colors=['rgb(1, 2, 3)', 'rgb(300, 2, 3)'])
1117-
1118-
pattern3 = (
1119-
"Whoops! The elements in your rgb colors tuples "
1120-
"cannot exceed 1.0."
1121-
)
1122-
1123-
self.assertRaisesRegexp(PlotlyError, pattern3,
1124-
tls.FigureFactory.create_gantt, df,
1125-
colors=[(0.1, 0.2, 0.3), (0.6, 0.8, 1.2)])
1126-
1127-
def test_use_colorscale(self):
1128-
1129-
# checks: 'Complete' in inputted array or list
1130-
1131-
df = [{'Task': 'A Job',
1132-
'Start': '2009-01-01',
1133-
'Finish': '2009-02-30'},
1134-
{'Task': 'A Job',
1135-
'Start': '2009-01-01',
1136-
'Finish': '2009-02-30'}]
1137-
1138-
pattern = (
1139-
"In order to use colorscale there must be a "
1140-
"'Complete' column in the chart."
1141-
)
1142-
self.assertRaisesRegexp(PlotlyError, pattern,
1143-
tls.FigureFactory.create_gantt, df,
1144-
use_colorscale=True)
1145-
1146-
def test_gantt_all_args(self):
1147-
1148-
# check if gantt chart matches with expected output
1149-
1150-
df = [dict(Task="Run",
1151-
Start='2010-01-01',
1152-
Finish='2011-02-02',
1153-
Complete=0),
1154-
dict(Task="Fast",
1155-
Start='2011-01-01',
1156-
Finish='2012-06-05',
1157-
Complete=25)]
1158-
1159-
test_gantt_chart = tls.FigureFactory.create_gantt(
1160-
df, colors='Blues', use_colorscale=True, reverse_colors=True,
1161-
title='Title', bar_width=0.5, showgrid_x=True, showgrid_y=True,
1162-
height=500, width=500
1163-
)
1164-
1165-
exp_gantt_chart = {
1166-
'data': [{'marker': {'color': 'white'},
1167-
'name': '',
1168-
'x': ['2010-01-01', '2011-02-02'],
1169-
'y': [0, 0]},
1170-
{'marker': {'color': 'white'},
1171-
'name': '',
1172-
'x': ['2011-01-01', '2012-06-05'],
1173-
'y': [1, 1]}],
1174-
'layout': {'height': 500,
1175-
'hovermode': 'closest',
1176-
'shapes': [{'fillcolor': 'rgb(220.0, 220.0, 220.0)',
1177-
'line': {'width': 0},
1178-
'opacity': 1,
1179-
'type': 'rect',
1180-
'x0': '2010-01-01',
1181-
'x1': '2011-02-02',
1182-
'xref': 'x',
1183-
'y0': -0.5,
1184-
'y1': 0.5,
1185-
'yref': 'y'},
1186-
{'fillcolor': 'rgb(166.25, 167.5, 208.0)',
1187-
'line': {'width': 0},
1188-
'opacity': 1,
1189-
'type': 'rect',
1190-
'x0': '2011-01-01',
1191-
'x1': '2012-06-05',
1192-
'xref': 'x',
1193-
'y0': 0.5,
1194-
'y1': 1.5,
1195-
'yref': 'y'}],
1196-
'showlegend': False,
1197-
'title': 'Title',
1198-
'width': 500,
1199-
'xaxis': {
1200-
'rangeselector': {
1201-
'buttons': [{'count': 7, 'label': '1w',
1202-
'step': 'day',
1203-
'stepmode': 'backward'},
1204-
{'count': 1, 'label': '1m',
1205-
'step': 'month',
1206-
'stepmode': 'backward'},
1207-
{'count': 6, 'label': '6m',
1208-
'step': 'month',
1209-
'stepmode': 'backward'},
1210-
{'count': 1, 'label': 'YTD',
1211-
'step': 'year',
1212-
'stepmode': 'todate'},
1213-
{'count': 1, 'label': '1y',
1214-
'step': 'year',
1215-
'stepmode': 'backward'},
1216-
{'step': 'all'}]
1217-
},
1218-
'showgrid': True,
1219-
'type': 'date',
1220-
'zeroline': False},
1221-
'yaxis': {'autorange': False,
1222-
'range': [-1, 3],
1223-
'showgrid': True,
1224-
'ticktext': ['Run', 'Fast'],
1225-
'tickvals': [0, 1],
1226-
'zeroline': False}}
1227-
}
1228-
1229-
self.assert_dict_equal(test_gantt_chart['data'][0],
1230-
exp_gantt_chart['data'][0])
1231-
1232-
self.assert_dict_equal(test_gantt_chart['data'][1],
1233-
exp_gantt_chart['data'][1])
1234-
1235-
self.assert_dict_equal(test_gantt_chart['layout'],
1236-
exp_gantt_chart['layout'])

0 commit comments

Comments
 (0)