Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6d5edf6

Browse files
committed
Add validation for fontstretch
1 parentb57b39b commit6d5edf6

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

‎lib/matplotlib/rcsetup.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,20 @@ def validate_fontweight(s):
387387
raiseValueError(f'{s} is not a valid font weight.')frome
388388

389389

390+
defvalidate_fontstretch(s):
391+
stretchvalues= [
392+
'ultra-condensed','extra-condensed','condensed','semi-condensed',
393+
'normal','semi-expanded','expanded','extra-expanded',
394+
'ultra-expanded']
395+
# Note: Historically, stretchvalues have been case-sensitive in Matplotlib
396+
ifsinstretchvalues:
397+
returns
398+
try:
399+
returnint(s)
400+
except (ValueError,TypeError)ase:
401+
raiseValueError(f'{s} is not a valid font stretch.')frome
402+
403+
390404
defvalidate_font_properties(s):
391405
parse_fontconfig_pattern(s)
392406
returns
@@ -900,7 +914,7 @@ def _convert_validator_spec(key, conv):
900914
"font.family":validate_stringlist,# used by text object
901915
"font.style":validate_string,
902916
"font.variant":validate_string,
903-
"font.stretch":validate_string,
917+
"font.stretch":validate_fontstretch,
904918
"font.weight":validate_fontweight,
905919
"font.size":validate_float,# Base font size in points
906920
"font.serif":validate_stringlist,

‎lib/matplotlib/tests/test_rcparams.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
_validate_color_or_linecolor,
2121
validate_cycler,
2222
validate_float,
23+
validate_fontstretch,
2324
validate_fontweight,
2425
validate_hatch,
2526
validate_hist_bins,
@@ -469,6 +470,25 @@ def test_validate_fontweight(weight, parsed_weight):
469470
assertvalidate_fontweight(weight)==parsed_weight
470471

471472

473+
@pytest.mark.parametrize('stretch, parsed_stretch', [
474+
('expanded','expanded'),
475+
('EXPANDED',ValueError),# stretch is case-sensitive
476+
(100,100),
477+
('100',100),
478+
(np.array(100),100),
479+
# fractional fontweights are not defined. This should actually raise a
480+
# ValueError, but historically did not.
481+
(20.6,20),
482+
('20.6',ValueError),
483+
([100],ValueError),
484+
])
485+
deftest_validate_fontstretch(stretch,parsed_stretch):
486+
ifparsed_stretchisValueError:
487+
withpytest.raises(ValueError):
488+
validate_fontstretch(stretch)
489+
else:
490+
assertvalidate_fontstretch(stretch)==parsed_stretch
491+
472492
deftest_keymaps():
473493
key_list= [kforkinmpl.rcParamsif'keymap'ink]
474494
forkinkey_list:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp