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

Skip to content

Commit 5fb45b8

Browse files
committed
TST: Move locale comma test to a subprocess
On some systems/pytest versions, the skip in an exception handler does not skip, but is treated as an exception. Namely, the ARM test machine in Cirrus and on my WSL Ubuntu.
1 parent 469b96b commit 5fb45b8

File tree

1 file changed

+27
-13
lines changed

1 file changed

+27
-13
lines changed

lib/matplotlib/tests/test_ticker.py

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1640,22 +1640,36 @@ def test_latex(self, is_latex, usetex, expected):
16401640
assert fmt.format_pct(50, 100) == expected
16411641

16421642

1643-
def test_locale_comma():
1644-
currentLocale = locale.getlocale()
1643+
def _impl_locale_comma():
16451644
try:
16461645
locale.setlocale(locale.LC_ALL, 'de_DE.UTF-8')
1647-
ticks = mticker.ScalarFormatter(useMathText=True, useLocale=True)
1648-
fmt = '$\\mathdefault{%1.1f}$'
1649-
x = ticks._format_maybe_minus_and_locale(fmt, 0.5)
1650-
assert x == '$\\mathdefault{0{,}5}$'
1651-
# Do not change , in the format string
1652-
fmt = ',$\\mathdefault{,%1.1f},$'
1653-
x = ticks._format_maybe_minus_and_locale(fmt, 0.5)
1654-
assert x == ',$\\mathdefault{,0{,}5},$'
16551646
except locale.Error:
1656-
pytest.skip("Locale de_DE.UTF-8 is not supported on this machine")
1657-
finally:
1658-
locale.setlocale(locale.LC_ALL, currentLocale)
1647+
print('SKIP: Locale de_DE.UTF-8 is not supported on this machine')
1648+
return
1649+
ticks = mticker.ScalarFormatter(useMathText=True, useLocale=True)
1650+
fmt = '$\\mathdefault{%1.1f}$'
1651+
x = ticks._format_maybe_minus_and_locale(fmt, 0.5)
1652+
assert x == '$\\mathdefault{0{,}5}$'
1653+
# Do not change , in the format string
1654+
fmt = ',$\\mathdefault{,%1.1f},$'
1655+
x = ticks._format_maybe_minus_and_locale(fmt, 0.5)
1656+
assert x == ',$\\mathdefault{,0{,}5},$'
1657+
1658+
1659+
def test_locale_comma():
1660+
# On some systems/pytest versions, `pytest.skip` in an exception handler
1661+
# does not skip, but is treated as an exception, so directly running this
1662+
# test can incorrectly fail instead of skip.
1663+
# Instead, run this test in a subprocess, which avoids the problem, and the
1664+
# need to fix the locale after.
1665+
proc = mpl.testing.subprocess_run_helper(_impl_locale_comma, timeout=60,
1666+
extra_env={'MPLBACKEND': 'Agg'})
1667+
skip_msg = next((line[len('SKIP:'):].strip()
1668+
for line in proc.stdout.splitlines()
1669+
if line.startswith('SKIP:')),
1670+
'')
1671+
if skip_msg:
1672+
pytest.skip(skip_msg)
16591673

16601674

16611675
def test_majformatter_type():

0 commit comments

Comments
 (0)