Skip to content

Commit 047a525

Browse files
committed
Fix validator tests for Python 2.7
1 parent 3cba342 commit 047a525

18 files changed

+117
-114
lines changed

Diff for: _plotly_utils/tests/__init__.py

Whitespace-only changes.

Diff for: _plotly_utils/tests/validators/__init__.py

Whitespace-only changes.

Diff for: _plotly_utils/tests/validators/test_angle_validator.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import pytest
2+
#from ..basevalidators import AngleValidator
23
from _plotly_utils.basevalidators import AngleValidator
34
import numpy as np
45

@@ -33,7 +34,7 @@ def test_coercion(val, expected, validator):
3334
# ### Test rejection ###
3435
@pytest.mark.parametrize('val',
3536
['hello', (), [], [1, 2, 3], set(), '34'])
36-
def test_rejection(val, validator: AngleValidator):
37+
def test_rejection(val, validator):
3738
with pytest.raises(ValueError) as validation_failure:
3839
validator.validate_coerce(val)
3940

Diff for: _plotly_utils/tests/validators/test_any_validator.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def validator_aok():
2121
@pytest.mark.parametrize('val', [
2222
set(), 'Hello', 123, np.inf, np.nan, {}
2323
])
24-
def test_acceptance(val, validator: AnyValidator):
24+
def test_acceptance(val, validator):
2525
assert validator.validate_coerce(val) is val
2626

2727

@@ -36,7 +36,7 @@ def test_acceptance(val, validator: AnyValidator):
3636
['Hello', 'World'],
3737
[np.pi, np.e, {}]
3838
])
39-
def test_acceptance_array(val, validator_aok: AnyValidator):
39+
def test_acceptance_array(val, validator_aok):
4040
coerce_val = validator_aok.validate_coerce(val)
4141
if isinstance(val, np.ndarray):
4242
assert isinstance(coerce_val, np.ndarray)

Diff for: _plotly_utils/tests/validators/test_basetraces_validator.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def validator():
1616

1717
# Tests
1818
# -----
19-
def test_acceptance(validator: BaseDataValidator):
19+
def test_acceptance(validator):
2020
val = [Scatter(mode='lines'), Box(fillcolor='yellow')]
2121
res = validator.validate_coerce(val)
2222
res_present = validator.present(res)
@@ -36,7 +36,7 @@ def test_acceptance(validator: BaseDataValidator):
3636
assert res_present[0].uid != res_present[1].uid
3737

3838

39-
def test_acceptance_dict(validator: BaseDataValidator):
39+
def test_acceptance_dict(validator):
4040
val = (dict(type='scatter', mode='lines'),
4141
dict(type='box', fillcolor='yellow'))
4242
res = validator.validate_coerce(val)
@@ -56,7 +56,7 @@ def test_acceptance_dict(validator: BaseDataValidator):
5656
assert res_present[0].uid != res_present[1].uid
5757

5858

59-
def test_default_is_scatter(validator: BaseDataValidator):
59+
def test_default_is_scatter(validator):
6060
val = [dict(mode='lines')]
6161
res = validator.validate_coerce(val)
6262
res_present = validator.present(res)
@@ -68,7 +68,7 @@ def test_default_is_scatter(validator: BaseDataValidator):
6868
assert res_present[0].mode == 'lines'
6969

7070

71-
def test_rejection_type(validator: BaseDataValidator):
71+
def test_rejection_type(validator):
7272
val = 37
7373

7474
with pytest.raises(ValueError) as validation_failure:
@@ -77,7 +77,7 @@ def test_rejection_type(validator: BaseDataValidator):
7777
assert "Invalid value" in str(validation_failure.value)
7878

7979

80-
def test_rejection_element_type(validator: BaseDataValidator):
80+
def test_rejection_element_type(validator):
8181
val = [42]
8282

8383
with pytest.raises(ValueError) as validation_failure:
@@ -86,7 +86,7 @@ def test_rejection_element_type(validator: BaseDataValidator):
8686
assert "Invalid element(s)" in str(validation_failure.value)
8787

8888

89-
def test_rejection_element_attr(validator: BaseDataValidator):
89+
def test_rejection_element_attr(validator):
9090
val = [dict(type='scatter', bogus=99)]
9191

9292
with pytest.raises(ValueError) as validation_failure:
@@ -97,7 +97,7 @@ def test_rejection_element_attr(validator: BaseDataValidator):
9797
str(validation_failure.value))
9898

9999

100-
def test_rejection_element_tracetype(validator: BaseDataValidator):
100+
def test_rejection_element_tracetype(validator):
101101
val = [dict(type='bogus', a=4)]
102102

103103
with pytest.raises(ValueError) as validation_failure:

Diff for: _plotly_utils/tests/validators/test_color_validator.py

+16-16
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ def validator_aok_colorscale():
3030
@pytest.mark.parametrize('val',
3131
['red', 'BLUE', 'rgb(255, 0, 0)', 'hsl(0, 100%, 50%)', 'hsla(0, 100%, 50%, 100%)',
3232
'hsv(0, 100%, 100%)', 'hsva(0, 100%, 100%, 50%)'])
33-
def test_acceptance(val, validator: ColorValidator):
33+
def test_acceptance(val, validator):
3434
assert validator.validate_coerce(val) == val
3535

3636

3737
# ### Rejection by type ###
3838
@pytest.mark.parametrize('val',
3939
[set(), 23, 0.5, {}, ['red'], [12]])
40-
def test_rejection(val, validator: ColorValidator):
40+
def test_rejection(val, validator):
4141
with pytest.raises(ValueError) as validation_failure:
4242
validator.validate_coerce(val)
4343

@@ -47,7 +47,7 @@ def test_rejection(val, validator: ColorValidator):
4747
# ### Rejection by value ###
4848
@pytest.mark.parametrize('val',
4949
['redd', 'rgbbb(255, 0, 0)', 'hsl(0, 1%0000%, 50%)'])
50-
def test_rejection(val, validator: ColorValidator):
50+
def test_rejection(val, validator):
5151
with pytest.raises(ValueError) as validation_failure:
5252
validator.validate_coerce(val)
5353

@@ -60,14 +60,14 @@ def test_rejection(val, validator: ColorValidator):
6060
@pytest.mark.parametrize('val',
6161
['red', 'BLUE', 23, 15, 'rgb(255, 0, 0)', 'hsl(0, 100%, 50%)', 'hsla(0, 100%, 50%, 100%)',
6262
'hsv(0, 100%, 100%)', 'hsva(0, 100%, 100%, 50%)'])
63-
def test_acceptance_colorscale(val, validator_colorscale: ColorValidator):
63+
def test_acceptance_colorscale(val, validator_colorscale):
6464
assert validator_colorscale.validate_coerce(val) == val
6565

6666

6767
# ### Rejection by type ###
6868
@pytest.mark.parametrize('val',
6969
[set(), {}, ['red'], [12]])
70-
def test_rejection_colorscale(val, validator_colorscale: ColorValidator):
70+
def test_rejection_colorscale(val, validator_colorscale):
7171
with pytest.raises(ValueError) as validation_failure:
7272
validator_colorscale.validate_coerce(val)
7373

@@ -77,7 +77,7 @@ def test_rejection_colorscale(val, validator_colorscale: ColorValidator):
7777
# ### Rejection by value ###
7878
@pytest.mark.parametrize('val',
7979
['redd', 'rgbbb(255, 0, 0)', 'hsl(0, 1%0000%, 50%)'])
80-
def test_rejection_colorscale(val, validator_colorscale: ColorValidator):
80+
def test_rejection_colorscale(val, validator_colorscale):
8181
with pytest.raises(ValueError) as validation_failure:
8282
validator_colorscale.validate_coerce(val)
8383

@@ -94,7 +94,7 @@ def test_rejection_colorscale(val, validator_colorscale: ColorValidator):
9494
['hsl(0, 100%, 50%)', 'hsla(0, 100%, 50%, 100%)', 'hsv(0, 100%, 100%)'],
9595
np.array(['hsl(0, 100%, 50%)', 'hsla(0, 100%, 50%, 100%)', 'hsv(0, 100%, 100%)']),
9696
['hsva(0, 100%, 100%, 50%)']])
97-
def test_acceptance_aok(val, validator_aok: ColorValidator):
97+
def test_acceptance_aok(val, validator_aok):
9898
coerce_val = validator_aok.validate_coerce(val)
9999

100100
if isinstance(val, np.ndarray):
@@ -111,7 +111,7 @@ def test_acceptance_aok(val, validator_aok: ColorValidator):
111111
[['red', 'rgb(255, 0, 0)'], ['hsl(0, 100%, 50%)', 'hsla(0, 100%, 50%, 100%)']],
112112
np.array([['red', 'rgb(255, 0, 0)'], ['hsl(0, 100%, 50%)', 'hsla(0, 100%, 50%, 100%)']])
113113
])
114-
def test_acceptance_aok_2D(val, validator_aok: ColorValidator):
114+
def test_acceptance_aok_2D(val, validator_aok):
115115
coerce_val = validator_aok.validate_coerce(val)
116116

117117
if isinstance(val, np.ndarray):
@@ -128,7 +128,7 @@ def test_acceptance_aok_2D(val, validator_aok: ColorValidator):
128128
['redd', 'rgb(255, 0, 0)'],
129129
['hsl(0, 100%, 50_00%)', 'hsla(0, 100%, 50%, 100%)', 'hsv(0, 100%, 100%)'],
130130
['hsva(0, 1%00%, 100%, 50%)']])
131-
def test_rejection_aok(val, validator_aok: ColorValidator):
131+
def test_rejection_aok(val, validator_aok):
132132
with pytest.raises(ValueError) as validation_failure:
133133
validator_aok.validate_coerce(val)
134134

@@ -142,7 +142,7 @@ def test_rejection_aok(val, validator_aok: ColorValidator):
142142
[np.array(['hsl(0, 100%, 50_00%)', 'hsla(0, 100%, 50%, 100%)']),
143143
np.array(['hsv(0, 100%, 100%)', 'purple'])],
144144
[['blue'], [2]]])
145-
def test_rejection_aok_2D(val, validator_aok: ColorValidator):
145+
def test_rejection_aok_2D(val, validator_aok):
146146
with pytest.raises(ValueError) as validation_failure:
147147
validator_aok.validate_coerce(val)
148148

@@ -157,7 +157,7 @@ def test_rejection_aok_2D(val, validator_aok: ColorValidator):
157157
['red', 0.5, 'rgb(255, 0, 0)'],
158158
['hsl(0, 100%, 50%)', 'hsla(0, 100%, 50%, 100%)', 'hsv(0, 100%, 100%)'],
159159
['hsva(0, 100%, 100%, 50%)']])
160-
def test_acceptance_aok_colorscale(val, validator_aok_colorscale: ColorValidator):
160+
def test_acceptance_aok_colorscale(val, validator_aok_colorscale):
161161
coerce_val = validator_aok_colorscale.validate_coerce(val)
162162
if isinstance(val, (list, np.ndarray)):
163163
assert np.array_equal(list(coerce_val), val)
@@ -170,7 +170,7 @@ def test_acceptance_aok_colorscale(val, validator_aok_colorscale: ColorValidator
170170
[['redd', 0.5, 'rgb(255, 0, 0)'],
171171
['hsl(0, 100%, 50_00%)', 'hsla(0, 100%, 50%, 100%)', 'hsv(0, 100%, 100%)'],
172172
['hsva(0, 1%00%, 100%, 50%)']])
173-
def test_rejection_aok_colorscale(val, validator_aok_colorscale: ColorValidator):
173+
def test_rejection_aok_colorscale(val, validator_aok_colorscale):
174174
with pytest.raises(ValueError) as validation_failure:
175175
validator_aok_colorscale.validate_coerce(val)
176176

@@ -180,25 +180,25 @@ def test_rejection_aok_colorscale(val, validator_aok_colorscale: ColorValidator)
180180
# Description
181181
# -----------
182182
# Test dynamic description logic
183-
def test_description(validator: ColorValidator):
183+
def test_description(validator):
184184
desc = validator.description()
185185
assert 'A number that will be interpreted as a color' not in desc
186186
assert 'A list or array of any of the above' not in desc
187187

188188

189-
def test_description_aok(validator_aok: ColorValidator):
189+
def test_description_aok(validator_aok):
190190
desc = validator_aok.description()
191191
assert 'A number that will be interpreted as a color' not in desc
192192
assert 'A list or array of any of the above' in desc
193193

194194

195-
def test_description_aok(validator_colorscale: ColorValidator):
195+
def test_description_aok(validator_colorscale):
196196
desc = validator_colorscale.description()
197197
assert 'A number that will be interpreted as a color' in desc
198198
assert 'A list or array of any of the above' not in desc
199199

200200

201-
def test_description_aok_colorscale(validator_aok_colorscale: ColorValidator):
201+
def test_description_aok_colorscale(validator_aok_colorscale):
202202
desc = validator_aok_colorscale.description()
203203
assert 'A number that will be interpreted as a color' in desc
204204
assert 'A list or array of any of the above' in desc

Diff for: _plotly_utils/tests/validators/test_colorscale_validator.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def named_colorscale(request):
2020
# Tests
2121
# -----
2222
# ### Acceptance by name ###
23-
def test_acceptance_named(named_colorscale, validator: ColorscaleValidator):
23+
def test_acceptance_named(named_colorscale, validator):
2424
# As-is
2525
assert validator.validate_coerce(named_colorscale) == named_colorscale
2626

@@ -36,7 +36,7 @@ def test_acceptance_named(named_colorscale, validator: ColorscaleValidator):
3636
((0.1, 'rgb(255,0,0)'), (0.3, 'green')),
3737
((0, 'purple'), (0.2, 'yellow'), (1.0, 'rgba(255,0,0,100)')),
3838
])
39-
def test_acceptance_array(val, validator: ColorscaleValidator):
39+
def test_acceptance_array(val, validator):
4040
assert validator.validate_coerce(val) == val
4141

4242
# ### Coercion as array ###
@@ -45,7 +45,7 @@ def test_acceptance_array(val, validator: ColorscaleValidator):
4545
[(0.1, 'rgb(255, 0, 0)'), (0.3, 'GREEN')],
4646
(np.array([0, 'Purple'], dtype='object'), (0.2, 'yellow'), (1.0, 'RGBA(255,0,0,100)')),
4747
])
48-
def test_acceptance_array(val, validator: ColorscaleValidator):
48+
def test_acceptance_array(val, validator):
4949
# Compute expected (tuple of tuples where color is
5050
# lowercase with no spaces)
5151
expected = [[e[0], e[1]] for e in val]
@@ -60,7 +60,7 @@ def test_acceptance_array(val, validator: ColorscaleValidator):
6060
@pytest.mark.parametrize('val', [
6161
23, set(), {}, np.pi
6262
])
63-
def test_rejection_type(val, validator: ColorscaleValidator):
63+
def test_rejection_type(val, validator):
6464
with pytest.raises(ValueError) as validation_failure:
6565
validator.validate_coerce(val)
6666

@@ -71,7 +71,7 @@ def test_rejection_type(val, validator: ColorscaleValidator):
7171
@pytest.mark.parametrize('val', [
7272
'Invalid', ''
7373
])
74-
def test_rejection_str_value(val, validator: ColorscaleValidator):
74+
def test_rejection_str_value(val, validator):
7575
with pytest.raises(ValueError) as validation_failure:
7676
validator.validate_coerce(val)
7777

@@ -87,7 +87,7 @@ def test_rejection_str_value(val, validator: ColorscaleValidator):
8787
([0.1, 'purple'], [0.2, 123]), # Color not a string
8888
([0.1, 'purple'], [0.2, 'yellowww']), # Invalid color string
8989
])
90-
def test_rejection_array(val, validator: ColorscaleValidator):
90+
def test_rejection_array(val, validator):
9191
with pytest.raises(ValueError) as validation_failure:
9292
validator.validate_coerce(val)
9393

Diff for: _plotly_utils/tests/validators/test_compound_validator.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def validator():
1414

1515
# Tests
1616
# -----
17-
def test_acceptance(validator: CompoundValidator):
17+
def test_acceptance(validator):
1818
val = Marker(color='green', size=10)
1919
res = validator.validate_coerce(val)
2020

@@ -23,7 +23,7 @@ def test_acceptance(validator: CompoundValidator):
2323
assert res.size == 10
2424

2525

26-
def test_acceptance_none(validator: CompoundValidator):
26+
def test_acceptance_none(validator):
2727
val = None
2828
res = validator.validate_coerce(val)
2929

@@ -32,7 +32,7 @@ def test_acceptance_none(validator: CompoundValidator):
3232
assert res.size is None
3333

3434

35-
def test_acceptance_dict(validator: CompoundValidator):
35+
def test_acceptance_dict(validator):
3636
val = dict(color='green', size=10)
3737
res = validator.validate_coerce(val)
3838

@@ -41,7 +41,7 @@ def test_acceptance_dict(validator: CompoundValidator):
4141
assert res.size == 10
4242

4343

44-
def test_rejection_type(validator: CompoundValidator):
44+
def test_rejection_type(validator):
4545
val = 37
4646

4747
with pytest.raises(ValueError) as validation_failure:
@@ -50,7 +50,7 @@ def test_rejection_type(validator: CompoundValidator):
5050
assert "Invalid value" in str(validation_failure.value)
5151

5252

53-
def test_rejection_value(validator: CompoundValidator):
53+
def test_rejection_value(validator):
5454
val = dict(color='green', size=10, bogus=99)
5555

5656
with pytest.raises(ValueError) as validation_failure:

Diff for: _plotly_utils/tests/validators/test_compoundarray_validator.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from _plotly_utils.basevalidators import CompoundArrayValidator
33
from plotly.graph_objs.layout import Image
44

5+
56
# Fixtures
67
# --------
78
@pytest.fixture()
@@ -13,7 +14,7 @@ def validator():
1314

1415
# Tests
1516
# -----
16-
def test_acceptance(validator: CompoundArrayValidator):
17+
def test_acceptance(validator):
1718
val = [Image(opacity=0.5, sizex=120), Image(x=99)]
1819
res = validator.validate_coerce(val)
1920
res_present = validator.present(res)
@@ -30,7 +31,7 @@ def test_acceptance(validator: CompoundArrayValidator):
3031
assert res_present[1].x == 99
3132

3233

33-
def test_acceptance_empty(validator: CompoundArrayValidator):
34+
def test_acceptance_empty(validator):
3435
val = [{}]
3536
res = validator.validate_coerce(val)
3637
res_present = validator.present(res)
@@ -43,7 +44,7 @@ def test_acceptance_empty(validator: CompoundArrayValidator):
4344
assert res_present[0].x is None
4445

4546

46-
def test_acceptance_dict(validator: CompoundArrayValidator):
47+
def test_acceptance_dict(validator):
4748
val = [dict(opacity=0.5, sizex=120), dict(x=99)]
4849
res = validator.validate_coerce(val)
4950
res_present = validator.present(res)
@@ -61,7 +62,7 @@ def test_acceptance_dict(validator: CompoundArrayValidator):
6162
assert res_present[1].x == 99
6263

6364

64-
def test_rejection_type(validator: CompoundArrayValidator):
65+
def test_rejection_type(validator):
6566
val = 37
6667

6768
with pytest.raises(ValueError) as validation_failure:
@@ -70,7 +71,7 @@ def test_rejection_type(validator: CompoundArrayValidator):
7071
assert "Invalid value" in str(validation_failure.value)
7172

7273

73-
def test_rejection_element(validator: CompoundArrayValidator):
74+
def test_rejection_element(validator):
7475
val = ['a', 37]
7576

7677
with pytest.raises(ValueError) as validation_failure:
@@ -79,7 +80,7 @@ def test_rejection_element(validator: CompoundArrayValidator):
7980
assert "Invalid element(s)" in str(validation_failure.value)
8081

8182

82-
def test_rejection_value(validator: CompoundArrayValidator):
83+
def test_rejection_value(validator):
8384
val = [dict(opacity=0.5, sizex=120, bogus=100)]
8485

8586
with pytest.raises(ValueError) as validation_failure:

0 commit comments

Comments
 (0)