|
| 1 | +import plotly |
| 2 | +from plotly.graph_objs import * |
| 3 | +import plotly.tools as tls |
| 4 | +from nose.tools import raises |
| 5 | + |
| 6 | + |
| 7 | +@raises(Exception) |
| 8 | +def test_print_grid_before_make_subplots(): |
| 9 | + fig.print_grid() |
| 10 | + |
| 11 | +@raises(Exception) |
| 12 | +def test_append_trace_before_make_subplots(): |
| 13 | + trace = Scatter( |
| 14 | + x=[1,2,3], |
| 15 | + y=[2,3,4] |
| 16 | + ) |
| 17 | + fig.append_trace(trace, 2, 2) |
| 18 | + |
| 19 | +@raises(Exception) |
| 20 | +def test_append_trace_row_out_of_range(): |
| 21 | + trace = Scatter( |
| 22 | + x=[1,2,3], |
| 23 | + y=[2,3,4] |
| 24 | + ) |
| 25 | + fig = tls.make_subplots(rows=2, cols=3) |
| 26 | + fig.append_trace(trace, 10, 2) |
| 27 | + |
| 28 | +@raises(Exception) |
| 29 | +def test_append_trace_col_out_of_range(): |
| 30 | + trace = Scatter( |
| 31 | + x=[1,2,3], |
| 32 | + y=[2,3,4] |
| 33 | + ) |
| 34 | + fig = tls.make_subplots(rows=2, cols=3) |
| 35 | + fig.append_trace(trace, 2, 0) |
| 36 | + |
| 37 | +def test_append_scatter(): |
| 38 | + expected = Figure( |
| 39 | + data=Data([ |
| 40 | + Scatter( |
| 41 | + x=[1, 2, 3], |
| 42 | + y=[2, 3, 4], |
| 43 | + xaxis='x5', |
| 44 | + yaxis='y5' |
| 45 | + ) |
| 46 | + ]), |
| 47 | + layout=Layout( |
| 48 | + xaxis1=XAxis( |
| 49 | + domain=[0.0, 0.2888888888888889], |
| 50 | + anchor='y1' |
| 51 | + ), |
| 52 | + xaxis2=XAxis( |
| 53 | + domain=[0.35555555555555557, 0.6444444444444445], |
| 54 | + anchor='y2' |
| 55 | + ), |
| 56 | + xaxis3=XAxis( |
| 57 | + domain=[0.7111111111111111, 1.0], |
| 58 | + anchor='y3' |
| 59 | + ), |
| 60 | + xaxis4=XAxis( |
| 61 | + domain=[0.0, 0.2888888888888889], |
| 62 | + anchor='y4' |
| 63 | + ), |
| 64 | + xaxis5=XAxis( |
| 65 | + domain=[0.35555555555555557, 0.6444444444444445], |
| 66 | + anchor='y5' |
| 67 | + ), |
| 68 | + xaxis6=XAxis( |
| 69 | + domain=[0.7111111111111111, 1.0], |
| 70 | + anchor='y6' |
| 71 | + ), |
| 72 | + yaxis1=YAxis( |
| 73 | + domain=[0.575, 1.0], |
| 74 | + anchor='x1' |
| 75 | + ), |
| 76 | + yaxis2=YAxis( |
| 77 | + domain=[0.575, 1.0], |
| 78 | + anchor='x2' |
| 79 | + ), |
| 80 | + yaxis3=YAxis( |
| 81 | + domain=[0.575, 1.0], |
| 82 | + anchor='x3' |
| 83 | + ), |
| 84 | + yaxis4=YAxis( |
| 85 | + domain=[0.0, 0.425], |
| 86 | + anchor='x4' |
| 87 | + ), |
| 88 | + yaxis5=YAxis( |
| 89 | + domain=[0.0, 0.425], |
| 90 | + anchor='x5' |
| 91 | + ), |
| 92 | + yaxis6=YAxis( |
| 93 | + domain=[0.0, 0.425], |
| 94 | + anchor='x6' |
| 95 | + ) |
| 96 | + ) |
| 97 | + ) |
| 98 | + |
| 99 | + trace = Scatter( |
| 100 | + x=[1,2,3], |
| 101 | + y=[2,3,4] |
| 102 | + ) |
| 103 | + fig = tls.make_subplots(rows=2, cols=3) |
| 104 | + fig.append_trace(trace, 2, 2) |
| 105 | + assert fig == expected |
| 106 | + |
| 107 | +@raises(Exception) |
| 108 | +def test_append_scatter_after_deleting_xaxis(): |
| 109 | + trace = Scatter( |
| 110 | + x=[1,2,3], |
| 111 | + y=[2,3,4] |
| 112 | + ) |
| 113 | + fig = tls.make_subplots(rows=2, cols=3) |
| 114 | + fig['layout'].pop('xaxis5', None) |
| 115 | + fig.append_trace(trace, 2, 2) |
| 116 | + |
| 117 | +@raises(Exception) |
| 118 | +def test_append_scatter_after_deleting_yaxis(): |
| 119 | + trace = Scatter( |
| 120 | + x=[1,2,3], |
| 121 | + y=[2,3,4] |
| 122 | + ) |
| 123 | + fig = tls.make_subplots(rows=2, cols=3) |
| 124 | + fig['layout'].pop('yaxis5', None) |
| 125 | + fig.append_trace(trace, 2, 2) |
| 126 | + |
| 127 | +def test_append_scatter3d(): |
| 128 | + expected = Figure( |
| 129 | + data=Data([ |
| 130 | + Scatter3d( |
| 131 | + x=[1, 2, 3], |
| 132 | + y=[2, 3, 4], |
| 133 | + z=[1, 2, 3], |
| 134 | + scene='scene2' |
| 135 | + ), |
| 136 | + Scatter3d( |
| 137 | + x=[1, 2, 3], |
| 138 | + y=[2, 3, 4], |
| 139 | + z=[1, 2, 3], |
| 140 | + scene='scene2' |
| 141 | + ) |
| 142 | + ]), |
| 143 | + layout=Layout( |
| 144 | + scene1=Scene( |
| 145 | + domain={'y': [0.575, 1.0], 'x': [0.0, 1.0]} |
| 146 | + ), |
| 147 | + scene2=Scene( |
| 148 | + domain={'y': [0.0, 0.425], 'x': [0.0, 1.0]} |
| 149 | + ) |
| 150 | + ) |
| 151 | + ) |
| 152 | + |
| 153 | + fig = tls.make_subplots(rows=2, cols=1, |
| 154 | + specs=[[{'is_3d': True}], |
| 155 | + [{'is_3d': True}]]) |
| 156 | + trace = Scatter3d( |
| 157 | + x=[1,2,3], |
| 158 | + y=[2,3,4], |
| 159 | + z=[1,2,3] |
| 160 | + ) |
| 161 | + fig.append_trace(trace, 1, 1) |
| 162 | + fig.append_trace(trace, 2, 1) |
| 163 | + assert fig == expected |
| 164 | + |
| 165 | +@raises(Exception) |
| 166 | +def test_append_scatter3d_after_deleting_scene(): |
| 167 | + fig = tls.make_subplots(rows=2, cols=1, |
| 168 | + specs=[[{'is_3d': True}], |
| 169 | + [{'is_3d': True}]]) |
| 170 | + trace = Scatter3d( |
| 171 | + x=[1,2,3], |
| 172 | + y=[2,3,4], |
| 173 | + z=[1,2,3] |
| 174 | + ) |
| 175 | + fig['layout'].pop('scene1', None) |
| 176 | + fig.append_trace(trace, 1, 1) |
0 commit comments