7
7
"""
8
8
9
9
from nose .tools import raises
10
+ from nose import with_setup
10
11
11
12
import random
12
13
import string
19
20
from plotly .exceptions import InputError , PlotlyRequestError
20
21
21
22
22
- def _random_filename ():
23
+ def random_filename ():
23
24
random_chars = [random .choice (string .ascii_uppercase ) for _ in range (5 )]
24
25
unique_filename = 'Valid Grid ' + '' .join (random_chars )
25
26
return unique_filename
26
27
27
28
28
- def _get_grid ():
29
- c1 = Column ('first column' , [1 , 2 , 3 , 4 ])
30
- c2 = Column ('second column' , ['a' , 'b' , 'c' , 'd' ])
29
+ def get_grid ():
30
+ c1 = Column ([1 , 2 , 3 , 4 ], 'first column' )
31
+ c2 = Column (['a' , 'b' , 'c' , 'd' ], 'second column' )
31
32
g = Grid ([c1 , c2 ])
32
33
return g
33
34
34
35
35
- def _init ():
36
+ def init ():
36
37
py .sign_in ('PythonTest' , '9v9f20pext' )
37
38
38
39
39
40
def upload_and_return_grid ():
40
- _init ()
41
- g = _get_grid ()
42
- unique_filename = _random_filename ()
41
+ init ()
42
+ g = get_grid ()
43
+ unique_filename = random_filename ()
43
44
44
45
py .grid_ops .upload (g , unique_filename , auto_open = False )
45
46
return g
@@ -50,26 +51,26 @@ def test_grid_upload():
50
51
upload_and_return_grid ()
51
52
52
53
54
+ @with_setup (init )
53
55
def test_grid_upload_in_new_folder ():
54
- _init ()
55
- g = _get_grid ()
56
- path = 'new folder: {}/grid in folder {}' .format (_random_filename (), _random_filename ())
56
+ g = get_grid ()
57
+ path = 'new folder: {}/grid in folder {}' .format (random_filename (), random_filename ())
57
58
py .grid_ops .upload (g , path , auto_open = False )
58
59
59
60
61
+ @with_setup (init )
60
62
def test_grid_upload_in_existing_folder ():
61
- _init ()
62
- g = _get_grid ()
63
- folder = _random_filename ()
64
- filename = _random_filename ()
63
+ g = get_grid ()
64
+ folder = random_filename ()
65
+ filename = random_filename ()
65
66
py .file_ops .mkdirs (folder )
66
67
path = 'existing folder: {}/grid in folder {}' .format (folder , filename )
67
68
py .grid_ops .upload (g , path , auto_open = False )
68
69
69
70
70
71
def test_column_append ():
71
72
g = upload_and_return_grid ()
72
- new_col = Column ('new col' , [1 , 5 , 3 ])
73
+ new_col = Column ([1 , 5 , 3 ], 'new col' )
73
74
74
75
py .grid_ops .append_columns ([new_col ], grid = g )
75
76
@@ -88,6 +89,7 @@ def test_plot_from_grid():
88
89
return url , g
89
90
90
91
92
+ @with_setup (init )
91
93
def test_get_figure_from_references ():
92
94
url , g = test_plot_from_grid ()
93
95
fig = py .get_figure (url )
@@ -157,24 +159,24 @@ def test_unequal_length_rows():
157
159
# Test duplicate columns
158
160
@raises (InputError )
159
161
def test_duplicate_columns ():
160
- c1 = Column ('first column' , [1 , 2 , 3 , 4 ])
161
- c2 = Column ('first column' , ['a' , 'b' , 'c' , 'd' ])
162
+ c1 = Column ([1 , 2 , 3 , 4 ], 'first column' )
163
+ c2 = Column (['a' , 'b' , 'c' , 'd' ], 'first column' )
162
164
Grid ([c1 , c2 ])
163
165
164
166
165
167
# Test delete
168
+ @with_setup (init )
166
169
def test_delete_grid ():
167
- _init ()
168
- g = _get_grid ()
169
- fn = _random_filename ()
170
+ g = get_grid ()
171
+ fn = random_filename ()
170
172
py .grid_ops .upload (g , fn , auto_open = False )
171
173
py .grid_ops .delete (g )
172
174
py .grid_ops .upload (g , fn , auto_open = False )
173
175
174
176
175
177
## Plotly failures
176
178
def test_duplicate_filenames ():
177
- c1 = Column ('first column' , [1 , 2 , 3 , 4 ])
179
+ c1 = Column ([1 , 2 , 3 , 4 ], 'first column' )
178
180
g = Grid ([c1 ])
179
181
180
182
random_chars = [random .choice (string .ascii_uppercase ) for _ in range (5 )]
@@ -183,6 +185,4 @@ def test_duplicate_filenames():
183
185
try :
184
186
py .grid_ops .upload (g , unique_filename , auto_open = False )
185
187
except PlotlyRequestError as e :
186
- if e .status_code != 409 :
187
- raise e
188
-
188
+ assert (e .status_code == 409 )
0 commit comments