Skip to content

Commit 0531958

Browse files
committed
new validate function for axis labels
1 parent feac0d4 commit 0531958

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

probscale/tests/test_validate.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ def test_fit_arguments_invalid(kwarg):
4747
validate.fit_argument('junk', kwarg)
4848

4949

50-
5150
@pytest.mark.parametrize(('value', 'error'), [
5251
('x', None), ('y', None), ('junk', ValueError)
5352
])
@@ -80,3 +79,9 @@ def test_axis_type(value, expected, error):
8079
])
8180
def test_other_options(value, expected):
8281
assert validate.other_options(value) == expected
82+
83+
84+
@pytest.mark.parametrize(('value', 'expected'), [(None, ''), ('test', 'test')])
85+
def test_axis_label(value, expected):
86+
result = validate.axis_label(value)
87+
assert result == expected

probscale/validate.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ def axes_object(ax):
1818
return fig, ax
1919

2020

21-
def axis_name(axname, argname):
21+
def axis_name(axis, axname):
2222
valid_args = ['x', 'y']
23-
if axname.lower() not in valid_args:
23+
if axis.lower() not in valid_args:
2424
msg = 'Invalid value for {} ({}). Must be on of {}.'
25-
raise ValueError(msg.format(argname, axname, valid_args))
25+
raise ValueError(msg.format(axname, axis, valid_args))
2626

27-
return axname.lower()
27+
return axis.lower()
2828

2929

3030
def fit_argument(arg, argname):
@@ -42,5 +42,12 @@ def axis_type(axtype):
4242
return axtype.lower()
4343

4444

45+
def axis_label(label):
46+
if label is None:
47+
return ''
48+
else:
49+
return label
50+
51+
4552
def other_options(options):
4653
return dict() if options is None else options.copy()

0 commit comments

Comments
 (0)