Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fce9ba3

Browse files
committed
prettify tests and update imports
1 parent b83a151 commit fce9ba3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+531
-509
lines changed
Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +0,0 @@
1-
def setup_package():
2-
pass
3-
4-
5-
def teardown_package():
6-
pass

plotly/tests/test_core/test_get_figure/test_get_figure.py

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55
A module intended for use with Nose.
66
77
"""
8-
from plotly.graph_objs import graph_objs
9-
from plotly.plotly import plotly as py
10-
from plotly import exceptions
11-
from nose.tools import raises
12-
import six
8+
from __future__ import absolute_import
139

14-
from unittest import TestCase
10+
from unittest import TestCase, skipIf
1511

16-
version = six.sys.version_info[:2] # need this for conditional testing
12+
from nose.tools import raises
13+
import six
1714

15+
from plotly import exceptions
16+
from plotly.graph_objs import graph_objs
17+
from plotly.plotly import plotly as py
1818

1919
# username for tests: 'plotlyimagetest'
2020
# api_key for account: '786r5mecv0'
@@ -53,8 +53,9 @@ def compare_with_raw(obj, raw_obj, parents=None):
5353
for entry, entry_raw in zip(obj, raw_obj):
5454
if isinstance(entry, (dict, list)):
5555
try:
56-
coll_name = graph_objs.NAME_TO_KEY[entry.__class__
57-
.__name__]
56+
coll_name = (
57+
graph_objs.NAME_TO_KEY[entry.__class__.__name__]
58+
)
5859
except KeyError:
5960
coll_name = entry.__class__.__name__
6061
if parents is None:
@@ -163,7 +164,7 @@ def test_all():
163164
ak = '786r5mecv0'
164165
run_test = False
165166
end_file = 2
166-
polar_plots = [], #[6, 7, 8]
167+
polar_plots = [], # [6, 7, 8]
167168
skip = list(range(0))
168169
if run_test:
169170
py.sign_in(un, ak)
@@ -198,18 +199,12 @@ def test_all():
198199

199200
class TestBytesVStrings(TestCase):
200201

201-
# unittest `skipIf` not supported in 2.6
202-
if version < (2, 7) or (2, 7) < version < (3, 3):
203-
pass
204-
else:
205-
from unittest import skipIf
206-
207-
@skipIf(not six.PY3, 'Decoding and missing escapes only seen in PY3')
208-
def test_proper_escaping(self):
209-
un = 'PlotlyImageTest'
210-
ak = '786r5mecv0'
211-
url = "https://plot.ly/~PlotlyImageTest/91/"
212-
py.sign_in(un, ak)
213-
print("getting: https://plot.ly/~PlotlyImageTest/91/")
214-
print("###########################################\n\n")
215-
fig = py.get_figure(url)
202+
@skipIf(not six.PY3, 'Decoding and missing escapes only seen in PY3')
203+
def test_proper_escaping(self):
204+
un = 'PlotlyImageTest'
205+
ak = '786r5mecv0'
206+
url = "https://plot.ly/~PlotlyImageTest/91/"
207+
py.sign_in(un, ak)
208+
print("getting: https://plot.ly/~PlotlyImageTest/91/")
209+
print("###########################################\n\n")
210+
fig = py.get_figure(url)
Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +0,0 @@
1-
def setup_package():
2-
pass
3-
4-
5-
def teardown_package():
6-
pass

plotly/tests/test_core/test_get_requests/test_get_requests.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,12 @@
55
A module intended for use with Nose.
66
77
"""
8-
9-
import requests
108
import copy
9+
import json
10+
import requests
11+
1112
import six
12-
import sys
1313

14-
if sys.version[:3] == '2.6':
15-
import simplejson as json
16-
else:
17-
import json
1814

1915
default_headers = {'plotly-username': '',
2016
'plotly-apikey': '',
@@ -151,4 +147,3 @@ def test_valid_request():
151147
# if figure['data'][0]['x'] != [u'1', u'2', u'3']:
152148
# print('ERROR')
153149
# return res
154-
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
def setup_package():
2-
import warnings
3-
warnings.filterwarnings('ignore')
1+
import warnings
42

53

6-
def teardown_package():
7-
pass
4+
def setup_package():
5+
warnings.filterwarnings('ignore')

plotly/tests/test_core/test_graph_objs/nose_tools.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
from __future__ import absolute_import
22

3+
from numbers import Number as Num
4+
35
import matplotlib
46
# Force matplotlib to not use any Xwindows backend.
57
matplotlib.use('Agg')
8+
69
from plotly.matplotlylib import Exporter, PlotlyRenderer
7-
from numbers import Number as Num
810

911

1012
def compare_dict(dict1, dict2, equivalent=True, msg='', tol=10e-8):

plotly/tests/test_core/test_graph_objs/test_annotations.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@
88
from __future__ import absolute_import
99

1010
from nose.tools import raises
11-
from plotly.graph_objs import *
12-
from plotly.exceptions import (PlotlyError,
13-
PlotlyDictKeyError,
14-
PlotlyDictValueError,
15-
PlotlyDataTypeError,
16-
PlotlyListEntryError)
11+
12+
from plotly.exceptions import (PlotlyError, PlotlyDictKeyError,
13+
PlotlyDictValueError, PlotlyListEntryError)
14+
from plotly.graph_objs import Annotation, Annotations, Data, Figure, Layout
15+
1716

1817

1918
def setup():
@@ -69,7 +68,7 @@ def test_validate():
6968
annotations.validate()
7069
annotations += [{'text': 'some text'}]
7170
annotations.validate()
72-
annotations += [{},{},{}]
71+
annotations += [{}, {}, {}]
7372
annotations.validate()
7473

7574

@@ -78,4 +77,3 @@ def test_validate_error():
7877
annotations = Annotations()
7978
annotations.append({'not-a-key': 'anything'})
8079
annotations.validate()
81-

plotly/tests/test_core/test_graph_objs/test_append_trace.py

Lines changed: 24 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,39 @@
1-
import plotly
2-
from plotly.graph_objs import *
3-
import plotly.tools as tls
1+
from __future__ import absolute_import
2+
43
from nose.tools import raises
54

5+
from plotly.graph_objs import (Data, Figure, Layout, Scatter, Scatter3d, Scene,
6+
XAxis, YAxis)
7+
import plotly.tools as tls
8+
69

710
@raises(Exception)
811
def test_print_grid_before_make_subplots():
12+
fig = Figure()
913
fig.print_grid()
1014

15+
1116
@raises(Exception)
1217
def test_append_trace_before_make_subplots():
13-
trace = Scatter(
14-
x=[1,2,3],
15-
y=[2,3,4]
16-
)
18+
trace = Scatter(x=[1, 2, 3], y=[2, 3, 4])
19+
fig = Figure()
1720
fig.append_trace(trace, 2, 2)
1821

22+
1923
@raises(Exception)
2024
def test_append_trace_row_out_of_range():
21-
trace = Scatter(
22-
x=[1,2,3],
23-
y=[2,3,4]
24-
)
25+
trace = Scatter(x=[1, 2, 3], y=[2, 3, 4])
2526
fig = tls.make_subplots(rows=2, cols=3)
2627
fig.append_trace(trace, 10, 2)
2728

29+
2830
@raises(Exception)
2931
def test_append_trace_col_out_of_range():
30-
trace = Scatter(
31-
x=[1,2,3],
32-
y=[2,3,4]
33-
)
32+
trace = Scatter(x=[1, 2, 3], y=[2, 3, 4])
3433
fig = tls.make_subplots(rows=2, cols=3)
3534
fig.append_trace(trace, 2, 0)
3635

36+
3737
def test_append_scatter():
3838
expected = Figure(
3939
data=Data([
@@ -96,34 +96,28 @@ def test_append_scatter():
9696
)
9797
)
9898

99-
trace = Scatter(
100-
x=[1,2,3],
101-
y=[2,3,4]
102-
)
99+
trace = Scatter(x=[1, 2, 3], y=[2, 3, 4])
103100
fig = tls.make_subplots(rows=2, cols=3)
104101
fig.append_trace(trace, 2, 2)
105102
assert fig == expected
106103

104+
107105
@raises(Exception)
108106
def test_append_scatter_after_deleting_xaxis():
109-
trace = Scatter(
110-
x=[1,2,3],
111-
y=[2,3,4]
112-
)
107+
trace = Scatter(x=[1, 2, 3], y=[2, 3, 4])
113108
fig = tls.make_subplots(rows=2, cols=3)
114109
fig['layout'].pop('xaxis5', None)
115110
fig.append_trace(trace, 2, 2)
116111

112+
117113
@raises(Exception)
118114
def test_append_scatter_after_deleting_yaxis():
119-
trace = Scatter(
120-
x=[1,2,3],
121-
y=[2,3,4]
122-
)
115+
trace = Scatter(x=[1, 2, 3], y=[2, 3, 4])
123116
fig = tls.make_subplots(rows=2, cols=3)
124117
fig['layout'].pop('yaxis5', None)
125118
fig.append_trace(trace, 2, 2)
126119

120+
127121
def test_append_scatter3d():
128122
expected = Figure(
129123
data=Data([
@@ -153,24 +147,17 @@ def test_append_scatter3d():
153147
fig = tls.make_subplots(rows=2, cols=1,
154148
specs=[[{'is_3d': True}],
155149
[{'is_3d': True}]])
156-
trace = Scatter3d(
157-
x=[1,2,3],
158-
y=[2,3,4],
159-
z=[1,2,3]
160-
)
150+
trace = Scatter3d(x=[1, 2, 3], y=[2, 3, 4], z=[1, 2, 3])
161151
fig.append_trace(trace, 1, 1)
162152
fig.append_trace(trace, 2, 1)
163153
assert fig == expected
164154

155+
165156
@raises(Exception)
166157
def test_append_scatter3d_after_deleting_scene():
167158
fig = tls.make_subplots(rows=2, cols=1,
168159
specs=[[{'is_3d': True}],
169160
[{'is_3d': True}]])
170-
trace = Scatter3d(
171-
x=[1,2,3],
172-
y=[2,3,4],
173-
z=[1,2,3]
174-
)
161+
trace = Scatter3d(x=[1, 2, 3], y=[2, 3, 4], z=[1, 2, 3])
175162
fig['layout'].pop('scene1', None)
176163
fig.append_trace(trace, 1, 1)

plotly/tests/test_core/test_graph_objs/test_consistency.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
are properly defined in both graph_objs.py and included in the mapping dicts.
77
88
"""
9+
from __future__ import absolute_import
10+
911
from plotly.graph_objs import graph_objs
1012

1113

plotly/tests/test_core/test_graph_objs/test_data.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@
88
from __future__ import absolute_import
99

1010
from nose.tools import raises
11-
from plotly.graph_objs import *
12-
from plotly.exceptions import (PlotlyError,
13-
PlotlyDictKeyError,
14-
PlotlyDictValueError,
15-
PlotlyDataTypeError,
11+
12+
from plotly.exceptions import (PlotlyError, PlotlyDictKeyError,
13+
PlotlyDictValueError, PlotlyDataTypeError,
1614
PlotlyListEntryError)
15+
from plotly.graph_objs import Annotations, Data, Figure, Layout
1716

1817

1918
def setup():
@@ -78,7 +77,7 @@ def test_validate():
7877
data.validate()
7978
data += [{'type': 'scatter'}]
8079
data.validate()
81-
data += [{},{},{}]
80+
data += [{}, {}, {}]
8281
data.validate()
8382

8483

@@ -87,4 +86,3 @@ def test_validate_error():
8786
data = Data()
8887
data.append({'not-a-key': 'anything'})
8988
data.validate()
90-

plotly/tests/test_core/test_graph_objs/test_error_bars.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,8 @@
88
from __future__ import absolute_import
99

1010
from nose.tools import raises
11-
from plotly.graph_objs import *
12-
from plotly.exceptions import (PlotlyDictKeyError,
13-
PlotlyDictValueError,
14-
PlotlyDataTypeError,
15-
PlotlyListEntryError)
11+
from plotly.graph_objs import ErrorX, ErrorY
12+
from plotly.exceptions import PlotlyDictKeyError
1613

1714

1815
def test_instantiate_error_x():

plotly/tests/test_core/test_graph_objs/test_get_data.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
from unittest import TestCase
44

5-
from plotly.graph_objs import *
5+
from plotly.graph_objs import (Data, Figure, Layout, Line, Margin, Marker,
6+
Scatter, XAxis, YAxis)
67

78

89
class TestGetData(TestCase):

0 commit comments

Comments
 (0)