Skip to content

Commit

Permalink
Test that checks unicode number presence won't crater tests
Browse files Browse the repository at this point in the history
Instead of failing, it only raises a warning.
  • Loading branch information
SethMMorton committed Nov 20, 2020
1 parent d5ab4ff commit 7171f51
Showing 1 changed file with 23 additions and 16 deletions.
39 changes: 23 additions & 16 deletions tests/test_unicode_numbers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"""

import unicodedata
import warnings

from natsort.unicode_numbers import (
decimal_chars,
Expand Down Expand Up @@ -34,32 +35,38 @@ def test_decimal_chars_contains_only_valid_unicode_decimal_characters():


def test_numeric_chars_contains_all_valid_unicode_numeric_and_digit_characters():
set_numeric_hex = set(numeric_hex)
set_numeric_chars = set(numeric_chars)
set_digit_chars = set(digit_chars)
set_decimal_chars = set(decimal_chars)
for i in range(0X110000):

assert set_decimal_chars.isdisjoint(digits_no_decimals)
assert set_digit_chars.issuperset(digits_no_decimals)

assert set_decimal_chars.isdisjoint(numeric_no_decimals)
assert set_numeric_chars.issuperset(numeric_no_decimals)


def test_missing_unicode_number_in_collection():
ok = True
set_numeric_hex = set(numeric_hex)
for i in range(0x110000):
try:
a = chr(i)
except ValueError:
break
if a in "0123456789":
continue
if unicodedata.numeric(a, None) is not None:
assert i in set_numeric_hex
assert a in set_numeric_chars
if unicodedata.digit(a, None) is not None:
assert i in set_numeric_hex
assert a in set_digit_chars
if unicodedata.decimal(a, None) is not None:
assert i in set_numeric_hex
assert a in set_decimal_chars

assert set_decimal_chars.isdisjoint(digits_no_decimals)
assert set_digit_chars.issuperset(digits_no_decimals)

assert set_decimal_chars.isdisjoint(numeric_no_decimals)
assert set_numeric_chars.issuperset(numeric_no_decimals)
if i not in set_numeric_hex:
ok = False
if not ok:
warnings.warn(
"""\
Not all numeric unicode characters are represented in natsort/unicode_numeric_hex.py
This can be addressed by running dev/generate_new_unicode_numbers.py with the current \
version of Python.
"""
)


def test_combined_string_contains_all_characters_in_list():
Expand Down

0 comments on commit 7171f51

Please sign in to comment.