コード例 #1
0
def test_random():
    """Try to sort 100,000 randomly generated strings without exception."""

    # Repeat test 100,000 times
    for _ in py23_range(100000):
        # Made a list of five randomly generated strings
        lst = [''.join(sample(printable, randint(7, 30)))
               for __ in py23_range(5)]
        # Try to sort.  If there is an exception, give some detailed info.
        try:
            natsorted(lst)
        except Exception as e:
            msg = "Ended with exception type '{exc}: {msg}'.\n"
            msg += "Failed on the input {lst}."
            fail(msg.format(exc=type(e).__name__, msg=str(e), lst=str(lst)))
コード例 #2
0
def test_digit_chars_contains_all_valid_unicode_digit_characters():
    for i in py23_range(0X10FFFF):
        try:
            a = py23_unichr(i)
        except ValueError:
            break
        if a in set('0123456789'):
            continue
        if unicodedata.digit(a, None) is not None:
            assert a in digit_chars
コード例 #3
0
def test_similar():
    """Try to sort 100,000 randomly generated
    similar strings without exception.
    """

    # Repeat test 100,000 times
    for _ in py23_range(100000):
        # Create a randomly generated string
        base = sample(printable, randint(7, 30))
        # Make a list of strings based on this string,
        # with some randomly generated modifications
        lst = []
        for __ in py23_range(5):
            new_str = copy(base)
            for ___ in py23_range(randint(1, 5)):
                new_str[randint(0, len(base)-1)] = choice(printable)
            lst.append(''.join(new_str))
        # Try to sort.  If there is an exception, give some detailed info.
        try:
            natsorted(lst)
        except Exception as e:
            msg = "Ended with exception type '{exc}: {msg}'.\n"
            msg += "Failed on the input {lst}."
            fail(msg.format(exc=type(e).__name__, msg=str(e), lst=str(lst)))
コード例 #4
0
def prof_str_asint_unsigned(a):
    print('*** Unsigned Int (Versions) Call ***')
    for _ in py23_range(1000):
        natsorted(a, number_type=int, signed=False)
コード例 #5
0
# -*- coding: utf-8 -*-
"""\
This file contains functions to profile natsorted with different
inputs and different settings.
"""
from __future__ import print_function
import cProfile
import random
import sys

sys.path.insert(0, '.')
from natsort import natsorted, index_natsorted
from natsort.py23compat import py23_range

# Sample lists to sort
nums = random.sample(py23_range(10000), 1000)
nstr = list(map(str, random.sample(py23_range(10000), 1000)))
astr = [
    'a' + x + 'num' for x in map(str, random.sample(py23_range(10000), 1000))
]
tstr = [['a' + x, 'a-' + x]
        for x in map(str, random.sample(py23_range(10000), 1000))]
cstr = [
    'a' + x + '-' + x for x in map(str, random.sample(py23_range(10000), 1000))
]


def prof_nums(a):
    print('*** Basic Call, Numbers ***')
    for _ in py23_range(1000):
        natsorted(a)
コード例 #6
0
ファイル: profile_natsorted.py プロジェクト: dpetzold/natsort
def prof_num_str(a):
    print('*** Basic Call, Numbers as Strings ***')
    for _ in py23_range(1000):
        natsorted(a)
コード例 #7
0
def prof_str_index(a):
    print('*** Basic Index Call ***')
    for _ in py23_range(1000):
        index_natsorted(a)
コード例 #8
0
def prof_str_noexp(a):
    print('*** No-Exp Call ***')
    for _ in py23_range(1000):
        natsorted(a, exp=False)
コード例 #9
0
ファイル: profile_natsorted.py プロジェクト: dpetzold/natsort
def prof_str_asint(a):
    print('*** Int Call ***')
    for _ in py23_range(1000):
        natsorted(a, number_type=int)
コード例 #10
0
def prof_nums(a):
    print('*** Basic Call, Numbers ***')
    for _ in py23_range(1000):
        natsorted(a)
コード例 #11
0
ファイル: profile_natsorted.py プロジェクト: dpetzold/natsort
def prof_str_unsigned(a):
    print('*** Unsigned Call ***')
    for _ in py23_range(1000):
        natsorted(a, signed=False)
コード例 #12
0
ファイル: profile_natsorted.py プロジェクト: dpetzold/natsort
def prof_str_unsigned_noexp(a):
    print('*** Unsigned No-Exp Call ***')
    for _ in py23_range(1000):
        natsorted(a, signed=False, exp=False)
コード例 #13
0
ファイル: profile_natsorted.py プロジェクト: dpetzold/natsort
def prof_str_noexp(a):
    print('*** No-Exp Call ***')
    for _ in py23_range(1000):
        natsorted(a, exp=False)
コード例 #14
0
ファイル: profile_natsorted.py プロジェクト: dpetzold/natsort
def prof_nested(a):
    print('*** Basic Call, Nested Strings ***')
    for _ in py23_range(1000):
        natsorted(a)
コード例 #15
0
ファイル: profile_natsorted.py プロジェクト: dpetzold/natsort
def prof_str_index(a):
    print('*** Basic Index Call ***')
    for _ in py23_range(1000):
        index_natsorted(a)
コード例 #16
0
def prof_str_index_key(a):
    print('*** Basic Index Call With Key ***')
    for _ in py23_range(1000):
        index_natsorted(a, key=lambda x: x.upper())
コード例 #17
0
ファイル: profile_natsorted.py プロジェクト: dpetzold/natsort
def prof_str_asint_unsigned(a):
    print('*** Unsigned Int (Versions) Call ***')
    for _ in py23_range(1000):
        natsorted(a, number_type=int, signed=False)
コード例 #18
0
def prof_str_unorderable(a):
    print('*** Basic Index Call, "Unorderable" ***')
    for _ in py23_range(1000):
        natsorted(a)
コード例 #19
0
ファイル: profile_natsorted.py プロジェクト: dpetzold/natsort
def prof_str_key(a):
    print('*** Basic Call With Key ***')
    for _ in py23_range(1000):
        natsorted(a, key=lambda x: x.upper())
コード例 #20
0
def prof_num_str(a):
    print('*** Basic Call, Numbers as Strings ***')
    for _ in py23_range(1000):
        natsorted(a)
コード例 #21
0
def prof_str_unsigned_noexp(a):
    print('*** Unsigned No-Exp Call ***')
    for _ in py23_range(1000):
        natsorted(a, signed=False, exp=False)
コード例 #22
0
def prof_nested(a):
    print('*** Basic Call, Nested Strings ***')
    for _ in py23_range(1000):
        natsorted(a)
コード例 #23
0
ファイル: profile_natsorted.py プロジェクト: dpetzold/natsort
def prof_str_unorderable(a):
    print('*** Basic Index Call, "Unorderable" ***')
    for _ in py23_range(1000):
        natsorted(a)
コード例 #24
0
def prof_str_unsigned(a):
    print('*** Unsigned Call ***')
    for _ in py23_range(1000):
        natsorted(a, signed=False)
コード例 #25
0
ファイル: profile_natsorted.py プロジェクト: dpetzold/natsort
def prof_nums(a):
    print('*** Basic Call, Numbers ***')
    for _ in py23_range(1000):
        natsorted(a)
コード例 #26
0
def prof_str_asint(a):
    print('*** Int Call ***')
    for _ in py23_range(1000):
        natsorted(a, number_type=int)
コード例 #27
0
ファイル: profile_natsorted.py プロジェクト: dpetzold/natsort
"""\
This file contains functions to profile natsorted with different
inputs and different settings.
"""
from __future__ import print_function
import cProfile
import random
import sys

sys.path.insert(0, '.')
from natsort import natsorted, index_natsorted
from natsort.py23compat import py23_range


# Sample lists to sort
nums = random.sample(py23_range(10000), 1000)
nstr = list(map(str, random.sample(py23_range(10000), 1000)))
astr = ['a'+x+'num' for x in map(str, random.sample(py23_range(10000), 1000))]
tstr = [['a'+x, 'a-'+x]
        for x in map(str, random.sample(py23_range(10000), 1000))]
cstr = ['a'+x+'-'+x for x in map(str, random.sample(py23_range(10000), 1000))]


def prof_nums(a):
    print('*** Basic Call, Numbers ***')
    for _ in py23_range(1000):
        natsorted(a)
cProfile.run('prof_nums(nums)', sort='time')


def prof_num_str(a):