summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSeth Morton <seth.m.morton@gmail.com>2023-03-01 21:25:31 -0800
committerSeth Morton <seth.m.morton@gmail.com>2023-03-01 21:25:31 -0800
commit1215858e0930dd1ab24c43726725c5e82ea80f87 (patch)
tree82409ab4904d799aec2535676581bc34535f9672
parente7ffcbe38a08bdda9ee8132be8c95fa55e40b4ac (diff)
parentf2ea0d6f134c414bb9d98b271cab76e11f160f1b (diff)
downloadnatsort-1215858e0930dd1ab24c43726725c5e82ea80f87.tar.gz
Merge branch 'run-on-freebsd-in-ci'
-rw-r--r--.github/workflows/tests.yml21
-rw-r--r--CHANGELOG.md5
-rw-r--r--natsort/compat/fake_fastnumbers.py2
-rw-r--r--tests/test_string_component_transform_factory.py18
-rw-r--r--tox.ini1
5 files changed, 44 insertions, 3 deletions
diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml
index 34fa9d2..64065ce 100644
--- a/.github/workflows/tests.yml
+++ b/.github/workflows/tests.yml
@@ -59,3 +59,24 @@ jobs:
- name: Upload to CodeCov
uses: codecov/codecov-action@v3
+
+ test-bsd:
+ name: Test on FreeBSD
+ runs-on: macos-12
+
+ steps:
+ - name: Checkout code
+ uses: actions/checkout@v3
+
+ - name: Install and Run Tests
+ uses: vmactions/freebsd-vm@v0
+ with:
+ prepare: |
+ pkg install -y python3
+
+ run: |
+ python3 -m venv .venv
+ source .venv/bin/activate.csh
+ pip install --upgrade pip
+ pip install pytest pytest-mock hypothesis
+ python -m pytest --hypothesis-profile=slow-tests
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3560a5b..e445b3d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,11 @@
Unreleased
---
+### Fixed
+- Broken test on FreeBSD due to a broken `locale.strxfrm`.
+ **This change has no effect outside fixing tests**
+ (Issue [#161](https://github.com/SethMMorton/natsort/issues/161))
+
[8.3.0] - 2023-02-27
---
diff --git a/natsort/compat/fake_fastnumbers.py b/natsort/compat/fake_fastnumbers.py
index cb1c900..430345a 100644
--- a/natsort/compat/fake_fastnumbers.py
+++ b/natsort/compat/fake_fastnumbers.py
@@ -55,7 +55,7 @@ def fast_float(
String to attempt to convert to a float.
key : callable
Single-argument function to apply to *x* if conversion fails.
- nan : object
+ nan : float
Value to return instead of NaN if NaN would be returned.
Returns
diff --git a/tests/test_string_component_transform_factory.py b/tests/test_string_component_transform_factory.py
index 4c8ed87..40b4d34 100644
--- a/tests/test_string_component_transform_factory.py
+++ b/tests/test_string_component_transform_factory.py
@@ -5,7 +5,7 @@ from functools import partial
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 'Å'.
+ # 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",
[
@@ -65,6 +79,7 @@ def no_null(x: str) -> bool:
],
)
@example(x=float("nan"))
+@example(x="Å")
@given(
x=integers()
| floats()
@@ -76,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.
diff --git a/tox.ini b/tox.ini
index 833d005..3fa2378 100644
--- a/tox.ini
+++ b/tox.ini
@@ -25,7 +25,6 @@ deps =
pytest-cov
pytest-mock
hypothesis
- semver
extras =
{env:WITH_EXTRAS:}
commands =