Skip to content

Commit

Permalink
Merge branch 'run-on-freebsd-in-ci'
Browse files Browse the repository at this point in the history
  • Loading branch information
SethMMorton committed Mar 2, 2023
2 parents e7ffcbe + f2ea0d6 commit 1215858
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 3 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
---

Expand Down
2 changes: 1 addition & 1 deletion natsort/compat/fake_fastnumbers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 17 additions & 1 deletion tests/test_string_component_transform_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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",
[
Expand Down Expand Up @@ -65,6 +79,7 @@ def no_null(x: str) -> bool:
],
)
@example(x=float("nan"))
@example(x="Å")
@given(
x=integers()
| floats()
Expand All @@ -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.
Expand Down
1 change: 0 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ deps =
pytest-cov
pytest-mock
hypothesis
semver
extras =
{env:WITH_EXTRAS:}
commands =
Expand Down

0 comments on commit 1215858

Please sign in to comment.