8000 Added tests for data and new test_annotations.py file. · appscluster/python-api@f395108 · GitHub
[go: up one dir, main page]

Skip to content

Commit f395108

Browse files
committed
Added tests for data and new test_annotations.py file.
Changes in graph_objs.py were made to solve bugs found in new testing.
1 parent 6e81a15 commit f395108

File tree

3 files changed

+113
-8
lines changed

3 files changed

+113
-8
lines changed

plotly/graph_objs/graph_objs.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,16 @@ def to_graph_objs(self, caller=True):
824824
825825
"""
826826
for index, entry in enumerate(self):
827-
if isinstance(entry, dict):
827+
if isinstance(entry, (PlotlyDict, PlotlyList)):
828+
if not isinstance(entry, Annotation):
829+
raise exceptions.PlotlyListEntryError(
830+
obj=self,
831+
index=index,
832+
notes="The entry could not be converted into an "
833+
"Annotation object because it was already a "
834+
"di 10000 fferent kind of graph object.",
835+
)
836+
elif isinstance(entry, dict):
828837
obj = Annotation()
829838
for k, v in entry.items():
830839
obj[k] = v
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
"""
2+
test_annotations:
3+
==========
4+
5+
A module intended for use with Nose.
6+
7+
"""
8+
from nose.tools import raises
9+
from ...graph_objs.graph_objs import *
10+
from ...exceptions import (PlotlyDictKeyError, PlotlyDictValueError,
11+
PlotlyDataTypeError, PlotlyListEntryError)
12+
13+
14+
def setup():
15+
import warnings
16+
warnings.filterwarnings('ignore')
17+
18+
19+
def test_trivial():
20+
assert Annotations() == list()
21+
22+
23+
def test_weird_instantiation(): # Python allows this...
24+
assert Annotations({}) == list({})
25+
26+
27+
def test_dict_instantiation():
28+
Annotations([{'text': 'annotation text'}])
29+
30+
31+
@raises(PlotlyDictKeyError)
32+
def test_dict_instantiation_key_error():
33+
print Annotations([{'not-a-key': 'anything'}])
34+
35+
36+
@raises(PlotlyDictValueError)
37+
def test_dict_instantiation_key_error():
38+
print Annotations([{'font': 'not-a-dict'}])
39+
40+
41+
@raises(PlotlyListEntryError)
42+
def test_dict_instantiation_graph_obj_error_0():
43+
Annotations([Data()])
44+
45+
46+
@raises(PlotlyListEntryError)
47+
def test_dict_instantiation_graph_obj_error_1():
48+
Annotations([Figure()])
49+
50+
51+
@raises(PlotlyListEntryError)
52+
def test_dict_instantiation_graph_obj_error_2():
53+
Annotations([Annotations()])
54+
55+
56+
@raises(PlotlyListEntryError)
57+
def test_dict_instantiation_graph_obj_error_3():
58+
Annotations([Layout()])
59+
60+
61+
def test_validate():
62+
annotations = Annotations()
63+
annotations.validate()
64+
annotations += [{'text': 'some text'}]
65+
annotations.validate()
66+
annotations += [{},{},{}]
67+
annotations.validate()
68+
69+
70+
@raises(PlotlyDictKeyError)
71+
def test_validate_error():
72+
annotations = Annotations()
73+
annotations.append({'not-a-key': 'anything'})
74+
annotations.validate()
75+

plotly/tests/test_graph_objs/test_data.py

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"""
88
from nose.tools import raises
99
from ...graph_objs.graph_objs import *
10-
from ...exceptions import PlotlyError
10+
from ...exceptions import (PlotlyDictKeyError, PlotlyDictValueError,
11+
PlotlyDataTypeError, PlotlyListEntryError)
1112

1213

1314
def setup():
@@ -19,7 +20,7 @@ def test_trivial():
1920
assert Data() == list()
2021

2122

22-
def test_weird_instantiation(): # TODO: ok?
23+
def test_weird_instantiation(): # Python allows this...
2324
assert Data({}) == list({})
2425

2526

@@ -31,21 +32,41 @@ def test_dict_instantiation():
3132
Data([{'type': 'scatter'}])
3233

3334

34-
@raises(PlotlyError)
35+
@raises(PlotlyDictKeyError)
3536
def test_dict_instantiation_key_error():
3637
print Data([{'not-a-key': 'anything'}])
3738

3839

39-
@raises(PlotlyError)
40+
@raises(PlotlyDictValueError)
41+
def test_dict_instantiation_key_error():
42+
print Data([{'marker': 'not-a-dict'}])
43+
44+
45+
@raises(PlotlyDataTypeError)
4046
def test_dict_instantiation_type_error():
4147
Data([{'type': 'invalid_type'}])
4248

4349

44-
@raises(PlotlyError)
45-
def test_dict_instantiation_graph_obj_error():
50+
@raises(PlotlyListEntryError)
51+
def test_dict_instantiation_graph_obj_error_0():
4652
Data([Data()])
4753

4854

55+
@raises(PlotlyListEntryError)
56+
def test_dict_instantiation_graph_obj_error_1():
57+
Data([Figure()])
58+
59+
60+
@raises(PlotlyListEntryError)
61+
def test_dict_instantiation_graph_obj_error_2():
62+
Data([Annotations()])
63+
64+
65+
@raises(PlotlyListEntryError)
66+
def test_dict_instantiation_graph_obj_error_3():
67+
Data([Layout()])
68+
69+
4970
def test_validate():
5071
data = Data()
5172
data.validate()
@@ -55,7 +76,7 @@ def test_validate():
5576
data.validate()
5677

5778

58-
@raises(PlotlyError)
79+
@raises(PlotlyDictKeyError)
5980
def test_validate_error():
6081
data = Data()
6182
data.append({'not-a-key': 'anything'})

0 commit comments

Comments
 (0)
0