-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
FreeBSD seems to throw an OSError when locale.strxfrm is given 'Å', which is surprising behavior. Well, maybe not, considering how many bugs I have found with FreeBSD's implementation of locale over the course of natsort development. Anyway, we just ignore any input that causes locale.strxfrm to barf in our tests.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
from typing import Any, Callable, FrozenSet, Union | ||
|
||
import pytest | ||
from hypothesis import example, given | ||
from hypothesis import assume, example, given | ||
from hypothesis.strategies import floats, integers, text | ||
from natsort.compat.fastnumbers import try_float, try_int | ||
from natsort.compat.locale import get_strxfrm | ||
|
@@ -32,6 +32,20 @@ def no_null(x: str) -> bool: | |
return "\0" not in x | ||
|
||
|
||
def input_is_ok_with_locale(x: str) -> bool: | ||
"""Ensure this input won't cause locale.strxfrm to barf""" | ||
# On FreeBSD, locale.strxfrm raises an OSError on input like 'Å'. | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
SethMMorton
Author
Owner
|
||
# You read that right - an *OSError* for invalid input. | ||
# We cannot really fix that, so we just filter out any value | ||
# that could cause locale.strxfrm to barf with this function. | ||
try: | ||
get_strxfrm()(x) | ||
except OSError: | ||
return False | ||
else: | ||
return True | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"alg, example_func", | ||
[ | ||
|
@@ -77,6 +91,7 @@ def test_string_component_transform_factory( | |
) -> None: | ||
string_component_transform_func = string_component_transform_factory(alg) | ||
x = str(x) | ||
assume(input_is_ok_with_locale(x)) # handle broken locale lib on BSD. | ||
try: | ||
assert list(string_component_transform_func(x)) == list(example_func(x)) | ||
except ValueError as e: # handle broken locale lib on BSD. | ||
|
Is this reported somewhere in FreeBSD?