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

Skip to content

Commit 9f838ac

Browse files
committed
better organized tests
1 parent 8db46b5 commit 9f838ac

File tree

3 files changed

+36
-34
lines changed

3 files changed

+36
-34
lines changed

plotly/tests/test_core/test_file/test_file.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"""
88

99
from nose.tools import raises
10+
from nose import with_setup
1011

1112
import random
1213
import string
@@ -16,6 +17,7 @@
1617
import plotly.tools as tls
1718
from plotly.exceptions import PlotlyRequestError
1819

20+
1921
def _random_filename():
2022
random_chars = [random.choice(string.ascii_uppercase) for _ in range(5)]
2123
unique_filename = 'Valid Folder'+''.join(random_chars)
@@ -26,20 +28,20 @@ def init():
2628
py.sign_in('PythonTest', '9v9f20pext')
2729

2830

31+
@with_setup(init)
2932
def test_create_folder():
30-
init()
3133
py.file_ops.mkdirs(_random_filename())
3234

3335

36+
@with_setup(init)
3437
def test_create_nested_folders():
35-
init()
3638
first_folder = _random_filename()
3739
nested_folder = '{}/{}'.format(first_folder, _random_filename())
3840
py.file_ops.mkdirs(nested_folder)
3941

4042

43+
@with_setup(init)
4144
def test_duplicate_folders():
42-
init()
4345
first_folder = _random_filename()
4446
py.file_ops.mkdirs(first_folder)
4547
try:

plotly/tests/test_core/test_grid/test_grid.py

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"""
88

99
from nose.tools import raises
10+
from nose import with_setup
1011

1112
import random
1213
import string
@@ -19,27 +20,27 @@
1920
from plotly.exceptions import InputError, PlotlyRequestError
2021

2122

22-
def _random_filename():
23+
def random_filename():
2324
random_chars = [random.choice(string.ascii_uppercase) for _ in range(5)]
2425
unique_filename = 'Valid Grid '+''.join(random_chars)
2526
return unique_filename
2627

2728

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')
3132
g = Grid([c1, c2])
3233
return g
3334

3435

35-
def _init():
36+
def init():
3637
py.sign_in('PythonTest', '9v9f20pext')
3738

3839

3940
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()
4344

4445
py.grid_ops.upload(g, unique_filename, auto_open=False)
4546
return g
@@ -50,26 +51,26 @@ def test_grid_upload():
5051
upload_and_return_grid()
5152

5253

54+
@with_setup(init)
5355
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())
5758
py.grid_ops.upload(g, path, auto_open=False)
5859

5960

61+
@with_setup(init)
6062
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()
6566
py.file_ops.mkdirs(folder)
6667
path = 'existing folder: {}/grid in folder {}'.format(folder, filename)
6768
py.grid_ops.upload(g, path, auto_open=False)
6869

6970

7071
def test_column_append():
7172
g = upload_and_return_grid()
72-
new_col = Column('new col', [1, 5, 3])
73+
new_col = Column([1, 5, 3], 'new col')
7374

7475
py.grid_ops.append_columns([new_col], grid=g)
7576

@@ -88,6 +89,7 @@ def test_plot_from_grid():
8889
return url, g
8990

9091

92+
@with_setup(init)
9193
def test_get_figure_from_references():
9294
url, g = test_plot_from_grid()
9395
fig = py.get_figure(url)
@@ -157,24 +159,24 @@ def test_unequal_length_rows():
157159
# Test duplicate columns
158160
@raises(InputError)
159161
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')
162164
Grid([c1, c2])
163165

164166

165167
# Test delete
168+
@with_setup(init)
166169
def test_delete_grid():
167-
_init()
168-
g = _get_grid()
169-
fn = _random_filename()
170+
g = get_grid()
171+
fn = random_filename()
170172
py.grid_ops.upload(g, fn, auto_open=False)
171173
py.grid_ops.delete(g)
172174
py.grid_ops.upload(g, fn, auto_open=False)
173175

174176

175177
## Plotly failures
176178
def test_duplicate_filenames():
177-
c1 = Column('first column', [1, 2, 3, 4])
179+
c1 = Column([1, 2, 3, 4], 'first column')
178180
g = Grid([c1])
179181

180182
random_chars = [random.choice(string.ascii_uppercase) for _ in range(5)]
@@ -183,6 +185,4 @@ def test_duplicate_filenames():
183185
try:
184186
py.grid_ops.upload(g, unique_filename, auto_open=False)
185187
except PlotlyRequestError as e:
186-
if e.status_code != 409:
187-
raise e
188-
188+
assert(e.status_code == 409)

plotly/tests/test_core/test_meta/test_meta.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"""
88

99
from nose.tools import raises
10+
from nose import with_setup
1011

1112
import random
1213
import string
@@ -22,17 +23,17 @@ def init():
2223
py.sign_in('PythonTest', '9v9f20pext')
2324

2425

25-
_grid = grid = Grid([Column('first column', [1, 2, 3, 4])])
26+
_grid = grid = Grid([Column([1, 2, 3, 4], 'first column')])
2627
_meta = {"settings":{"scope1":{"model":"Unicorn Finder","voltage":4}}}
2728

2829
def _random_filename():
2930
random_chars = [random.choice(string.ascii_uppercase) for _ in range(5)]
3031
unique_filename = 'Valid Grid with Meta '+''.join(random_chars)
3132
return unique_filename
3233

33-
def test_upload_meta():
34-
init()
3534

35+
@with_setup(init)
36+
def test_upload_meta():
3637
unique_filename = _random_filename()
3738
grid_url = py.grid_ops.upload(_grid, unique_filename, auto_open=False)
3839

@@ -42,10 +43,9 @@ def test_upload_meta():
4243
grid_url=grid_url)
4344

4445

46+
@with_setup(init)
4547
def test_upload_meta_with_grid():
46-
init()
47-
48-
c1 = Column('first column', [1, 2, 3, 4])
48+
c1 = Column([1, 2, 3, 4], 'first column')
4949
grid = Grid([c1])
5050

5151
unique_filename = _random_filename()

0 commit comments

Comments
 (0)