Skip to content

Commit

Permalink
validate_hatch from hatch module
Browse files Browse the repository at this point in the history
  • Loading branch information
ShivamPathak99 committed Apr 14, 2024
1 parent 2817fb2 commit af4629a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 15 deletions.
15 changes: 2 additions & 13 deletions lib/matplotlib/rcsetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from matplotlib.colors import Colormap, is_color_like
from matplotlib._fontconfig_pattern import parse_fontconfig_pattern
from matplotlib._enums import JoinStyle, CapStyle
from matplotlib.hatch import _validate_hatch_pattern

# Don't let the original cycler collide with our validating cycler
from cycler import Cycler, cycler as ccycler
Expand Down Expand Up @@ -617,19 +618,7 @@ def _validate_int_greaterequal0(s):
raise RuntimeError(f'Value must be >=0; got {s}')


def validate_hatch(s):
r"""
Validate a hatch pattern.
A hatch pattern string can have any sequence of the following
characters: ``\ / | - + * . x o O``.
"""
if not isinstance(s, str):
raise ValueError("Hatch pattern must be a string")
_api.check_isinstance(str, hatch_pattern=s)
unknown = set(s) - {'\\', '/', '|', '-', '+', '*', '.', 'x', 'o', 'O'}
if unknown:
raise ValueError("Unknown hatch symbol(s): %s" % list(unknown))
return s
validate_hatch = _validate_hatch_pattern


validate_hatchlist = _listify_validator(validate_hatch)
Expand Down
3 changes: 1 addition & 2 deletions lib/matplotlib/tests/test_rcparams.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,7 @@ def generate_validator_testcases(valid):
'success': (('--|', '--|'), ('\\oO', '\\oO'),
('/+*/.x', '/+*/.x'), ('', '')),
'fail': (('--_', ValueError),
(8, ValueError),
('X', ValueError)),
(8, ValueError)),
},
{'validator': validate_colorlist,
'success': (('r,g,b', ['r', 'g', 'b']),
Expand Down

0 comments on commit af4629a

Please sign in to comment.