Skip to content

Commit 60f88e5

Browse files
committed
Minor changes
1 parent 3142e3f commit 60f88e5

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

codext/__common__.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@
2929

3030

3131
__all__ = ["add", "add_map", "b", "clear", "codecs", "decode", "encode", "ensure_str", "examples", "guess",
32-
"generate_strings_from_regex", "get_alphabet_from_mask", "handle_error", "list_categories", "list_encodings",
33-
"lookup", "maketrans", "rank", "re", "register", "remove", "reset", "s2i", "search", "stopfunc", "BytesIO",
34-
"MASKS", "PY3"]
32+
"generate_strings_from_regex", "get_alphabet_from_mask", "handle_error", "is_native", "list_categories",
33+
"list_encodings", "lookup", "maketrans", "rank", "re", "register", "remove", "reset", "s2i", "search",
34+
"stopfunc", "BytesIO", "MASKS", "PY3"]
3535
CODECS_REGISTRY = None
3636
MASKS = {
3737
'a': printable,
@@ -439,6 +439,11 @@ def examples(encoding, number=10):
439439
codecs.examples = examples
440440

441441

442+
def is_native(encoding):
443+
""" Determine if a given encoding is native or not. """
444+
return codecs.lookup(encoding).parameters['category'] == "native"
445+
446+
442447
def list_categories():
443448
""" Get a list of all codec categories. """
444449
c = ["native"]

tests/test_generated.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import os
77
import re
88
from itertools import chain
9+
from random import randint
910
from string import printable
1011
from unittest import TestCase
1112

@@ -71,6 +72,9 @@ def _template(self):
7172
# examples validation tests
7273
if k.startswith("enc-dec") and isinstance(examples, list):
7374
for s in examples:
75+
rd = re.match(r"\@random(?:\{(\d+)\})?$", s)
76+
if rd:
77+
s = "".join(chr(randint(0, 255)) for i in range(int(rd.group(1) or "512")))
7478
self.assertEqual(icdec(f2(icenc(f1(s, ename)), ename)), icdec(s))
7579
self.assertEqual(icdec(f2(icenc(f1(b(s), ename)), ename)), b(icdec(s)))
7680
# file tests

0 commit comments

Comments
 (0)